Compute attributes name for variant

issue10758
review354001002
This commit is contained in:
Cédric Krier
2021-10-10 22:09:06 +02:00
parent 637df04723
commit 1e90b88ee0
6 changed files with 45 additions and 0 deletions
+2
View File
@@ -1,3 +1,5 @@
* Compute attributes name for variant
Version 6.0.0 - 2021-05-03
* Bug fixes (see mercurial logs for details)
+10
View File
@@ -0,0 +1,10 @@
<?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. -->
<tryton>
<data>
<record model="ir.message" id="msg_label_value">
<field name="text">%(label)s: %(value)s</field>
</record>
</data>
</tryton>
+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 ModelSQL, ModelView, DictSchemaMixin, fields
from trytond.pool import PoolMeta
from trytond.pyson import Eval
@@ -51,3 +52,27 @@ class Product(metaclass=PoolMeta):
},
depends=['attribute_set'],
help="Add attributes to the variant.")
attributes_name = fields.Function(fields.Char(
"Attributes Name",
states={
'invisible': ~Eval('attribute_set'),
},
depends=['attribute_set']),
'on_change_with_attributes_name')
@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))
+1
View File
@@ -5,3 +5,4 @@ depends:
product
xml:
product.xml
message.xml
+4
View File
@@ -2,6 +2,10 @@
<!-- 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='active']" position="after">
<label name="attributes_name"/>
<field name="attributes_name" colspan="5"/>
</xpath>
<xpath expr="/form/notebook/page[@id='attributes']/field[@name='attribute_set']"
position="after">
<field name="attributes" colspan="4"/>
+3
View File
@@ -2,6 +2,9 @@
<!-- 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='name']" position="after">
<field name="attributes_name" expand="1"/>
</xpath>
<xpath expr="//field[@name='attribute_set']" position="after">
<field name="attributes" tree_invisible="1"/>
</xpath>