From 1b1fa9ee958033ed52cee8d7b0fdc5e1d60b40fe Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Fri, 16 Sep 2022 13:03:42 +0000 Subject: [PATCH] [FIX] mrp: MTO - decrease the post production when decreasing the SO Use case to reproduce: - Create a product with manufacture and MTO route - Set the warehouse in 3 steps manufacturing - Confirm a SO for 5 units - Update the quantity to 4 units Current behavior Each picking has a quantity to 4 units. Except for the post production to stock that still for 5 units but a return is created. Expected behavior Each picking has 4 units It happens due to `_run_pull` that will create a new procurement group in post production location (the purpose is to avoid a merge between semi-finished product and finished product). But in the case of a negative procurement, we want to decrease a picking and not create a production order. So create a new procurement group with the next MO sequence will aslo create another issue because `_run_manufacture` will skip the MO creation since the quantity is negative and it will be a gap in the sequence number. Instead of creating a new procurement group, search for an existing in sibbling moves, so `_search_picking_for_assignation` could find a picking to merge the negative procurement and decrease an existing move. closes odoo/odoo#100439 X-original-commit: c5e8adaa2b364e3ff4625e080df4c523a9673668 Signed-off-by: Arnold Moyaux (arm) --- addons/mrp/models/stock_rule.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index 4fb810809cc..1bb6bc2f820 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -83,6 +83,10 @@ class StockRule(models.Model): if not warehouse_id: warehouse_id = rule.location_dest_id.warehouse_id if rule.picking_type_id == warehouse_id.sam_type_id: + if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) < 0: + procurement.values['group_id'] = procurement.values['group_id'].stock_move_ids.filtered( + lambda m: m.state not in ['done', 'cancel']).move_orig_ids.group_id[:1] + continue manu_type_id = warehouse_id.manu_type_id if manu_type_id: name = manu_type_id.sequence_id.next_by_id()