Skip to content
Snippets Groups Projects
Commit ec86c67a authored by Nathan Marotte (nama)'s avatar Nathan Marotte (nama)
Browse files

[FIX] mrp : Confirm MO twice generates multiple stock move


Issue: When two Odoo webpage are open on a Manufacturing order, it is
possible to mark the MO as todo twice, then when trying to record the
production, there will be a traceback Expected Singleton

Steps to reproduce:
 1) Install MRP
 2) Create a Manufacturing order for a Product with a BO
 3) Save, open a new odoo webclient and go to the same MO
 4) Mark as todo on each webclient
 5) Check availability on each webclient
 6) Produce on each webclient, and save the wizard
 -> Traceback Expected Singleton

opw-2636556

closes odoo/odoo#76210

Signed-off-by: default avatarArnold Moyaux <amoyaux@users.noreply.github.com>
parent 3b8615c0
No related branches found
No related tags found
No related merge requests found
......@@ -686,6 +686,9 @@ class MrpProduction(models.Model):
def action_confirm(self):
self._check_company()
for production in self:
# Avoid confirming it twice
if production.state != 'draft':
continue
if not production.move_raw_ids:
raise UserError(_("Add some materials to consume before marking this MO as to do."))
for move_raw in production.move_raw_ids:
......
......@@ -1552,3 +1552,39 @@ class TestRoutingAndKits(SavepointCase):
wo2.button_start()
self.assertEqual(wo2.qty_producing, 10)
self.assertEqual(wo2.finished_lot_id, lot1)
def test_confirm_twice(self):
"""
Test that when confirming a production twice (mark as to do), the moves are only generated once
One assert and one "assertNotRaise"
"""
product_inside = self.env['product.product'].create({'name': 'Wood'})
product = self.env['product.product'].create({'name': 'Woooden stick'})
bom = self.env['mrp.bom'].create({
'product_id': product.id,
'product_tmpl_id': product.product_tmpl_id.id,
'product_qty': 1.0,
'type': 'normal',
'bom_line_ids': [(0, 0, {'product_id': product_inside.id, 'product_qty': 1})]
})
production_table_form = Form(self.env['mrp.production'])
production_table_form.product_id = product
production_table_form.bom_id = bom
production_table_form.product_qty = 2.0
production_table = production_table_form.save()
# Confirm twice to generate the issue
production_table.action_confirm()
previous_move_finished_ids = production_table.move_finished_ids
production_table.action_confirm()
# The actual test
self.assertEqual(production_table.move_finished_ids, previous_move_finished_ids, "Confirming it twice should not generate another move finished id")
# Then we continue testing the business flow for double protection
# since there is a blocking traceback we want to ensure it doesn't appear
production_table.action_assign()
context = {'active_id': production_table.id, 'active_model': 'mrp.production'}
wizard = self.env['mrp.product.produce'].with_context(context).create({})
# Will raise Expected Singleton if we actually managed to confirm twice
wizard.do_produce()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment