From e8bb3e93d3acd830009d0f28f9a306af1696ef6a Mon Sep 17 00:00:00 2001 From: Brammer Brakel Date: Mon, 7 Nov 2022 13:49:18 -0500 Subject: [PATCH 1/2] [14.0][IMP] product_configurator_mrp (Set BoM Sequences) --- product_configurator_mrp/models/mrp.py | 15 +++++++++++++++ product_configurator_mrp/models/product_config.py | 1 + 2 files changed, 16 insertions(+) diff --git a/product_configurator_mrp/models/mrp.py b/product_configurator_mrp/models/mrp.py index 4c67cc780d..a34e6cfd40 100644 --- a/product_configurator_mrp/models/mrp.py +++ b/product_configurator_mrp/models/mrp.py @@ -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" diff --git a/product_configurator_mrp/models/product_config.py b/product_configurator_mrp/models/product_config.py index 9c245c6157..be64bb0e29 100644 --- a/product_configurator_mrp/models/product_config.py +++ b/product_configurator_mrp/models/product_config.py @@ -122,6 +122,7 @@ def create_get_bom(self, variant, product_tmpl_id=None, values=None): 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}) + mrp_bom_id.set_bom_sequences(mrp_bom_id.product_tmpl_id) return mrp_bom_id return False From c4dd5fa23535acbf36c817ede7c13effecad15be Mon Sep 17 00:00:00 2001 From: Brammer Brakel Date: Mon, 7 Nov 2022 13:54:30 -0500 Subject: [PATCH 2/2] [14.0][FIX] product_configurator_mrp (Operation Steps) --- product_configurator_mrp/models/product_config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/product_configurator_mrp/models/product_config.py b/product_configurator_mrp/models/product_config.py index be64bb0e29..f8d5aac5f0 100644 --- a/product_configurator_mrp/models/product_config.py +++ b/product_configurator_mrp/models/product_config.py @@ -121,7 +121,9 @@ 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