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

[14.0] stock_available_to_promise_release: Allow unrelease processed qties #971

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

Conversation

mmequignon
Copy link
Member

@mmequignon mmequignon commented Jan 13, 2025

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.

Copy link
Contributor

@jbaudoux jbaudoux left a 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

iterator = move._get_chained_moves_iterator("move_orig_ids")
moves_to_cancel = self.env["stock.move"]
# 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")
origin_moves = origin_moves.filtered(
Copy link
Contributor

Choose a reason for hiding this comment

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

When calling _split_origins, you need to give the remaining quantity that needs to be split
move._split_origins(origin_moves, qty_to_unrelease)

def _split_origins(self, origins, qty):
qty = self.product_qty

Copy link
Member Author

Choose a reason for hiding this comment

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

You want me to modify the implementation of _split_origins ?

Copy link
Contributor

Choose a reason for hiding this comment

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

there is no choice since you may decrease the quantity on each iteration

qty_to_return_at_step -= returned_qty
if qty_to_return_at_step == 0:
break

Copy link
Contributor

Choose a reason for hiding this comment

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

and do this outside of for loop
qty_to_unrelease = qty_cancelled_at_step


returned_quantity = 0
# create return
return_type = picking.picking_type_id.return_picking_type_id
Copy link
Contributor

Choose a reason for hiding this comment

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

nice to have: raise error if no return_type configured

return_type = picking.picking_type_id.return_picking_type_id
wiz_values = {
"picking_id": picking.id,
"original_location_id": picking.location_dest_id.id,
Copy link
Contributor

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

Suggested change
"original_location_id": picking.location_dest_id.id,
"original_location_id": picking.location_id.id,

"move_id": move.id,
}
product_return_moves.append((0, 0, return_move_vals))
returned_quantity += move_qty
Copy link
Contributor

Choose a reason for hiding this comment

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

The quantity_to_return should decrease on each iteration

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it's done in upper method
https://github.com/OCA/wms/pull/971/files#diff-fca2e9865c2d75a9793dbe699bffdf976606d996b69d09cacd25660f2926e998R693
Thing is that it's not nice to modify an argument inside a method, which is why I'm adding a new variable returned_qty which I compare with arg.
In the end, I return the number of units that were returned, and deduct this number in the wrapping method.
This is where the quantity_to_return counter is.

Copy link
Contributor

@jbaudoux jbaudoux Jan 15, 2025

Choose a reason for hiding this comment

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

Yes but I mean this line move_qty = min(quantity_to_return, move.quantity_done)
you forgot to substract the already processed qty by previous iterations. Should be move_qty = min(quantity_to_return - returned_quantity, move.quantity_done)

@jbaudoux
Copy link
Contributor

cc @rousseldenis @lmignon

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.

2 participants