This commit is contained in:
2026-03-05 17:53:49 +01:00
parent ae0817e0ac
commit 2b956e6142

View File

@@ -485,28 +485,26 @@ class Line(metaclass=PoolMeta):
premium = fields.Numeric("Premium/Discount",digits='unit') premium = fields.Numeric("Premium/Discount",digits='unit')
fee_ = fields.Many2One('fee.fee',"Fee") fee_ = fields.Many2One('fee.fee',"Fee")
attributes = fields.Dict('product.attribute', 'Attributes', attributes = fields.Dict(
'product.attribute', 'Attributes',
domain=[ domain=[
('sets', '=', Eval('product._parent_template', {}).get('attribute_set', ('sets', '=', Eval('attribute_set')),
Eval('attribute_set', -1))), ],
],
states={ states={
'readonly': (~Eval('attribute_set') 'readonly': ~Eval('attribute_set'),
& ~Eval('product._parent_template', {}).get('attribute_set')), },
}, depends=['product', 'attribute_set'],
depends={'product.template'}, help="Add attributes to the variant."
help="Add attributes to the variant.") )
attributes_name = fields.Function(fields.Char( attributes_name = fields.Function(
"Attributes Name", fields.Char("Attributes Name"),
states={ 'on_change_with_attributes_name'
'invisible': ~Eval('attribute_set'), )
}),
'on_change_with_attributes_name')
@fields.depends('product', 'attributes') @fields.depends('product', 'attributes')
def on_change_with_attributes_name(self, name=None): def on_change_with_attributes_name(self, name=None):
if not self.product.attribute_set or not self.attributes: if not self.product or not self.product.attribute_set or not self.attributes:
return return
def key(attribute): def key(attribute):
@@ -516,10 +514,47 @@ class Line(metaclass=PoolMeta):
for attribute in sorted(self.product.attribute_set.attributes, key=key): for attribute in sorted(self.product.attribute_set.attributes, key=key):
if attribute.name in self.attributes: if attribute.name in self.attributes:
value = self.attributes[attribute.name] value = self.attributes[attribute.name]
values.append(gettext('product_attribute.msg_label_value', values.append(gettext(
label=attribute.string, 'product_attribute.msg_label_value',
value=attribute.format(value))) label=attribute.string,
value=attribute.format(value)
))
return " | ".join(filter(None, values)) return " | ".join(filter(None, values))
# attributes = fields.Dict('product.attribute', 'Attributes',
# domain=[
# ('sets', '=', Eval('product._parent_template', {}).get('attribute_set',
# Eval('attribute_set', -1))),
# ],
# states={
# 'readonly': (~Eval('attribute_set')
# & ~Eval('product._parent_template', {}).get('attribute_set')),
# },
# depends={'product.template'},
# help="Add attributes to the variant.")
# attributes_name = fields.Function(fields.Char(
# "Attributes Name",
# states={
# 'invisible': ~Eval('attribute_set'),
# }),
# 'on_change_with_attributes_name')
# @fields.depends('product', 'attributes')
# def on_change_with_attributes_name(self, name=None):
# if not self.product.attribute_set or not self.attributes:
# return
# def key(attribute):
# return getattr(attribute, 'sequence', attribute.name)
# values = []
# for attribute in sorted(self.product.attribute_set.attributes, key=key):
# if attribute.name in self.attributes:
# value = self.attributes[attribute.name]
# values.append(gettext('product_attribute.msg_label_value',
# label=attribute.string,
# value=attribute.format(value)))
# return " | ".join(filter(None, values))
@classmethod @classmethod
def default_price_type(cls): def default_price_type(cls):