Files
odoo_source/addons
Adrien Widart c574a7f4e9 [FIX] stock: put in pack the half-up rounded quantity
In some cases, when putting in pack, it will lead to a "unreserve more
than reserved" error

To reproduce the issue:
1. In Settings, enable "Packages"
2. Create a storable product P
3. Update the on-hand quantity: 0.4 x P
4. Create and mark as todo a planned delivery order DO
    - Operations: 0.4 x P
5. In the detailed operations, set the done quantity to 0.3
6. Put in Pack
7. Open the detailed operations
    - Error: There is a line with 0.11 x P reserved instead of 0.10. The
total reserved quantity is therefore 0.41 which is not possible.
Moreover, the available quantity of the related quant is 0.29 which does
not make sense
8. Set the done quantity to 0.1
9. Put in Pack
10. Validate

Error: a User Error is displayed "It is not possible to unreserve more
products of ... than you have in stock." The user is now stuck, he can
neither process the picking nor unreserve it.

On step 6, when putting in pack, we split the SML into two ones. To do
so, we also split the reserved quantity:
https://github.com/odoo/odoo/blob/fcc74186330c8df37cfac08455bd7bba44d4656b/addons/stock/models/stock_picking.py#L1384-L1388
However, because of a floating point issue, we have:
`0.4 - 0.3 = 0.10000000000000003`
Therefore, since we use the rounding method `UP`, we have:
```py
ml.product_uom_qty == 0.4
quantity_left_todo == 0.11
done_to_keep == 0.3
```
And we then use these values to update the reserved quantity on each
SML:
https://github.com/odoo/odoo/blob/fcc74186330c8df37cfac08455bd7bba44d4656b/addons/stock/models/stock_picking.py#L1391-L1398
When writing on that field, we also try to update the quants:
https://github.com/odoo/odoo/blob/55921e32baa1b4b226bd43edf20e93619e411905/addons/stock/models/stock_move_line.py#L378-L383
(As shown, if an error is raised, we ignore it)
After the reservation of `quantity_left_todo`, there are 0.29 x P left.
Therefore, when trying to reserve `done_to_keep`, it will raise an
error:
https://github.com/odoo/odoo/blob/b5d16141dc48d4379452ea40e167f3b00f956c20/addons/stock/models/stock_quant.py#L679-L680
But as shown above, the error will be ignored. This explains the
inconsistency between the reserved quantity on the SMLs and on the
quant.

On step 10, when validating the picking, we try to unreserve all SMLs:
https://github.com/odoo/odoo/blob/55921e32baa1b4b226bd43edf20e93619e411905/addons/stock/models/stock_move_line.py#L570-L572
So we will try to unreserve more than actually reserved on the quant.
That's the reason why an error will be displayed.

OPW-2942054

closes odoo/odoo#98521

X-original-commit: 4f593706ee6d1b3ddf0f1c9c90c86df2977459d9
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
2022-08-22 10:27:18 +02:00
..
2022-08-22 08:57:47 +02:00
2022-07-07 13:30:24 +02:00
2022-08-16 09:19:08 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-08-03 13:44:49 +02:00
2022-08-22 10:26:57 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-08-17 11:20:56 +02:00
2022-08-08 12:33:03 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00
2022-07-07 13:30:24 +02:00