Skip to content
Snippets Groups Projects
Commit 8fe8ca99 authored by Simon Lejeune's avatar Simon Lejeune
Browse files

[FIX] stock: picking assign for stock moves if batched in a one2many

Let’s say you have 10 units of products item1 and item2 in your stock.
If you create a sale order with two order lines: 1 item1 and 1 item2,
it’ll create one picking with two pack operations: 1 item1 and 1 item2.
Validate the picking, everything goes fine.

Now if you go back to the sale order and increase the quantity of the
two order lines, let’s say you sold now 2 item1 and 2 item2, it’ll
create two picking having each one a single pack operation: the first
with a pack operation for 1 unit of item1, the second one with a pack
operation of 1unit for item2.

The expected result would be that a single new picking with the two pack
operations is created.

This bug is due to the fact that there’s a check on sale order line
write that’ll call _action_procurement_create if you indeed increased
the quantity of any line. This method will at some point call
assign_picking on the model stock move. This method will try to find a
non-done picking with the same procurement group as the one we’re
working (the procurement group for our sale order). For the first write
on sale.order.line, it won’t find one because there aren’t, so it’ll
create one. For the second write on sale.order.line (so, for the second
line) it should find the picking created by the first write, but it
won’t and so it’ll create a second picking.

The fact that it didn't find the picking create by the previous line
is due to the fact that we do not update the computed fields
between write on a one2many field since rev 7b8afc29 and that “group_id”
on the model stock.picking is a computed field (a related).

As we prefer to keep the behavior of not recomputing the computed fields
between writes on a one2many (it’s a trade-off for performance reason,
except in edge cases the recomputation is useless), we explicitly
trigger the recomputation before looking for a candidate picking in the
stock.move action_assign, so that the next searchs on picking.group_id
will be succesful.

This commit also introduces a test for this case.

Closes #14718
parent c9cd40d0
Branches
Tags
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment