Compute attributes name for variant

issue10844
review362271002
This commit is contained in:
Cédric Krier
2021-10-12 10:09:51 +02:00
parent 1e775b5340
commit 95be8d94dd
3 changed files with 39 additions and 0 deletions
+25
View File
@@ -1,5 +1,6 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.i18n import gettext
from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.pyson import Eval
@@ -34,6 +35,13 @@ class Image(metaclass=PoolMeta):
'invisible': ~Eval('attribute_set') | Eval('product'),
},
depends=['attribute_set', 'product'])
attributes_name = fields.Function(fields.Char(
"Attributes Name",
states={
'invisible': ~Eval('attribute_set'),
},
depends=['attribute_set']),
'on_change_with_attributes_name')
attribute_set = fields.Function(
fields.Many2One('product.attribute.set', "Attribute Set"),
@@ -43,3 +51,20 @@ class Image(metaclass=PoolMeta):
def on_change_with_attribute_set(self, name=None):
if self.template and self.template.attribute_set:
return self.template.attribute_set.id
@fields.depends('attribute_set', 'attributes')
def on_change_with_attributes_name(self, name=None):
if not self.attribute_set or not self.attributes:
return
def key(attribute):
return getattr(attribute, 'sequence', attribute.name)
values = []
for attribute in sorted(self.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))
+6
View File
@@ -3,6 +3,12 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="image_view_list">
<field name="model">product.image</field>
<field name="inherit" ref="product_image.image_view_list"/>
<field name="name">image_list</field>
</record>
<record model="ir.ui.view" id="image_view_form">
<field name="model">product.image</field>
<field name="inherit" ref="product_image.image_view_form"/>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//field[@name='product']" position="after">
<field name="attributes_name" expand="1"/>
</xpath>
</data>