[FIX] mrp: start the workorder only once
Steps to reproduce the bug: - Create a MO with work orders - Confirm the MO - Under the tab Work Orders > click on the button start multiple times quickly Problem: Several `mrp.workcentre.productivity` are created for the work order, whereas normally the workorder can have only one timer started (without date_end). Solution: - If the workorder already has a timer running, return true to stop the process - Add a constraint to block the user when he tries for example to create with an rpc call several `mrp.workcenter.productivity` without an end date for the same workoder opw-2802436 closes odoo/odoo#90094 X-original-commit: dd22195a75ec437e42424ee95ca9a41feeb48b0b Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
@@ -4373,6 +4373,12 @@ msgid ""
|
||||
"product form."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: code:addons/mrp/models/mrp_workcenter.py:0
|
||||
#, python-format
|
||||
msgid "The Workoder (%s) cannot be started twice!"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp
|
||||
#: code:addons/mrp/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
|
||||
@@ -395,6 +395,12 @@ class MrpWorkcenterProductivity(models.Model):
|
||||
else:
|
||||
blocktime.duration = 0.0
|
||||
|
||||
@api.constrains('workorder_id')
|
||||
def _check_open_time_ids(self):
|
||||
for workorder in self.workorder_id:
|
||||
if len(workorder.time_ids.filtered(lambda t: t.date_start and not t.date_end)) > 1:
|
||||
raise ValidationError(_('The Workoder (%s) cannot be started twice!', workorder.display_name))
|
||||
|
||||
def button_block(self):
|
||||
self.ensure_one()
|
||||
self.workcenter_id.order_ids.end_all()
|
||||
|
||||
@@ -552,6 +552,8 @@ class MrpWorkorder(models.Model):
|
||||
|
||||
def button_start(self):
|
||||
self.ensure_one()
|
||||
if any(time.date_start and not time.date_end for time in self.time_ids):
|
||||
return True
|
||||
# As button_start is automatically called in the new view
|
||||
if self.state in ('done', 'cancel'):
|
||||
return True
|
||||
|
||||
@@ -2754,3 +2754,23 @@ class TestMrpOrder(TestMrpCommon):
|
||||
self.assertEqual(mo.state, 'cancel', 'Manufacturing order should be cancelled.')
|
||||
self.assertEqual(wo.state, 'cancel', 'Workorders should be cancelled.')
|
||||
self.assertTrue(mo.workorder_ids.time_ids.date_end, 'The timers must stop after the cancellation of the MO')
|
||||
|
||||
def test_starting_wo_twice(self):
|
||||
"""
|
||||
Check that the work order is started only once when clicking the start button several times.
|
||||
"""
|
||||
production_form = Form(self.env['mrp.production'])
|
||||
production_form.bom_id = self.bom_2
|
||||
production_form.product_qty = 1
|
||||
production = production_form.save()
|
||||
production_form = Form(production)
|
||||
with production_form.workorder_ids.new() as wo:
|
||||
wo.name = 'OP1'
|
||||
wo.workcenter_id = self.workcenter_1
|
||||
wo.duration_expected = 40
|
||||
production = production_form.save()
|
||||
production.action_confirm()
|
||||
production.button_plan()
|
||||
production.workorder_ids[0].button_start()
|
||||
production.workorder_ids[0].button_start()
|
||||
self.assertEqual(len(production.workorder_ids[0].time_ids.filtered(lambda t: t.date_start and not t.date_end)), 1)
|
||||
|
||||
Reference in New Issue
Block a user