Skip to content

Commit

Permalink
[MIG] Migrated a module in v17.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar-OSI committed Feb 22, 2024
1 parent 61cfa38 commit 01e170b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 71 deletions.
2 changes: 1 addition & 1 deletion product_configurator_mrp_component/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Product Configurator Manufacturing Components",
"version": "14.0.1.1.3",
"version": "17.0.1.0.0",
"category": "Manufacturing",
"summary": "BOM Support for configurable products",
"author": "Pledra, Odoo Community Association (OCA)",
Expand Down
136 changes: 70 additions & 66 deletions product_configurator_mrp_component/models/product_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,81 @@ class ProductConfigSession(models.Model):
_inherit = "product.config.session"

def create_get_bom(self, variant, product_tmpl_id=None, values=None):
master_bom = self.env["mrp.bom"].search(
[
("product_tmpl_id", "=", product_tmpl_id.id),
("product_id", "=", False),
],
order="sequence asc",
limit=1,
)
vals = False
wizard_values = variant.product_template_attribute_value_ids.mapped(
"product_attribute_value_id"
)
for config_component_line in master_bom.bom_line_config_ids:
config_component_vals = config_component_line.product_tmpl_id.mapped(
"attribute_line_ids.value_ids"
if product_tmpl_id:
master_bom = self.env["mrp.bom"].search(
[
("product_tmpl_id", "=", product_tmpl_id.id),
("product_id", "=", False),
],
order="sequence asc",
limit=1,
)
vals = set(wizard_values.ids).intersection(set(config_component_vals.ids))

# Bypass config component variant creation if not all required vals are set
do_not_create = False
for line in config_component_line.product_tmpl_id.attribute_line_ids:
common_vals = set(vals) & set(line.value_ids.ids)
if line.required and not common_vals:
do_not_create = True
if do_not_create:
continue

# Otherwise create config component variant and bom
else:
component_config_session = self.create_get_session(
config_component_line.product_tmpl_id.id
vals = False
wizard_values = variant.product_template_attribute_value_ids.mapped(
"product_attribute_value_id"
)
for config_component_line in master_bom.bom_line_config_ids:
config_component_vals = config_component_line.product_tmpl_id.mapped(
"attribute_line_ids.value_ids"
)
component_config_session.write({"value_ids": [(6, 0, vals)]})
component_config_session.action_confirm()
component_variant = component_config_session.product_id

# Look for existing configuration set and if doesn't exist, create it.
bom_line_config_set = self.env["mrp.bom.line.configuration.set"].search(
[("name", "=", component_variant.display_name)],
limit=1,
vals = set(wizard_values.ids).intersection(
set(config_component_vals.ids)
)
if not bom_line_config_set:
# Bypass config component variant creation if not all required vals are set
do_not_create = False
for line in config_component_line.product_tmpl_id.attribute_line_ids:
common_vals = set(vals) & set(line.value_ids.ids)
if line.required and not common_vals:
do_not_create = True
if do_not_create:
continue

# Otherwise create config component variant and bom
else:
component_config_session = self.create_get_session(
config_component_line.product_tmpl_id.id
)
component_config_session.write({"value_ids": [(6, 0, vals)]})
component_config_session.action_confirm()
component_variant = component_config_session.product_id

# Look for existing configuration set and if doesn't exist, create it.
bom_line_config_set = self.env[
"mrp.bom.line.configuration.set"
].create(
{
"name": component_variant.display_name,
}
].search(
[("name", "=", component_variant.display_name)],
limit=1,
)
self.env["mrp.bom.line.configuration"].create(
{
"config_set_id": bom_line_config_set.id,
"value_ids": [(6, 0, vals)],
}
)
# Look for existing bom line and if doesn't exist, create it.
existing_bom_line = self.env["mrp.bom.line"].search(
[
("bom_id", "=", master_bom.id),
("product_id", "=", component_config_session.product_id.id),
("config_set_id", "=", bom_line_config_set.id),
],
limit=1,
)
if not existing_bom_line:
self.env["mrp.bom.line"].create(
{
"bom_id": master_bom.id,
"product_id": component_variant.id,
"config_set_id": bom_line_config_set.id,
"product_qty": config_component_line.product_qty,
}
if not bom_line_config_set:
bom_line_config_set = self.env[
"mrp.bom.line.configuration.set"
].create(
{
"name": component_variant.display_name,
}
)
self.env["mrp.bom.line.configuration"].create(
{
"config_set_id": bom_line_config_set.id,
"value_ids": [(6, 0, vals)],
}
)
# Look for existing bom line and if doesn't exist, create it.
existing_bom_line = self.env["mrp.bom.line"].search(
[
("bom_id", "=", master_bom.id),
("product_id", "=", component_config_session.product_id.id),
("config_set_id", "=", bom_line_config_set.id),
],
limit=1,
)
if not existing_bom_line:
self.env["mrp.bom.line"].create(
{
"bom_id": master_bom.id,
"product_id": component_variant.id,
"config_set_id": bom_line_config_set.id,
"product_qty": config_component_line.product_qty,
}
)
return super().create_get_bom(variant, product_tmpl_id=None, values=None)
6 changes: 2 additions & 4 deletions product_configurator_mrp_component/views/mrp_bom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<odoo>

<record id="mrp_bom_configurable_components_inherit" model="ir.ui.view">
<field name="name">mrp.bom.configure.components</field>
<field name="model">mrp.bom</field>
Expand All @@ -9,7 +8,7 @@
<page
name="config_components"
string="Configurable Components"
attrs="{'invisible':[('config_ok', '=', False)]}"
invisible="not config_ok"
>
<field name="available_config_components" invisible="1" />
<field
Expand Down Expand Up @@ -63,7 +62,7 @@
readonly="True"
class="oe_inline oe_stat_button"
icon="fa-exclamation-triangle"
attrs="{'invisible': ['|', ('config_ok', '=', False), ('product_template_attribute_value_ids', '!=', [])]}"
invisible="not config_ok or product_template_attribute_value_ids"
string=""
title="Product has been set to configurable."
/>
Expand All @@ -80,5 +79,4 @@
</field>
</field>
</record>

</odoo>

0 comments on commit 01e170b

Please sign in to comment.