diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index e69a454b45d..0fab4e26da5 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1653,3 +1653,47 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): return_picking_2 = self.env['stock.picking'].browse(res['res_id']) return_picking_2.button_validate() self.assertEqual(return_wizard.product_return_moves.quantity, 1) + + def test_2_steps_fixed_procurement_propagation_with_backorder(self): + """ + When validating a picking (partially coming from a backorder) linked to 2 destinations moves in a 2-steps delivery, + stock.move.line should be created for the 2 OUT moves. + Steps: + - Warehouse with Outgoing Shipments in 2 steps and propagation of rule set to Fixed + - Create a SO with 3 Product X + - on PICK_1 picking: set 1 unit in done, validate and create a backorder + - Create a SO with 1 Product X + - on PICK_2 picking: set 3 units in done and validate + """ + warehouse = self.company_data.get('default_warehouse') + warehouse.delivery_steps = 'pick_ship' + rule = warehouse.delivery_route_id.rule_ids.filtered(lambda r: r.procure_method == 'make_to_stock')[0] + rule.group_propagation_option = 'fixed' + fixedGroup = self.env['procurement.group'].create({}) + rule.group_id = fixedGroup + self.env['stock.quant']._update_available_quantity(self.test_product_delivery, warehouse.lot_stock_id, 4) + # create a SO with 3 products + so1 = self._get_new_sale_order(product=self.test_product_delivery, amount=3) + so1.action_confirm() + pick1 = fixedGroup.stock_move_ids.filtered(lambda m: m.origin == so1.name)[0].picking_id + out1 = so1.picking_ids.filtered(lambda p: p.picking_type_id == warehouse.out_type_id) + # set 1 done on the PICK move + pick1.move_ids.write({'quantity': 1, 'picked': True}) + res_dict = pick1.button_validate() + # create a backorder for the 2 remaining products + backorder_wizard = Form(self.env[(res_dict.get('res_model'))].with_context(res_dict['context'])).save() + backorder_wizard.process() + pick2 = pick1.backorder_ids[0] + self.assertEqual(out1.move_line_ids.quantity, 1) + # create another SO with 1 product + so2 = self._get_new_sale_order(product=self.test_product_delivery, amount=1) + so2.action_confirm() + # PICK move of this SO will increment the product quantity of the PICK backorder by 1 + # PICK backorder is linked to out1 and out2 + out2 = so2.picking_ids.filtered(lambda p: p.picking_type_id == warehouse.out_type_id) + pick2.move_ids.write({'quantity': 3, 'picked': True}) + pick2.button_validate() + self.assertEqual(out1.state, 'assigned') + self.assertEqual(out1.move_line_ids.quantity, 3) + self.assertEqual(out2.state, 'assigned') + self.assertEqual(out2.move_line_ids.quantity, 1) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index e884323e62a..b62a86d2452 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1528,7 +1528,7 @@ Please change the quantity done or the rounding precision of your unit of measur return self.env['stock.quant']._get_available_quantity(self.product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict, allow_negative=allow_negative) def _get_available_move_lines_in(self): - move_lines_in = self.move_orig_ids.filtered(lambda m: m.state == 'done').mapped('move_line_ids') + move_lines_in = self.move_orig_ids.move_dest_ids.move_orig_ids.filtered(lambda m: m.state == 'done').mapped('move_line_ids') def _keys_in_groupby(ml): return (ml.location_dest_id, ml.lot_id, ml.result_package_id, ml.owner_id)