[IMP] mrp_multi_level: add hooks to improve extensibility

This commit is contained in:
Jordi Ballester Alomar
2024-07-26 18:23:30 +02:00
parent 006a592899
commit 4587caa27d
2 changed files with 14 additions and 7 deletions

View File

@@ -301,3 +301,7 @@ class ProductMRPArea(models.Model):
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"

View File

@@ -291,7 +291,7 @@ class MultiLevelMrp(models.TransientModel):
)
# 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 @@ class MultiLevelMrp(models.TransientModel):
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 @@ class MultiLevelMrp(models.TransientModel):
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")