[FIX] mrp_subcontrating: fix batch validation
Steps to reproduce the bug:
- Create a storable product “P1”
- Update the qty to 100
- Create a Transfer:
- product: P1
- type: Delivery order
- qty: 1 unit
- Mark as to do
- Reserve the Qty
- Create a seconde transfer:
- product: P1
- type: Delivery order
- qty: 5 unit
- Mark as to do
- Reserve the Qty
- qty done: 2 unit
- Create a batch picking with the 2 transfer
- Try to validate the batch
Problem:
A traceback is triggered: “ValueError: min() arg is an empty sequence”:
https://github.com/odoo/odoo/blob/829369d3ca0530f1aad0599fbb1598810a928cc3/addons/mrp_subcontracting/models/stock_picking.py#L73
Because when validating the first picking, the `_action_done` function
is triggered, so moves that do not have qty done will be cancelled
https://github.com/odoo/odoo/blob/3073779762a106b4022bfb0a350758445d28ea15/addons/stock/models/stock_move.py#L1524-L1529
Therefore, the reserved qty will be unreserved, and the
`stock.move.line` will be unlinked
https://github.com/odoo/odoo/blob/3073779762a106b4022bfb0a350758445d28ea15/addons/stock/models/stock_move.py#L1442
https://github.com/odoo/odoo/blob/3073779762a106b4022bfb0a350758445d28ea15/addons/stock/models/stock_move.py#L724
Solution:
We get the `date` from the `stock.move.line` to use it only when we have
subcontracted production, we can therefore add a check before accessing
them
opw-3159876
closes odoo/odoo#113136
X-original-commit: e996a45be6326cf76cf96ee76eb97abc86017458
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>