From b23edf5db2660b6f32cd22ef1e461ca4a685a63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 16 Apr 2021 14:51:57 +0000 Subject: [PATCH] [FIX] mrp: fix multi plan MO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The button plan of in the manufacturing order tree view doesn't confirm correctly the draft MO selected (but only the related moves). task-2479111 closes odoo/odoo#70608 X-original-commit: ef9515611ac96368eae14fc941bca15e3724557a Signed-off-by: Rémy Voet Signed-off-by: William Henrotin --- addons/mrp/models/mrp_production.py | 3 +- addons/mrp/tests/test_order.py | 42 +++++++++++++++++++++++++++ addons/mrp/tests/test_stock_report.py | 10 +++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 9ab12705f53..3a32ac7b2ec 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1091,8 +1091,9 @@ class MrpProduction(models.Model): def button_plan(self): """ Create work orders. And probably do stuff, like things. """ orders_to_plan = self.filtered(lambda order: not order.is_planned) + orders_to_confirm = orders_to_plan.filtered(lambda mo: mo.state == 'draft') + orders_to_confirm.action_confirm() for order in orders_to_plan: - (order.move_raw_ids | order.move_finished_ids).filtered(lambda m: m.state == 'draft')._action_confirm() order._plan_workorders() return True diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 5bb34ba7384..a96ccf8eed8 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -1626,3 +1626,45 @@ class TestMrpOrder(TestMrpCommon): self.assertTrue(warning, 'Use of wrong serial number location not detected') self.assertEqual(list(warning.keys())[0], 'warning', 'Warning message was not returned') self.assertEqual(scrap.location_id, mo.location_dest_id, 'Location was not auto-corrected') + + def test_multi_button_plan(self): + """ Test batch methods (confirm/validate) of the MO with the same bom """ + self.bom_2.type = "normal" # avoid to get the operation of the kit bom + + mo_3 = Form(self.env['mrp.production']) + mo_3.bom_id = self.bom_3 + mo_3 = mo_3.save() + + self.assertEqual(len(mo_3.workorder_ids), 2) + + mo_3.button_plan() + self.assertEqual(mo_3.state, 'confirmed') + self.assertEqual(mo_3.workorder_ids[0].state, 'ready') + + mo_1 = Form(self.env['mrp.production']) + mo_1.bom_id = self.bom_3 + mo_1 = mo_1.save() + + mo_2 = Form(self.env['mrp.production']) + mo_2.bom_id = self.bom_3 + mo_2 = mo_2.save() + + self.assertEqual(mo_1.product_id, self.product_6) + self.assertEqual(mo_2.product_id, self.product_6) + self.assertEqual(len(self.bom_3.operation_ids), 2) + self.assertEqual(len(mo_1.workorder_ids), 2) + self.assertEqual(len(mo_2.workorder_ids), 2) + + (mo_1 | mo_2).button_plan() # Confirm and plan in the same "request" + self.assertEqual(mo_1.state, 'confirmed') + self.assertEqual(mo_2.state, 'confirmed') + self.assertEqual(mo_1.workorder_ids[0].state, 'ready') + self.assertEqual(mo_2.workorder_ids[0].state, 'ready') + + # produce + res_dict = (mo_1 | mo_2).button_mark_done() + self.assertEqual(res_dict.get('res_model'), 'mrp.immediate.production') + wizard = Form(self.env[res_dict['res_model']].with_context(res_dict['context'])).save() + wizard.process() + self.assertEqual(mo_1.state, 'done') + self.assertEqual(mo_2.state, 'done') diff --git a/addons/mrp/tests/test_stock_report.py b/addons/mrp/tests/test_stock_report.py index f4da9ff1a34..01ce0a7c55e 100644 --- a/addons/mrp/tests/test_stock_report.py +++ b/addons/mrp/tests/test_stock_report.py @@ -159,15 +159,21 @@ class TestSaleStockReports(TestReportsCommon): 'name': 'Banana', 'type': 'product', }) + product_chocolate = self.env['product.product'].create({ + 'name': 'Chocolate', + 'type': 'consu', + }) # We create 2 identical MO mo_form = Form(self.env['mrp.production']) mo_form.product_id = product_banana mo_form.product_qty = 10 + with mo_form.move_raw_ids.new() as move: + move.product_id = product_chocolate + mo_1 = mo_form.save() - mo_1.button_plan() mo_2 = mo_1.copy() - mo_2.button_plan() + (mo_1 | mo_2).action_confirm() # Check for both MO if the highlight (is_matched) corresponds to the correct MO for mo in [mo_1, mo_2]: