mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_multi_level: avoid recursion on LLC calculation.
Introduce a safe and configurable LLC depth limit to avoid infinite recursion. Also, improve extensibility of BoM finding and fix it to not consider archived BoMs.
This commit is contained in:
committed by
Bernat Puig Font
parent
d90552bfa0
commit
d8de668a88
@@ -16,6 +16,7 @@
|
|||||||
"data": [
|
"data": [
|
||||||
"security/mrp_multi_level_security.xml",
|
"security/mrp_multi_level_security.xml",
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
|
"data/system_parameter.xml",
|
||||||
"views/mrp_area_views.xml",
|
"views/mrp_area_views.xml",
|
||||||
"views/product_product_views.xml",
|
"views/product_product_views.xml",
|
||||||
"views/product_template_views.xml",
|
"views/product_template_views.xml",
|
||||||
|
|||||||
7
mrp_multi_level/data/system_parameter.xml
Normal file
7
mrp_multi_level/data/system_parameter.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo noupdate="1">
|
||||||
|
<record id="llc_calculation_recursion_limit" model="ir.config_parameter">
|
||||||
|
<field name="key">mrp_multi_level.llc_calculation_recursion_limit</field>
|
||||||
|
<field name="value">1000</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -318,11 +318,31 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
logger.info("End MRP Cleanup")
|
logger.info("End MRP Cleanup")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _domain_bom_lines_by_llc(self, llc, product_templates):
|
||||||
|
return [
|
||||||
|
("product_id.llc", "=", llc),
|
||||||
|
("bom_id.product_tmpl_id", "in", product_templates.ids),
|
||||||
|
("bom_id.active", "=", True),
|
||||||
|
]
|
||||||
|
|
||||||
|
def _get_bom_lines_by_llc(self, llc, product_templates):
|
||||||
|
return self.env["mrp.bom.line"].search(
|
||||||
|
self._domain_bom_lines_by_llc(llc, product_templates)
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _low_level_code_calculation(self):
|
def _low_level_code_calculation(self):
|
||||||
logger.info("Start low level code calculation")
|
logger.info("Start low level code calculation")
|
||||||
counter = 999999
|
counter = 999999
|
||||||
llc = 0
|
llc = 0
|
||||||
|
llc_recursion_limit = (
|
||||||
|
int(
|
||||||
|
self.env["ir.config_parameter"]
|
||||||
|
.sudo()
|
||||||
|
.get_param("mrp_multi_level.llc_calculation_recursion_limit")
|
||||||
|
)
|
||||||
|
or 1000
|
||||||
|
)
|
||||||
self.env["product.product"].search([]).write({"llc": llc})
|
self.env["product.product"].search([]).write({"llc": llc})
|
||||||
products = self.env["product.product"].search([("llc", "=", llc)])
|
products = self.env["product.product"].search([("llc", "=", llc)])
|
||||||
if products:
|
if products:
|
||||||
@@ -334,12 +354,7 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
llc += 1
|
llc += 1
|
||||||
products = self.env["product.product"].search([("llc", "=", llc - 1)])
|
products = self.env["product.product"].search([("llc", "=", llc - 1)])
|
||||||
p_templates = products.mapped("product_tmpl_id")
|
p_templates = products.mapped("product_tmpl_id")
|
||||||
bom_lines = self.env["mrp.bom.line"].search(
|
bom_lines = self._get_bom_lines_by_llc(llc - 1, p_templates)
|
||||||
[
|
|
||||||
("product_id.llc", "=", llc - 1),
|
|
||||||
("bom_id.product_tmpl_id", "in", p_templates.ids),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
products = bom_lines.mapped("product_id")
|
products = bom_lines.mapped("product_id")
|
||||||
products.write({"llc": llc})
|
products.write({"llc": llc})
|
||||||
counter = self.env["product.product"].search_count([("llc", "=", llc)])
|
counter = self.env["product.product"].search_count([("llc", "=", llc)])
|
||||||
@@ -347,6 +362,9 @@ class MultiLevelMrp(models.TransientModel):
|
|||||||
llc, counter
|
llc, counter
|
||||||
)
|
)
|
||||||
logger.info(log_msg)
|
logger.info(log_msg)
|
||||||
|
if llc > llc_recursion_limit:
|
||||||
|
logger.error("Recursion limit reached during LLC calculation.")
|
||||||
|
break
|
||||||
|
|
||||||
mrp_lowest_llc = llc
|
mrp_lowest_llc = llc
|
||||||
logger.info("End low level code calculation")
|
logger.info("End low level code calculation")
|
||||||
|
|||||||
Reference in New Issue
Block a user