From a32c519f72be3c3b950a8514c4689f0701e0ae12 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Tue, 30 Jul 2024 11:50:14 +0200 Subject: [PATCH] [IMP] mrp_multi_level: hook for method to get rule --- mrp_multi_level/models/product_mrp_area.py | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/mrp_multi_level/models/product_mrp_area.py b/mrp_multi_level/models/product_mrp_area.py index 9207a3fda3..3ef93d18a1 100644 --- a/mrp_multi_level/models/product_mrp_area.py +++ b/mrp_multi_level/models/product_mrp_area.py @@ -178,31 +178,38 @@ def _compute_qty_available(self): location=rec._get_locations().ids ).qty_available - def _compute_supply_method(self): + def _get_rule(self): + self.ensure_one() group_obj = self.env["procurement.group"] + proc_loc = self.location_proc_id or self.location_id + values = { + "warehouse_id": self.mrp_area_id.warehouse_id, + "company_id": self.company_id, + } + rule = group_obj._get_rule(self.product_id, proc_loc, values) + if not rule: + return False + # Keep getting the rule for the product and the source location until the + # action is "buy" or "manufacture". Or until the action is "Pull From" or + # "Pull & Push" and the supply method is "Take from Stock". + while rule.action not in ("buy", "manufacture") and rule.procure_method in ( + "make_to_order", + "mts_else_mto", + ): + new_rule = group_obj._get_rule( + self.product_id, rule.location_src_id, values + ) + if not new_rule: + break + rule = new_rule + return rule + + def _compute_supply_method(self): for rec in self: - proc_loc = rec.location_proc_id or rec.location_id - values = { - "warehouse_id": rec.mrp_area_id.warehouse_id, - "company_id": rec.company_id, - } - rule = group_obj._get_rule(rec.product_id, proc_loc, values) + rule = rec._get_rule() if not rule: rec.supply_method = "none" continue - # Keep getting the rule for the product and the source location until the - # action is "buy" or "manufacture". Or until the action is "Pull From" or - # "Pull & Push" and the supply method is "Take from Stock". - while rule.action not in ("buy", "manufacture") and rule.procure_method in ( - "make_to_order", - "mts_else_mto", - ): - new_rule = group_obj._get_rule( - rec.product_id, rule.location_src_id, values - ) - if not new_rule: - break - rule = new_rule # Determine the supply method based on the final rule. boms = rec.product_id.product_tmpl_id.bom_ids.filtered( lambda x: x.type in ["normal", "phantom"]