diff options
| author | Rémy Voet (ryv) <ryv@odoo.com> | 2021-04-16 14:51:57 +0000 |
|---|---|---|
| committer | Rémy Voet (ryv) <ryv@odoo.com> | 2021-04-19 09:42:08 +0000 |
| commit | b9845323fc6383bcbf90599fd062bea3528f97b4 (patch) | |
| tree | ec8858693fd38ba1d81d96c27318d7c4b6f94b9e /addons | |
| parent | 4de0ae434d1adc97fc1077b8d0f23c7e800ec161 (diff) | |
[FIX] mrp: fix multi plan MO
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#69409
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mrp/models/mrp_production.py | 3 | ||||
| -rw-r--r-- | addons/mrp/tests/test_order.py | 42 |
2 files changed, 44 insertions, 1 deletions
diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 30e147487d7..051913b4635 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1120,8 +1120,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 90f0fe9d8db..3f20e9e41b8 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -1552,3 +1552,45 @@ class TestMrpOrder(TestMrpCommon): # of a conversion 187.5ml = 0.188L # thus creating an extra line with 'product_uom_qty': 0.5 self.assertEqual(len(mo_product_final_form.move_raw_ids.move_line_ids), 1, 'One move line should exist for the MO.') + + 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') |
