Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] stock_move_negative_stock_location #1801

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

santostelmo
Copy link
Contributor

@santostelmo santostelmo commented Dec 20, 2024

Context

When making an stock move with a negative quantity, odoo convert it to a positive return move and the locations are inverted.
For stock moves with negative quantities, this module sets the source location with the return
picking type default destination location. Like that destination location is properly set on the return move.

Usage

In Returns picking type set the default destination location as Stock
Create a stock move from Stock to Customer with a negative quantity and validate it.
That move will be converted into a stock move from Customer to Stock with a positive quantity.

@santostelmo santostelmo force-pushed the 16.0-add-stock_move_negative_location branch from bc7b2db to 6912963 Compare December 20, 2024 05:29
@santostelmo santostelmo force-pushed the 16.0-add-stock_move_negative_location branch from 6912963 to b87153c Compare December 20, 2024 05:34
@santostelmo santostelmo changed the title [ADD] stock_move_negative_stock_location [16.0][ADD] stock_move_negative_stock_location Dec 20, 2024
@rousseldenis
Copy link
Contributor

rousseldenis commented Dec 20, 2024

@santostelmo @jbaudoux Thanks for this. But, shouldn't it be a "bug" in stock module behavior ?

@santostelmo
Copy link
Contributor Author

@santostelmo @jbaudoux Thanks for this. But, shouldn't it be a "bug" in stock module behavior ?

You're absolutely right ! I am opening a issue to odoo. In the meantime we have this module to workaround.

Copy link
Contributor

@sebalix sebalix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments.
For sure, having this fixed in core would be better :)
If not possible in 16.0, maybe in master.

# #L1381C14-L1381C27)
# to be able to invert location_id and location_dest_id
if self.env.context.get("neg_r_moves"):
self.set_negative_return_moves_location()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And handle the context only where it is needed (if in later version Odoo adds a hook for instance, we could trash easily this context handling without touching the business method set_negative_return_moves_location:

Suggested change
self.set_negative_return_moves_location()
neg_moves = self.browse(self.env.context.get("neg_r_moves")).exists()
neg_moves.set_negative_return_moves_location()

Comment on lines +26 to +27
neg_r_moves = self.browse(self.env.context["neg_r_moves"])
for move in neg_r_moves:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to get methods not depending on context but on current recordset, easier to test and understand:

Suggested change
neg_r_moves = self.browse(self.env.context["neg_r_moves"])
for move in neg_r_moves:
for move in self:

@@ -0,0 +1,3 @@
When making an stock move with a negative quantity, odoo convert it to a positive return move and the locations are inverted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When making an stock move with a negative quantity, odoo convert it to a positive return move and the locations are inverted.
When making a stock move with a negative quantity, Odoo converts it to a positive return move and the locations are inverted.

Comment on lines +27 to +39
location_source = self.env.ref("stock.stock_location_stock")
location_dest = self.env.ref("stock.stock_location_customers")

# WH: Stock → Customers
rule = self.env["stock.rule"].search(
[
("action", "=", "pull"),
("picking_type_id", "=", self.env.ref("stock.picking_type_out").id),
("location_src_id", "=", location_source.id),
("location_dest_id", "=", location_dest.id),
("procure_method", "=", "make_to_stock"),
]
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These config data can be retrieved in setUpClass, to keep transactional data and asserts only in the test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants