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 break
rule = new_rule rule = new_rule
# Determine the supply method based on the final 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 = ( rec.supply_method = (
"phantom" "phantom"
if rule.action == "manufacture" if rule.action == "manufacture" and boms and boms[0].type == "phantom"
and rec.product_id.product_tmpl_id.bom_ids
and rec.product_id.product_tmpl_id.bom_ids[0].type == "phantom"
else rule.action else rule.action
) )

View File

@@ -8,6 +8,7 @@ import logging
from datetime import date, timedelta from datetime import date, timedelta
from odoo import _, api, exceptions, fields, models from odoo import _, api, exceptions, fields, models
from odoo.tools import float_is_zero
logger = logging.getLogger(__name__) 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) mrp_action_date = mrp_date - timedelta(days=product_mrp_area.mrp_lead_time)
return mrp_action_date, mrp_date_supply 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 @api.model
def explode_action( def explode_action(
self, product_mrp_area_id, mrp_action_date, name, qty, action, values=None self, product_mrp_area_id, mrp_action_date, name, qty, action, values=None
@@ -200,45 +212,43 @@ class MultiLevelMrp(models.TransientModel):
mrp_date_demand = mrp_action_date mrp_date_demand = mrp_action_date
if mrp_date_demand < date.today(): if mrp_date_demand < date.today():
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 return False
bomcount = 0 pd = self.env["decimal.precision"].precision_get("Product Unit of Measure")
for bom in product_mrp_area_id.product_id.bom_ids: for bomline in bom.bom_line_ids:
if not bom.active or not bom.bom_line_ids: if (
float_is_zero(bomline.product_qty, precision_digits=pd)
or bomline.product_id.type != "product"
):
continue continue
bomcount += 1 if self.with_context(mrp_explosion=True)._exclude_from_mrp(
if bomcount != 1: bomline.product_id, product_mrp_area_id.mrp_area_id
):
# Stop explosion.
continue continue
for bomline in bom.bom_line_ids: if bomline._skip_bom_line(product_mrp_area_id.product_id):
if bomline.product_qty <= 0.00 or bomline.product_id.type != "product": continue
continue # TODO: review: mrp_transit_delay, mrp_inspection_delay
if self.with_context(mrp_explosion=True)._exclude_from_mrp( mrp_date_demand_2 = mrp_date_demand - timedelta(
bomline.product_id, product_mrp_area_id.mrp_area_id days=(
): product_mrp_area_id.mrp_transit_delay
# Stop explosion. + product_mrp_area_id.mrp_inspection_delay
continue
if bomline._skip_bom_line(product_mrp_area_id.product_id):
continue
# TODO: review: mrp_transit_delay, mrp_inspection_delay
mrp_date_demand_2 = mrp_date_demand - timedelta(
days=(
product_mrp_area_id.mrp_transit_delay
+ product_mrp_area_id.mrp_inspection_delay
)
) )
move_data = self._prepare_mrp_move_data_bom_explosion( )
product_mrp_area_id, move_data = self._prepare_mrp_move_data_bom_explosion(
bomline, product_mrp_area_id,
qty, bomline,
mrp_date_demand_2, qty,
bom, mrp_date_demand_2,
name, bom,
action, name,
values, action,
) values,
mrpmove_id2 = self.env["mrp.move"].create(move_data) )
if hasattr(action, "mrp_move_down_ids"): mrpmove_id2 = self.env["mrp.move"].create(move_data)
action.mrp_move_down_ids = [(4, mrpmove_id2.id)] if hasattr(action, "mrp_move_down_ids"):
action.mrp_move_down_ids = [(4, mrpmove_id2.id)]
return True return True
@api.model @api.model