Skip to content

[16.0][FIX] stock_available_to_promise_release: improve returnable qty calculation#1145

Open
nicolas-delbovier-acsone wants to merge 1 commit intoOCA:16.0from
acsone:16.0-fix-stock_available_to_promise_release-returnable-qty
Open

[16.0][FIX] stock_available_to_promise_release: improve returnable qty calculation#1145
nicolas-delbovier-acsone wants to merge 1 commit intoOCA:16.0from
acsone:16.0-fix-stock_available_to_promise_release-returnable-qty

Conversation

@nicolas-delbovier-acsone
Copy link
Copy Markdown

Correct the identification of consumed moves by checking done quantities in addition to the move state.

The previous logic only considered moves in the 'done' state. However, during certain validation flows, a move might have its quantity_done fully set while its state hasn't yet been updated. This caused the returnable quantity to be over-calculated, incorrectly preventing the cancellation of moves.

By including moves where product_uom_qty == m.quantity_done, we accurately capture moves that are effectively finished, regardless of their transient state.

@nicolas-delbovier-acsone nicolas-delbovier-acsone changed the title [FIX] stock_available_to_promise_release: improve returnable qty calculation [16.0] [FIX] stock_available_to_promise_release: improve returnable qty calculation Mar 25, 2026
@nicolas-delbovier-acsone nicolas-delbovier-acsone changed the title [16.0] [FIX] stock_available_to_promise_release: improve returnable qty calculation [16.0][FIX] stock_available_to_promise_release: improve returnable qty calculation Mar 25, 2026
Copy link
Copy Markdown

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

LGYM. Can you take a look at the failing tests? I would like to avoid to have this PR stuck by issues not related to your change.

# be limited to the quantity not consumed
done_dest_moves = done_moves.move_dest_ids.filtered(
lambda m: m.state == "done"
lambda m: m.state == "done" or m.product_uom_qty == m.quantity_done
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you ellaborate the issue you are facing?

Suggested change
lambda m: m.state == "done" or m.product_uom_qty == m.quantity_done
lambda m: m.state == "done" or m.picking_id.printed

From what I remember, the purpose was to allow to pick for multiple packs (you pick for all SO and then distribute on multiple SO). When one SO gets canceled, then the over-picked quantity had to be returned back to the stock.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you write a test for this? Because i don't quite understand the purpose of this change.
If you want to exclude not done but already picked/reserved dest moves, shouldn't be the change like J-E suggested and update the returnable_qty? By considering the quantity_done?
Because it could be that not the full product_qty is picked.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The bug we had is because of some interaction with a custom module of ours. Because of the cancelling of some moves happening at the same time as the validation of the picking, I found myself needing this new condition because in some special case we tested, the state on the move was not updated "at the right time".

I'll try to reproduce this error in a unit test that does not depend from our custom module when I have the time.

@jbaudoux
Copy link
Copy Markdown
Contributor

cc @mt-software-de

@sbidoul sbidoul force-pushed the 16.0-fix-stock_available_to_promise_release-returnable-qty branch 2 times, most recently from ad6bca3 to 3574e0b Compare March 27, 2026 17:17
…ulation

Correct the identification of consumed moves by checking done quantities
in addition to the move state.

The previous logic only considered moves in the 'done' state. However,
during certain validation flows, a move might have its `quantity_done`
fully set while its `state` hasn't yet been updated. This caused the
returnable quantity to be over-calculated, incorrectly preventing
the cancellation of moves.

By including moves where `product_uom_qty == m.quantity_done`, we
accurately capture moves that are effectively finished, regardless
of their transient state.
@nicolas-delbovier-acsone nicolas-delbovier-acsone force-pushed the 16.0-fix-stock_available_to_promise_release-returnable-qty branch from 3574e0b to 46790bc Compare March 31, 2026 06:13
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.

4 participants