-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
[14.0] stock_available_to_promise_release: Allow unrelease processed qties #971
base: 14.0
Are you sure you want to change the base?
Conversation
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.
Need to adapt README as well
stock_available_to_promise_release/models/stock_location_route.py
Outdated
Show resolved
Hide resolved
stock_available_to_promise_release/models/stock_location_route.py
Outdated
Show resolved
Hide resolved
return_type = picking.picking_type_id.return_picking_type_id | ||
wiz_values = { | ||
"picking_id": picking.id, | ||
"original_location_id": picking.location_dest_id.id, |
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.
This is not necessary. Otherwise, it should be
"original_location_id": picking.location_dest_id.id, | |
"original_location_id": picking.location_id.id, |
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.
@mmequignon Can you drop this line?
b5ad9ef
to
f6cf4c7
Compare
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.
Some minor remarks
} | ||
product_return_moves = [] | ||
for move in self: | ||
if not move.state == "done": |
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.
if not move.state == "done": | |
if move.state != "done": |
for move in self: | ||
if not move.state == "done": | ||
continue | ||
move_qty = min(quantity_to_return - returned_quantity, move.quantity_done) |
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.
Process real quantities and not uom quantities. You can use product_qty
as the move is done
move_qty = min(quantity_to_return - returned_quantity, move.quantity_done) | |
move_qty = min(quantity_to_return - returned_quantity, move.product_qty) |
} | ||
product_return_moves.append((0, 0, return_move_vals)) | ||
returned_quantity += move_qty | ||
if returned_quantity == quantity_to_return: |
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.
use float compare
@@ -591,6 +597,39 @@ def _get_chained_moves_iterator(self, chain_field): | |||
yield moves | |||
moves = moves.mapped(chain_field) | |||
|
|||
def _return_quantity_in_stock(self, quantity_to_return): |
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.
def _return_quantity_in_stock(self, quantity_to_return): | |
def _return_quantity_in_stock(self, quantity_to_return): | |
"""Return a quantity from a list of moves. | |
The quantity to return is in the product uom""" |
@@ -591,6 +597,39 @@ def _get_chained_moves_iterator(self, chain_field): | |||
yield moves | |||
moves = moves.mapped(chain_field) | |||
|
|||
def _return_quantity_in_stock(self, quantity_to_return): | |||
picking = self.picking_id | |||
picking.ensure_one() |
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.
picking.ensure_one() | |
picking.ensure_one() | |
move.product_id.ensure_one() |
returned_qty = moves_to_return._return_quantity_in_stock( | ||
qty_to_return_at_step | ||
) | ||
qty_returned_for_move += returned_qty |
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.
I would move this before the block just after the if float_is_zero
qty_returned_for_move += qty_to_return_at_step
origin_moves = move._split_origins(origin_moves) | ||
impacted_picking_ids.update(origin_moves.mapped("picking_id").ids) | ||
qty_to_split = qty_to_unrelease - qty_returned_for_move | ||
# TODO find new name |
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.
You can drop this TODO, you fixed it already
# backup procure_method as when you don't propagate cancel, the | ||
# destination move is forced to make_to_stock | ||
procure_method = move.procure_method | ||
next(iterator) # skip the current move | ||
for origin_moves in iterator: | ||
done_moves = origin_moves.filtered(lambda m: m.state == "done") |
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.
Move this variable down where it is used
if float_is_zero(qty_to_return_at_step, precision_rounding=rounding): | ||
continue |
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.
if float_is_zero(qty_to_return_at_step, precision_rounding=rounding): | |
continue | |
if float_is_zero(qty_to_return_at_step, precision_rounding=rounding): | |
continue | |
elif not move.rule_id.allow_unrelease_return_done_move: | |
raise UserError(_(f"You cannot unrelease the move {move.name} because some origin moves ', '.join(done_moves.mapped("name"))} are done")) |
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.
without using f-string to not give code in the translations
|
||
returned_quantity = 0 | ||
# create return | ||
return_type = picking.picking_type_id.return_picking_type_id |
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.
return_type = picking.picking_type_id.return_picking_type_id | |
return_type = picking.picking_type_id.return_picking_type_id | |
if not return_type: | |
raise UserError(_(f"The operation {picking.name} is done and cannot be returned")) |
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.
without using f-string to not give code in the translations
This PR adds a new option on stock routes, allowing to unrelease a delivery even if some internal operations (e.g. pick) are already done, creating a return move to the stock location.