From 4587caa27d509f198dd14a397ace0691f0a2ab9b Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Fri, 26 Jul 2024 18:23:30 +0200 Subject: [PATCH] [IMP] mrp_multi_level: add hooks to improve extensibility --- mrp_multi_level/models/product_mrp_area.py | 4 ++++ mrp_multi_level/wizards/mrp_multi_level.py | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mrp_multi_level/models/product_mrp_area.py b/mrp_multi_level/models/product_mrp_area.py index ef62c12ef7..febca56170 100644 --- a/mrp_multi_level/models/product_mrp_area.py +++ b/mrp_multi_level/models/product_mrp_area.py @@ -301,3 +301,7 @@ def _to_be_exploded(self): def _get_locations(self): self.ensure_one() return self.mrp_area_id._get_locations() + + def _should_create_planned_order(self): + self.ensure_one() + return not self.supply_method == "phantom" diff --git a/mrp_multi_level/wizards/mrp_multi_level.py b/mrp_multi_level/wizards/mrp_multi_level.py index d44d725f67..eaed350af2 100644 --- a/mrp_multi_level/wizards/mrp_multi_level.py +++ b/mrp_multi_level/wizards/mrp_multi_level.py @@ -291,7 +291,7 @@ def create_planned_order( ) # Do not create planned order for products that are Kits planned_order = False - if not product_mrp_area_id.supply_method == "phantom": + if product_mrp_area_id._should_create_planned_order(): planned_order = self.env["mrp.planned.order"].create(order_data) qty_ordered = qty_ordered + qty @@ -814,6 +814,14 @@ def _init_mrp_inventory(self, product_mrp_area): if invs: po.mrp_inventory_id = invs[0] + def should_build_time_phased_inventory(self, product_mrp_area): + return not ( + self._exclude_from_mrp( + product_mrp_area.product_id, product_mrp_area.mrp_area_id + ) + or product_mrp_area.supply_method == "phantom" + ) + @api.model def _mrp_final_process(self, mrp_areas): logger.info("Start MRP final process") @@ -824,12 +832,7 @@ def _mrp_final_process(self, mrp_areas): for product_mrp_area in product_mrp_area_ids: # Build the time-phased inventory - if ( - self._exclude_from_mrp( - product_mrp_area.product_id, product_mrp_area.mrp_area_id - ) - or product_mrp_area.supply_method == "phantom" - ): + if not self.should_build_time_phased_inventory(product_mrp_area): continue self._init_mrp_inventory(product_mrp_area) logger.info("End MRP final process")