diff --git a/addons/mrp/models/mrp_abstract_workorder.py b/addons/mrp/models/mrp_abstract_workorder.py index c4673041ba92a7f39af27d151d78bcb4e78e1c5c..0cf35f4c7e81f1646fdf0c3ecb790ee2924637e6 100644 --- a/addons/mrp/models/mrp_abstract_workorder.py +++ b/addons/mrp/models/mrp_abstract_workorder.py @@ -84,10 +84,9 @@ class MrpAbstractWorkorder(models.AbstractModel): for move_line in move_raw.move_line_ids: # Get workorder lines that match reservation. candidates = move_workorder_lines._find_candidate(move_line) - while candidates: + for candidate in candidates: if float_compare(qty_todo, 0, precision_rounding=rounding) <= 0: break - candidate = candidates.pop() qty_to_add = move_line.product_uom_qty - candidate.qty_done line_values['to_update'][candidate] = { 'qty_done': candidate.qty_done + qty_to_add, diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 25e693f3d0f4a1c5c5c5d54830c5a82c6d9d1a46..f970e5055e435d5a272b1a3bbea3c3dfc35d3d14 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -676,6 +676,32 @@ class TestMrpOrder(TestMrpCommon): self.assertEqual(mo.move_raw_ids.filtered(lambda m: m.product_id == p1).quantity_done, 20, 'Update the produce quantity should not impact already produced quantity.') mo.button_mark_done() + def test_product_produce_6(self): + """ Build some final products and change the quantity to produce + directly in the wizard. The component line should be updated . + """ + self.stock_location = self.env.ref('stock.stock_location_stock') + mo, bom, p_final, p1, p2 = self.generate_mo(qty_final=1) + self.assertEqual(len(mo), 1, 'MO should have been created') + + mo.action_assign() + + produce_form = Form(self.env['mrp.product.produce'].with_context({ + 'active_id': mo.id, + 'active_ids': [mo.id], + })) + produce_form.qty_producing = 3 + self.assertEqual(len(produce_form.workorder_line_ids._records), 4, 'Update the produce quantity should change the components quantity.') + self.assertEqual(sum([x['qty_done'] for x in produce_form.workorder_line_ids._records]), 15, 'Update the produce quantity should change the components quantity.') + produce_form.qty_producing = 4 + self.assertEqual(len(produce_form.workorder_line_ids._records), 6, 'Update the produce quantity should change the components quantity.') + self.assertEqual(sum([x['qty_done'] for x in produce_form.workorder_line_ids._records]), 20, 'Update the produce quantity should change the components quantity.') + produce_form.qty_producing = 1 + self.assertEqual(len(produce_form.workorder_line_ids._records), 2, 'Update the produce quantity should change the components quantity.') + self.assertEqual(sum([x['qty_done'] for x in produce_form.workorder_line_ids._records]), 5, 'Update the produce quantity should change the components quantity.') + produce_wizard = produce_form.save() + produce_wizard.do_produce() + def test_product_produce_uom(self): plastic_laminate = self.env.ref('mrp.product_product_plastic_laminate') bom = self.env.ref('mrp.mrp_bom_plastic_laminate')