Skip to content

Commit

Permalink
[IMP]product_configurator_mrp: Parent Bom Type for New Variant of Pro…
Browse files Browse the repository at this point in the history
…duct.
  • Loading branch information
Vandan-OSI committed Jul 31, 2024
1 parent 1662454 commit 6058526
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions product_configurator_mrp/models/mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class MrpBom(models.Model):
readonly=True,
)

@api.model
def default_get(self, val_list):
result = super().default_get(val_list)
if result.get("product_tmpl_id"):
product_tmpl_id = self.env["product.template"].browse(
result.get("product_tmpl_id")
)
result["company_id"] = (
product_tmpl_id and product_tmpl_id.company_id.id or False
)
return result


class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"
Expand Down
4 changes: 4 additions & 0 deletions product_configurator_mrp/models/product_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
order="sequence asc",
limit=1,
)
bom_type = parent_bom and parent_bom.type or "normal"
bom_lines = []
if not parent_bom:
# If not Bom, then Cycle through attributes to add their
Expand Down Expand Up @@ -113,6 +114,7 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
bom_values = {
"product_tmpl_id": self.product_tmpl_id.id,
"product_id": variant.id,
"type": bom_type,
"bom_line_ids": bom_lines,
}
specs = self.get_onchange_specifications(model="mrp.bom")
Expand All @@ -133,6 +135,8 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
values.update(bom_values)
mrp_bom_id = mrpBom.create(values)
if mrp_bom_id and parent_bom:
if mrp_bom_id.company_id and not parent_bom.company_id:
mrp_bom_id.company_id = False
for operation_line in parent_bom.operation_ids:
operation_line.copy(default={"bom_id": mrp_bom_id.id})
return mrp_bom_id
Expand Down
2 changes: 1 addition & 1 deletion product_configurator_mrp/tests/test_mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class TestMrp(ProductConfiguratorTestCases):
def setUp(self):
super(TestMrp, self).setUp()
super().setUp()
self.mrpBomConfigSet = self.env["mrp.bom.line.configuration.set"]
self.mrpBomConfig = self.env["mrp.bom.line.configuration"]
self.mrpBom = self.env["mrp.bom"]
Expand Down
4 changes: 2 additions & 2 deletions product_configurator_mrp/wizard/product_configurator_mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def action_config_done(self):
return res
model_name = "mrp.production"
line_vals = self._get_order_vals(res["res_id"])
mrpProduction = self.env[model_name]
# mrpProduction = self.env[model_name]
cfg_session = self.config_session_id
specs = cfg_session.get_onchange_specifications(model=model_name)
# specs = cfg_session.get_onchange_specifications(model=model_name)
# updates = mrpProduction.onchange(line_vals, ["bom_id"], specs)
# values = updates.get("value", {})
# values = cfg_session.get_vals_to_write(values=values, model=model_name)
Expand Down

0 comments on commit 6058526

Please sign in to comment.