[IMP] mrp_bom_attribute_match: make private methods, private

These methods shouldn't be exposed to xmlrpc.
This commit is contained in:
Ivàn Todorovich
2022-10-25 16:42:53 -03:00
committed by Ilyas
parent c079ae6990
commit b28c5bd7e4
3 changed files with 26 additions and 25 deletions

View File

@@ -39,11 +39,11 @@ class MrpBomLine(models.Model):
@api.onchange("component_template_id") @api.onchange("component_template_id")
def _onchange_component_template_id(self): def _onchange_component_template_id(self):
self.update_component_attributes() self._update_component_attributes()
def update_component_attributes(self): def _update_component_attributes(self):
if self.component_template_id: if self.component_template_id:
self.check_component_attributes() self._check_component_attributes()
self.product_backup_id = self.product_id.id self.product_backup_id = self.product_id.id
self.match_on_attribute_ids = ( self.match_on_attribute_ids = (
self.component_template_id.attribute_line_ids.mapped("attribute_id") self.component_template_id.attribute_line_ids.mapped("attribute_id")
@@ -51,14 +51,14 @@ class MrpBomLine(models.Model):
.ids .ids
) )
self.product_id = False self.product_id = False
self.check_variants_validity() self._check_variants_validity()
else: else:
self.match_on_attribute_ids = False self.match_on_attribute_ids = False
if self.product_backup_id and not self.product_id: if self.product_backup_id and not self.product_id:
self.product_id = self.product_backup_id.id self.product_id = self.product_backup_id.id
self.product_backup_id = False self.product_backup_id = False
def check_component_attributes(self): def _check_component_attributes(self):
comp_attr_ids = ( comp_attr_ids = (
self.component_template_id.valid_product_template_attribute_line_ids.attribute_id.ids self.component_template_id.valid_product_template_attribute_line_ids.attribute_id.ids
) )
@@ -84,9 +84,9 @@ class MrpBomLine(models.Model):
@api.onchange("bom_product_template_attribute_value_ids") @api.onchange("bom_product_template_attribute_value_ids")
def _onchange_attribute_value_ids(self): def _onchange_attribute_value_ids(self):
if self.bom_product_template_attribute_value_ids: if self.bom_product_template_attribute_value_ids:
self.check_variants_validity() self._check_variants_validity()
def check_variants_validity(self): def _check_variants_validity(self):
if ( if (
not self.bom_product_template_attribute_value_ids not self.bom_product_template_attribute_value_ids
or not self.component_template_id or not self.component_template_id
@@ -195,7 +195,7 @@ class MrpBom(models.Model):
update_product_boms() update_product_boms()
product_ids.clear() product_ids.clear()
# upd start # upd start
component_template_product = self.get_component_template_product( component_template_product = self._get_component_template_product(
current_line, product, current_line.product_id current_line, product, current_line.product_id
) )
if component_template_product: if component_template_product:
@@ -271,7 +271,9 @@ class MrpBom(models.Model):
) )
return boms_done, lines_done return boms_done, lines_done
def get_component_template_product(self, bom_line, bom_product_id, line_product_id): def _get_component_template_product(
self, bom_line, bom_product_id, line_product_id
):
if bom_line.component_template_id: if bom_line.component_template_id:
comp = bom_line.component_template_id comp = bom_line.component_template_id
comp_attr_ids = ( comp_attr_ids = (
@@ -313,5 +315,5 @@ class MrpBom(models.Model):
def write(self, vals): def write(self, vals):
res = super(MrpBom, self).write(vals) res = super(MrpBom, self).write(vals)
for line in self.bom_line_ids: for line in self.bom_line_ids:
line.update_component_attributes() line._update_component_attributes()
return res return res

View File

@@ -5,15 +5,14 @@ class MrpProduction(models.Model):
_inherit = "mrp.production" _inherit = "mrp.production"
def action_confirm(self): def action_confirm(self):
res = super(MrpProduction, self).action_confirm() res = super().action_confirm()
if self and self.bom_id: for bom_line in self.bom_id.bom_line_ids:
for bom_line in self.bom_id.bom_line_ids: if bom_line.component_template_id:
if bom_line.component_template_id: # product_id was set in mrp.bom.explode for correct flow. Need to remove it.
# product_id was set in mrp.bom.explode for correct flow. Need to remove it. bom_line.product_id = False
bom_line.product_id = False
return res return res
def write(self, vals): def write(self, vals):
for bl in self.bom_id.bom_line_ids.filtered(lambda x: x.component_template_id): for bl in self.bom_id.bom_line_ids.filtered("component_template_id"):
bl.check_component_attributes() bl._check_component_attributes()
return super(MrpProduction, self).write(vals) return super().write(vals)

View File

@@ -8,11 +8,11 @@ class ProductTemplate(models.Model):
def write(self, vals): def write(self, vals):
res = super().write(vals) res = super().write(vals)
for rec in self: for rec in self:
rec.check_product_with_component_change_allowed() rec._check_product_with_component_change_allowed()
rec.check_component_change_allowed() rec._check_component_change_allowed()
return res return res
def check_product_with_component_change_allowed(self): def _check_product_with_component_change_allowed(self):
self.ensure_one() self.ensure_one()
if len(self.attribute_line_ids) > 0 and len(self.bom_ids) > 0: if len(self.attribute_line_ids) > 0 and len(self.bom_ids) > 0:
for bom in self.bom_ids: for bom in self.bom_ids:
@@ -38,10 +38,10 @@ class ProductTemplate(models.Model):
) )
) )
def check_component_change_allowed(self): def _check_component_change_allowed(self):
self.ensure_one() self.ensure_one()
if len(self.attribute_line_ids) > 0: if len(self.attribute_line_ids) > 0:
boms = self.get_component_boms() boms = self._get_component_boms()
if boms: if boms:
for bom in boms: for bom in boms:
vpa = bom.product_tmpl_id.valid_product_template_attribute_line_ids vpa = bom.product_tmpl_id.valid_product_template_attribute_line_ids
@@ -61,7 +61,7 @@ class ProductTemplate(models.Model):
) )
) )
def get_component_boms(self): def _get_component_boms(self):
self.ensure_one() self.ensure_one()
bom_lines = self.env["mrp.bom.line"].search( bom_lines = self.env["mrp.bom.line"].search(
[("component_template_id", "=", self._origin.id)] [("component_template_id", "=", self._origin.id)]