diff --git a/product_configurator/models/product_attribute.py b/product_configurator/models/product_attribute.py index 6fd8c22d..b9a75069 100644 --- a/product_configurator/models/product_attribute.py +++ b/product_configurator/models/product_attribute.py @@ -36,6 +36,12 @@ def onchange_custom_type(self): def onchange_val_custom_field(self): if not self.val_custom: self.custom_type = False + self.quantity = False + + @api.onchange('quantity') + def onchange_quantity(self): + if self.quantity: + self.custom_type = "int" CUSTOM_TYPES = [ ('char', 'Char'), @@ -101,7 +107,10 @@ def onchange_val_custom_field(self): "when there is no available attribute values, in the configuration " "interface" ) - + quantity = fields.Boolean(string="Quantity") + attr_product_id = fields.Many2one( + comodel_name="product.product", string="Product" + ) # TODO prevent the same attribute from being defined twice on the # attribute lines @@ -166,6 +175,8 @@ def onchange_attribute(self): self.multi = self.attribute_id.multi self.custom = self.attribute_id.val_custom self.hide = self.attribute_id.hide + self.quantity = self.attribute_id.quantity + self.attr_product_id = self.attribute_id.attr_product_id # TODO: Remove all dependencies pointed towards the attribute being # changed @@ -202,9 +213,19 @@ def onchange_values(self): "when there is no available attribute values, in the configuration " "interface" ) + quantity = fields.Boolean(string="Quantity") # TODO: Constraint not allowing introducing dependencies that do not exist # on the product.template + @api.onchange('custom') + def onchange_custom_field(self): + if not self.custom: + self.quantity = False + self.attr_product_id = False + else: + self.quantity = self.attribute_id.quantity + self.attr_product_id = self.attribute_id.attr_product_id + def _search_product_template_value_ids(self, operator, value): return [('id', operator, value)] diff --git a/product_configurator/models/product_config.py b/product_configurator/models/product_config.py index 5d8a00f5..99bae6fe 100644 --- a/product_configurator/models/product_config.py +++ b/product_configurator/models/product_config.py @@ -819,7 +819,7 @@ def get_cfg_price(self, value_ids=None, custom_vals=None): value_ids = self.value_ids.ids if custom_vals is None: - custom_vals = {} + custom_vals = self._get_custom_vals_dict() product_tmpl = self.product_tmpl_id self = self.with_context({'active_id': product_tmpl.id}) @@ -834,7 +834,23 @@ def get_cfg_price(self, value_ids=None, custom_vals=None): pt_attr_value_ids=av_ids, ) price_extra = sum(extra_prices.values()) - return product_tmpl.list_price + price_extra + + pricelist = self.env.context.get("pricelist") + if pricelist: + pricelist = self.env["product.pricelist"].browse(pricelist) + else: + pricelist = self.env.user.partner_id.property_product_pricelist + custom_vals_price = 0 + for attribute, custom_val in custom_vals.items(): + attribute_id = self.env["product.attribute"].browse(attribute) + if attribute_id.quantity and attribute_id.attr_product_id: + custom_vals_price += ( + attribute_id.attr_product_id.with_context( + pricelist=pricelist.id + ).price * custom_val + ) + + return product_tmpl.list_price + price_extra + custom_vals_price def _get_config_image( self, value_ids=None, custom_vals=None, size=None): diff --git a/product_configurator/views/product_attribute_view.xml b/product_configurator/views/product_attribute_view.xml index e4d66f37..e61e4991 100644 --- a/product_configurator/views/product_attribute_view.xml +++ b/product_configurator/views/product_attribute_view.xml @@ -70,9 +70,11 @@ + + @@ -80,7 +82,7 @@ - +