From a331de548fae9819de826e33adf4b2f6eaaddf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Tue, 16 May 2023 15:26:21 +0200 Subject: [PATCH] mrp_workcenter_cost: keep durations set by users --- mrp_workcenter_cost/models/mrp_production.py | 12 ++++++++++-- .../tests/test_mrp_workcenter_cost.py | 5 ++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mrp_workcenter_cost/models/mrp_production.py b/mrp_workcenter_cost/models/mrp_production.py index bb834224a..0effe4ec7 100644 --- a/mrp_workcenter_cost/models/mrp_production.py +++ b/mrp_workcenter_cost/models/mrp_production.py @@ -14,7 +14,15 @@ class MrpProduction(models.Model): self.product_id.mrp_workcenter_cost == "theoretical" and not any(t.cost_already_recorded for t in self.workorder_ids.time_ids) ) + duration_by_workorder = {} if should_overwrite_duration: - for workorder in self.workorder_ids.filtered("duration_expected"): + workorders = self.workorder_ids.filtered("duration_expected") + for workorder in workorders: + duration_by_workorder[workorder.id] = workorder.duration workorder.duration = workorder.duration_expected - return super()._cal_price(consumed_moves) + res = super()._cal_price(consumed_moves) + # Restore the durations set by users + if should_overwrite_duration: + for workorder in workorders: + workorder.duration = duration_by_workorder[workorder.id] + return res diff --git a/mrp_workcenter_cost/tests/test_mrp_workcenter_cost.py b/mrp_workcenter_cost/tests/test_mrp_workcenter_cost.py index fa007251f..81a86ffaf 100644 --- a/mrp_workcenter_cost/tests/test_mrp_workcenter_cost.py +++ b/mrp_workcenter_cost/tests/test_mrp_workcenter_cost.py @@ -65,11 +65,10 @@ class TestMrp(TransactionCase): def test_workcenter_cost_theoretical(self): self.bom.product_tmpl_id.mrp_workcenter_cost = "theoretical" - # Duration will be reset on MO validation self.production.workorder_ids.duration = 30 self._mrp_production_done(self.production) - self.assertNotEqual(self.production.workorder_ids.duration, 30) - self.assertEqual( + self.assertEqual(self.production.workorder_ids.duration, 30) + self.assertNotEqual( self.production.workorder_ids.duration, self.production.workorder_ids.duration_expected, )