diff --git a/CHANGELOG b/CHANGELOG index fac92c3301..4c89782a1e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Compute attributes name for variant + Version 6.0.0 - 2021-05-03 * Bug fixes (see mercurial logs for details) diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..69faa09f32 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + %(label)s: %(value)s + + + diff --git a/product.py b/product.py index eb779bc93c..b176df142a 100644 --- a/product.py +++ b/product.py @@ -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)) diff --git a/tryton.cfg b/tryton.cfg index 3bfde53bca..9ae2030d27 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,3 +5,4 @@ depends: product xml: product.xml + message.xml diff --git a/view/product_form.xml b/view/product_form.xml index b90c58cba8..dc3e976751 100644 --- a/view/product_form.xml +++ b/view/product_form.xml @@ -2,6 +2,10 @@ + + diff --git a/view/product_tree.xml b/view/product_tree.xml index 91dd59e451..f643959297 100644 --- a/view/product_tree.xml +++ b/view/product_tree.xml @@ -2,6 +2,9 @@ + + +