[FIX] {sale_,}stock: decrease SOL qty with existing backorders

2-steps delivery. If there is already a backorder for the picking
out->customer, when decreasing the SOL qty, an unexpected picking
will be created

To reproduce the error:
1. In Settings, enable "Multi-Step Routes"
2. Edit the warehouse:
   - Outgoing: 2 steps
3. Create a storable product P
4. Update the on hand qty:
   - 10 x P at WH/Stock
5. Create and confirm a SO with 10 x P
6. Process the pickings with 6 x P (with backorders)
   - There should be 4 pickings
7. On the SO, decrease the quantity to 7

Error: an unexpected picking (customer -> out) is created for 3 x P

Step 6, when creating a backorder for 4 x P from out to customer,
we split the initial SM, and we force the `procure_method` to
`make_to_stock`
Step 7, when decreasing the qty, we create a negative procurement
and run the rules' system. Because of warehouse configuration, the
rule that links output location and customer one is based on an MTO
logic: the SM for -3 x P has the `procure_method` set to
`make_to_order`. As a result, that move will not be merged with the
one created during the split (step 6) and we will create the
unexpected picking for the move.

The SM generated by the split should keep the same procure method
logic as the initial one.

OPW-3141387

closes odoo/odoo#114787

X-original-commit: 920924e963d389ab2f962e0fe45ef229641d00c4
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart (awt)
2023-03-09 15:55:07 +01:00
parent 4ba49c93ec
commit 1a0787062d
2 changed files with 38 additions and 1 deletions
@@ -1313,3 +1313,40 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon):
line.product_uom_qty = 8
self.assertEqual(so.picking_ids.move_ids.product_uom_qty, 8)
def test_backorder_and_decrease_sol_qty(self):
"""
2 steps delivery
SO with 10 x P
Process pickings of 6 x P with backorders
Update SO: 7 x P
Backorder should be updated: 1 x P
"""
warehouse = self.company_data['default_warehouse']
warehouse.delivery_steps = 'pick_ship'
stock_location = warehouse.lot_stock_id
out_location = warehouse.wh_output_stock_loc_id
customer_location = self.env.ref('stock.stock_location_customers')
so = self._get_new_sale_order()
so.action_confirm()
pick01, ship01 = so.picking_ids
pick01.move_line_ids.qty_done = 6
pick01._action_done()
pick02 = pick01.backorder_ids
ship01.move_line_ids[0].qty_done = 6
ship01._action_done()
ship02 = ship01.backorder_ids
so.order_line.product_uom_qty = 7
self.assertRecordValues(so.picking_ids.move_ids.sorted('id'), [
{'location_id': out_location.id, 'location_dest_id': customer_location.id, 'product_uom_qty': 6.0, 'quantity_done': 6.0, 'state': 'done'},
{'location_id': stock_location.id, 'location_dest_id': out_location.id, 'product_uom_qty': 6.0, 'quantity_done': 6.0, 'state': 'done'},
{'location_id': stock_location.id, 'location_dest_id': out_location.id, 'product_uom_qty': 1.0, 'quantity_done': 0.0, 'state': 'assigned'},
{'location_id': out_location.id, 'location_dest_id': customer_location.id, 'product_uom_qty': 1.0, 'quantity_done': 0.0, 'state': 'waiting'},
])
self.assertEqual(ship01.move_ids.move_orig_ids, (pick01 | pick02).move_ids)
self.assertEqual(ship02.move_ids.move_orig_ids, (pick01 | pick02).move_ids)
+1 -1
View File
@@ -1842,7 +1842,7 @@ Please change the quantity done or the rounding precision of your unit of measur
def _prepare_move_split_vals(self, qty):
vals = {
'product_uom_qty': qty,
'procure_method': 'make_to_stock',
'procure_method': self.procure_method,
'move_dest_ids': [(4, x.id) for x in self.move_dest_ids if x.state not in ('done', 'cancel')],
'move_orig_ids': [(4, x.id) for x in self.move_orig_ids],
'origin_returned_move_id': self.origin_returned_move_id.id,