diff --git a/mrp_multi_level/models/product_mrp_area.py b/mrp_multi_level/models/product_mrp_area.py index ce8a2c9097..e6153a005d 100644 --- a/mrp_multi_level/models/product_mrp_area.py +++ b/mrp_multi_level/models/product_mrp_area.py @@ -206,18 +206,19 @@ def _compute_supply_method(self): boms_by_product = self.env["mrp.bom"]._bom_find(self.mapped("product_id")) for rec in self: rule = rec._get_rule() - if not rule: + bom = boms_by_product.get(rec.product_id, self.env["mrp.bom"]) + if bom.type == "phantom": + rec.supply_method = "phantom" + rec.supply_bom_id = bom + elif not rule: rec.supply_method = "none" rec.supply_bom_id = False - continue - # Determine the supply method based on the final rule. - bom = boms_by_product.get(rec.product_id, self.env["mrp.bom"]) - rec.supply_method = ( - "phantom" - if rule.action == "manufacture" and bom.type == "phantom" - else rule.action - ) - rec.supply_bom_id = bom + elif rule.action == "manufacture": + rec.supply_method = rule.action + rec.supply_bom_id = bom + else: + rec.supply_method = rule.action + rec.supply_bom_id = False @api.depends( "mrp_area_id", "supply_method", "product_id.route_ids", "product_id.seller_ids" diff --git a/mrp_multi_level/tests/test_mrp_multi_level.py b/mrp_multi_level/tests/test_mrp_multi_level.py index 8db2b70466..dcff742300 100644 --- a/mrp_multi_level/tests/test_mrp_multi_level.py +++ b/mrp_multi_level/tests/test_mrp_multi_level.py @@ -444,11 +444,31 @@ def test_17_supply_method(self): self.fp_4.route_ids = [(4, self.env.ref("mrp.route_warehouse0_manufacture").id)] product_mrp_area._compute_supply_method() self.assertEqual(product_mrp_area.supply_method, "manufacture") + # because of the issue discussed here https://github.com/odoo/odoo/pull/188846 + # we need to apply routes explicitly in the proper order (by sequence) self.fp_4.route_ids = [ - (4, self.env.ref("purchase_stock.route_warehouse0_buy").id) + ( + 6, + 0, + ( + self.env.ref("stock.route_warehouse0_mto") + + self.env.ref("purchase_stock.route_warehouse0_buy") + + self.env.ref("mrp.route_warehouse0_manufacture") + ).ids, + ) ] product_mrp_area._compute_supply_method() self.assertEqual(product_mrp_area.supply_method, "buy") + kit_bom = self.mrp_bom_obj.create( + { + "product_tmpl_id": self.fp_4.product_tmpl_id.id, + "product_id": self.fp_4.id, + "type": "phantom", + } + ) + product_mrp_area._compute_supply_method() + self.assertEqual(product_mrp_area.supply_method, "phantom") + self.assertEqual(product_mrp_area.supply_bom_id, kit_bom) def test_18_priorize_safety_stock(self): now = datetime.now()