[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#70608

X-original-commit: ef9515611ac96368eae14fc941bca15e3724557a
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
Rémy Voet (ryv)
2021-05-10 13:29:20 +00:00
parent 6c0edacc6e
commit b23edf5db2
3 changed files with 52 additions and 3 deletions
+2 -1
View File
@@ -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
+42
View File
@@ -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')
+8 -2
View File
@@ -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]: