From 8dbebbf444200bcd7c91aa9ad034b76b22357a49 Mon Sep 17 00:00:00 2001 From: Martin Maes Date: Thu, 7 Dec 2023 08:47:01 +0100 Subject: [PATCH] [FIX] mrp: fix MO qty from BoM In a Manufacturing Order based on a BoM, changing the qty values and then change the scheduled date will reset the qty to the bom ones. This should not be the case. Regarding the test, setting the date before the bom_id ensure that the date will be set when we enter the _compute_move_raw_ids. enterprise: https://github.com/odoo/enterprise/pull/51822 opw-3568943 closes odoo/odoo#146508 X-original-commit: 780dded Related: odoo/enterprise#52892 Signed-off-by: William Henrotin (whe) --- addons/mrp/models/mrp_production.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index b4538e381f7..76662b94750 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -743,7 +743,7 @@ class MrpProduction(models.Model): date_finished = date_finished + relativedelta(minutes=workorder_expected_duration or 60) production.date_finished = date_finished - @api.depends('company_id', 'bom_id', 'product_id', 'product_qty', 'product_uom_id', 'location_src_id', 'date_start') + @api.depends('company_id', 'bom_id', 'product_id', 'product_qty', 'product_uom_id', 'location_src_id') def _compute_move_raw_ids(self): for production in self: if production.state != 'draft': @@ -913,7 +913,23 @@ class MrpProduction(models.Model): if not vals.get('procurement_group_id'): procurement_group_vals = self._prepare_procurement_group_vals(vals) vals['procurement_group_id'] = self.env["procurement.group"].create(procurement_group_vals).id - return super().create(vals_list) + res = super().create(vals_list) + # Make sure that the date passed in vals_list are taken into account and not modified by a compute + for rec, vals in zip(res, vals_list): + if (rec.move_raw_ids + and rec.move_raw_ids[0].date + and vals.get('date_start') + and rec.move_raw_ids[0].date != vals['date_start']): + rec.move_raw_ids.write({ + 'date': vals['date_start'], + 'date_deadline': vals['date_start'] + }) + if (rec.move_finished_ids + and rec.move_finished_ids[0].date + and vals.get('date_finished') + and rec.move_finished_ids[0].date != vals['date_finished']): + rec.move_finished_ids.write({'date': vals['date_finished']}) + return res def unlink(self): self.action_cancel()