Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit e80de38

Browse files
committed
[FIX]is quantity ticked and product is there on attribute then add in price custom-val * attribute-product-price
1 parent 20c3a91 commit e80de38

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

product_configurator/models/product_attribute.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ def onchange_val_custom_field(self):
3838
self.custom_type = False
3939
self.quantity = False
4040

41+
@api.onchange('quantity')
42+
def onchange_quantity(self):
43+
if self.quantity:
44+
self.custom_type = "int"
45+
4146
CUSTOM_TYPES = [
4247
('char', 'Char'),
4348
('int', 'Integer'),
@@ -203,6 +208,8 @@ def onchange_values(self):
203208
def onchange_custom_field(self):
204209
if not self.custom:
205210
self.quantity = False
211+
else:
212+
self.quantity = self.attribute_id.quantity
206213

207214
def _search_product_template_value_ids(self, operator, value):
208215
return [('id', operator, value)]

product_configurator/models/product_config.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def get_cfg_price(self, value_ids=None, custom_vals=None):
819819
value_ids = self.value_ids.ids
820820

821821
if custom_vals is None:
822-
custom_vals = {}
822+
custom_vals = self._get_custom_vals_dict()
823823

824824
product_tmpl = self.product_tmpl_id
825825
self = self.with_context({'active_id': product_tmpl.id})
@@ -834,7 +834,24 @@ def get_cfg_price(self, value_ids=None, custom_vals=None):
834834
pt_attr_value_ids=av_ids,
835835
)
836836
price_extra = sum(extra_prices.values())
837-
return product_tmpl.list_price + price_extra
837+
838+
pricelist = self.env.context.get("pricelist")
839+
if pricelist:
840+
pricelist = self.env["product.pricelist"].browse(pricelist)
841+
else:
842+
pricelist = self.env.user.partner_id.property_product_pricelist
843+
custom_vals_price = 0
844+
print("custom_vals ", custom_vals)
845+
for attribute, custom_val in custom_vals.items():
846+
attribute_id = self.env["product.attribute"].browse(attribute)
847+
if attribute_id.quantity and attribute_id.attr_product_id:
848+
custom_vals_price += (
849+
attribute_id.attr_product_id.with_context(
850+
pricelist=pricelist.id
851+
).price * custom_val
852+
)
853+
854+
return product_tmpl.list_price + price_extra + custom_vals_price
838855

839856
def _get_config_image(
840857
self, value_ids=None, custom_vals=None, size=None):

product_configurator/views/product_attribute_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<page string="Custom Values" attrs="{'invisible': [('val_custom', '!=', True)]}" groups="product_configurator.group_product_configurator_manager">
8282
<group>
8383
<group>
84-
<field name="custom_type"/>
84+
<field name="custom_type" attrs="{'readonly': [('quantity', '=', True)]}" force_save="1"/>
8585
<field name="min_val" attrs="{'invisible': [('custom_type','not in',['int','float'])]}"/>
8686
<field name="max_val" attrs="{'invisible': [('custom_type','not in',['int','float'])]}"/>
8787
</group>

product_configurator/views/product_view.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
<field name="required" invisible="not context.get('default_config_ok', False)"/>
6767
<field name="multi" invisible="not context.get('default_config_ok', False)" attrs="{'readonly': [('custom','=',True)]}" force_save="1"/>
6868
<field name="custom" invisible="not context.get('default_config_ok', False)" attrs="{'readonly': [('multi','=',True)]}" force_save="1"/>
69-
<field name="quantity" invisible="not context.get('default_config_ok', False)" attrs="{'readonly': [('custom','!=',True)]}" force_save="1"/>
7069
</xpath>
7170

7271
<xpath expr="//field[@name='attribute_line_ids']/tree/field[@name='value_ids']" position="attributes">

0 commit comments

Comments
 (0)