From 95be8d94dd699540ed815afbbb017678e12cdf16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 12 Oct 2021 10:09:51 +0200 Subject: [PATCH] Compute attributes name for variant issue10844 review362271002 --- product.py | 25 +++++++++++++++++++++++++ product.xml | 6 ++++++ view/image_list.xml | 8 ++++++++ 3 files changed, 39 insertions(+) create mode 100644 view/image_list.xml diff --git a/product.py b/product.py index f2d7376695..c39602f112 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 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)) diff --git a/product.xml b/product.xml index 2fca96c8df..f68220b2eb 100644 --- a/product.xml +++ b/product.xml @@ -3,6 +3,12 @@ this repository contains the full copyright notices and license terms. --> + + product.image + + image_list + + product.image diff --git a/view/image_list.xml b/view/image_list.xml new file mode 100644 index 0000000000..0fe067a749 --- /dev/null +++ b/view/image_list.xml @@ -0,0 +1,8 @@ + + + + + + +