-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
base: 16.0
Are you sure you want to change the base?
[16.0][ADD] stock_move_negative_stock_location #1801
Conversation
bc7b2db
to
6912963
Compare
6912963
to
b87153c
Compare
@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. |
There was a problem hiding this 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() |
There was a problem hiding this comment.
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
:
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() |
neg_r_moves = self.browse(self.env.context["neg_r_moves"]) | ||
for move in neg_r_moves: |
There was a problem hiding this comment.
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:
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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"), | ||
] | ||
) |
There was a problem hiding this comment.
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
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 asStock
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.