From 7ae5c26526a3c5455a05e200e2d00883148c816a Mon Sep 17 00:00:00 2001 From: "David (dafr)" Date: Thu, 12 Oct 2023 13:51:09 +0200 Subject: [PATCH] [FIX] mrp: use date_start for confirmed mo in _run_manufacture For Confirmed MOs, the date that should be used is the `date_start`, not the `date_deadline`: - Confirmed MOs have StockMoves with `move.date == mo.date_start` - When computing the qty_to_order, the move.date will be used - When finding existing MO to add quantity If `mo.date_deadline != mo.date_start` Then we can end up in a situation where a Confirm MO is too late to take its quantity into account, but not too late to add the qty_to_order to it. Then everytime you run the scheduler, this MO will be too late, so new quantity must be ordered, and the quantity will be added on this MO which is too late. ## TO REPRODUCE ## - Create product P_M - Create BoM - Create Reordering Rule: trigger: auto | min: 10 | max: 20 | route: manufacture - Create & Confirm SO for 10 unit of P_M => new confirmed MO for P_M should have been created - Update MO scheduled date to 2 days in the future - Run Scheduler => New quantity added, you can run the scheduler as many times as you want, new quantity will always be added OPW-3524854 closes odoo/odoo#142256 X-original-commit: 531fa573a3bb40bd3b82c2a21db5e82d51a2800a Signed-off-by: William Henrotin (whe) Signed-off-by: David Fesquet (dafr) --- addons/mrp/models/stock_rule.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index 219bde78e2b..fca88c6bdf1 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -63,8 +63,13 @@ class StockRule(models.Model): ('user_id', '=', False), ) if procurement.values.get('orderpoint_id'): - procurement_date = fields.Date.to_date(procurement.values['date_planned']) - relativedelta(days=int(bom.produce_delay)) - domain += (('date_deadline', '<=', datetime.combine(procurement_date, datetime.max.time())),) + procurement_date = datetime.combine( + fields.Date.to_date(procurement.values['date_planned']) - relativedelta(days=int(bom.produce_delay)), + datetime.max.time() + ) + domain += ('|', + '&', ('state', '=', 'draft'), ('date_deadline', '<=', procurement_date), + '&', ('state', '=', 'confirmed'), ('date_start', '<=', procurement_date)) if group: domain += (('procurement_group_id', '=', group.id),) mo = self.env['mrp.production'].sudo().search(domain, limit=1)