From 85ab16bda47ec710b105d1efe7f6bc9364e65c9f Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Tue, 8 Feb 2022 10:48:31 -0500 Subject: [PATCH] [14.0][FIX] product_configurator_sale (Custom Values on Reconfigure) pre-commit --- .../wizard/product_configurator.py | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/product_configurator_sale/wizard/product_configurator.py b/product_configurator_sale/wizard/product_configurator.py index 3cfb90f745..8db2193652 100644 --- a/product_configurator_sale/wizard/product_configurator.py +++ b/product_configurator_sale/wizard/product_configurator.py @@ -1,7 +1,7 @@ # Copyright (C) 2021 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class ProductConfiguratorSale(models.TransientModel): @@ -52,3 +52,33 @@ def action_config_done(self): else: self.order_id.write({"order_line": [(0, 0, values)]}) return + + @api.model + def create(self, vals): + if self.env.context.get("default_order_line_id", False): + sale_line = self.env["sale.order.line"].browse( + self.env.context["default_order_line_id"] + ) + if sale_line.custom_value_ids: + vals["custom_value_ids"] = self._get_custom_values( + sale_line.config_session_id + ) + res = super(ProductConfiguratorSale, self).create(vals) + return res + + def _get_custom_values(self, session): + custom_values = [(5,)] + [ + ( + 0, + 0, + { + "attribute_id": value_custom.attribute_id.id, + "value": value_custom.value, + "attachment_ids": [ + (4, attach.id) for attach in value_custom.attachment_ids + ], + }, + ) + for value_custom in session.custom_value_ids + ] + return custom_values