Merge PR #991 into 14.0

Signed-off-by LoisRForgeFlow
This commit is contained in:
OCA-git-bot
2023-04-21 07:38:14 +00:00
2 changed files with 49 additions and 38 deletions

View File

@@ -201,11 +201,12 @@ class ProductMRPArea(models.Model):
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"]
)
rec.supply_method = (
"phantom"
if rule.action == "manufacture"
and rec.product_id.product_tmpl_id.bom_ids
and rec.product_id.product_tmpl_id.bom_ids[0].type == "phantom"
if rule.action == "manufacture" and boms and boms[0].type == "phantom"
else rule.action
)

View File

@@ -8,6 +8,7 @@ import logging
from datetime import date, timedelta
from odoo import _, api, exceptions, fields, models
from odoo.tools import float_is_zero
logger = logging.getLogger(__name__)
@@ -192,6 +193,17 @@ class MultiLevelMrp(models.TransientModel):
mrp_action_date = mrp_date - timedelta(days=product_mrp_area.mrp_lead_time)
return mrp_action_date, mrp_date_supply
@api.model
def _get_bom_to_explode(self, product_mrp_area_id):
boms = self.env["mrp.bom"]
if product_mrp_area_id.supply_method in ["manufacture", "phantom"]:
boms = product_mrp_area_id.product_id.bom_ids.filtered(
lambda x: x.type in ["normal", "phantom"]
)
if not boms:
return False
return boms[0]
@api.model
def explode_action(
self, product_mrp_area_id, mrp_action_date, name, qty, action, values=None
@@ -200,17 +212,15 @@ class MultiLevelMrp(models.TransientModel):
mrp_date_demand = mrp_action_date
if mrp_date_demand < date.today():
mrp_date_demand = date.today()
if not product_mrp_area_id.product_id.bom_ids:
bom = self._get_bom_to_explode(product_mrp_area_id)
if not bom:
return False
bomcount = 0
for bom in product_mrp_area_id.product_id.bom_ids:
if not bom.active or not bom.bom_line_ids:
continue
bomcount += 1
if bomcount != 1:
continue
pd = self.env["decimal.precision"].precision_get("Product Unit of Measure")
for bomline in bom.bom_line_ids:
if bomline.product_qty <= 0.00 or bomline.product_id.type != "product":
if (
float_is_zero(bomline.product_qty, precision_digits=pd)
or bomline.product_id.type != "product"
):
continue
if self.with_context(mrp_explosion=True)._exclude_from_mrp(
bomline.product_id, product_mrp_area_id.mrp_area_id