diff --git a/addons/mrp/models/stock_scrap.py b/addons/mrp/models/stock_scrap.py index d3a5feb7d6b98..e1dda66078af6 100644 --- a/addons/mrp/models/stock_scrap.py +++ b/addons/mrp/models/stock_scrap.py @@ -88,9 +88,5 @@ def do_replenish(self, values=False): if self.production_id and self.production_id.procurement_group_id: values.update({ 'group_id': self.production_id.procurement_group_id, - 'move_dest_ids': self.production_id.procurement_group_id.stock_move_ids.filtered( - lambda m: m.location_id == self.location_id - and m.product_id == self.product_id - and m.state not in ('assigned', 'done', 'cancel')) }) super().do_replenish(values) diff --git a/addons/mrp/tests/test_replenish.py b/addons/mrp/tests/test_replenish.py index d149c9636c225..1e1e498736b0d 100644 --- a/addons/mrp/tests/test_replenish.py +++ b/addons/mrp/tests/test_replenish.py @@ -144,6 +144,49 @@ def test_replenish_from_scrap(self): replenish_picking.button_validate() self.assertEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned']) + def test_scrap_replenishment_reassigns_required_qty_to_component(self): + """ Test that when validating the scrap replenishment transfer, the required quantity + is re-assigned to the component for the final manufacturing product. """ + warehouse = self.env.ref('stock.warehouse0') + warehouse.manufacture_steps = 'pbm' + basic_mo, _, _, product_to_scrap, other_product = self.generate_mo(qty_final=1, qty_base_1=10, qty_base_2=10) + for product in (product_to_scrap, other_product): + self.env['stock.quant'].create({ + 'product_id': product.id, + 'location_id': warehouse.lot_stock_id.id, + 'quantity': 20 + }) + self.assertEqual(basic_mo.move_raw_ids.location_id, warehouse.pbm_loc_id) + basic_mo.action_confirm() + self.assertEqual(len(basic_mo.picking_ids), 1) + basic_mo.picking_ids.action_assign() + basic_mo.picking_ids.button_validate() + self.assertEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned']) + + # Scrap the product and trigger replenishment + scrap_form = Form.from_action(self.env, basic_mo.button_scrap()) + scrap_form.product_id = product_to_scrap + scrap_form.scrap_qty = 5 + scrap_form.should_replenish = True + self.assertEqual(scrap_form.location_id, warehouse.pbm_loc_id) + scrap_form.save().action_validate() + + # Assert that the component quantity is reduced + self.assertNotEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned']) + move_to_scrap = basic_mo.move_raw_ids.filtered(lambda m: m.product_id == product_to_scrap) + move_other = basic_mo.move_raw_ids.filtered(lambda m: m.product_id == other_product) + self.assertEqual(move_to_scrap.quantity, 5, "Scrapped component should have qty 5") + self.assertEqual(move_other.quantity, 10, "Other component should remain qty 10") + self.assertEqual(len(basic_mo.picking_ids), 2) + + replenish_picking = basic_mo.picking_ids.filtered(lambda x: x.state == 'assigned') + replenish_picking.button_validate() + + # Assert that the component quantity is re-assigned + self.assertEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned']) + self.assertEqual(move_to_scrap.quantity, 10, "Scrapped component should return to qty 10") + self.assertEqual(move_other.quantity, 10, "Other component should still be qty 10") + def test_global_visibility_days_affect_lead_time_manufacture_rule(self): """ Ensure global visibility days will only be captured one time in an orderpoint's lead_days/json_lead_days.