Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] product_configurator_mrp (Set BoM Sequences) #1

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions product_configurator_mrp/models/mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ class MrpBom(models.Model):
readonly=True,
)

def set_bom_sequences(self, product_tmpl_id=None):
# Set BoM Sequences. For MO, Odoo will look for the first BoM to use, which is
# usually the Master BoM without a variant. Setting the Master BoM sequence
# higher will ensure Odoo doesn't use the master BoM when it should use
# variant's BoM
related_boms = self.env["mrp.bom"].search(
[("product_tmpl_id", "=", product_tmpl_id.id)]
)
if related_boms:
for bom in related_boms:
if bom.product_id and bom.sequence == 0:
bom.write({"sequence": 1})
elif not bom.product_id:
bom.write({"sequence": len(related_boms)})


class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"
Expand Down
5 changes: 4 additions & 1 deletion product_configurator_mrp/models/product_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None):
mrp_bom_id = mrpBom.create(values)
if mrp_bom_id and parent_bom:
for operation_line in parent_bom.operation_ids:
operation_line.copy(default={"bom_id": mrp_bom_id.id})
new_op = operation_line.copy(default={"bom_id": mrp_bom_id.id})
for step in new_op.quality_point_ids:
step.write({"product_ids": [(6, 0, [variant.id])]})
mrp_bom_id.set_bom_sequences(mrp_bom_id.product_tmpl_id)
return mrp_bom_id
return False

Expand Down