changeset 10374a7d6720 in modules/product_attribute:default
details: 
https://hg.tryton.org/modules/product_attribute?cmd=changeset&node=10374a7d6720
description:
        Compute attributes name for variant

        issue10758
        review354001002
diffstat:

 CHANGELOG             |   2 ++
 message.xml           |  10 ++++++++++
 product.py            |  25 +++++++++++++++++++++++++
 tryton.cfg            |   1 +
 view/product_form.xml |   4 ++++
 view/product_tree.xml |   3 +++
 6 files changed, 45 insertions(+), 0 deletions(-)

diffs (96 lines):

diff -r d33951be2718 -r 10374a7d6720 CHANGELOG
--- a/CHANGELOG Sun Jul 04 17:54:47 2021 +0200
+++ b/CHANGELOG Sun Oct 10 22:09:06 2021 +0200
@@ -1,3 +1,5 @@
+* Compute attributes name for variant
+
 Version 6.0.0 - 2021-05-03
 * Bug fixes (see mercurial logs for details)
 
diff -r d33951be2718 -r 10374a7d6720 message.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml       Sun Oct 10 22:09:06 2021 +0200
@@ -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>
diff -r d33951be2718 -r 10374a7d6720 product.py
--- a/product.py        Sun Jul 04 17:54:47 2021 +0200
+++ b/product.py        Sun Oct 10 22:09:06 2021 +0200
@@ -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 @@
             },
         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 -r d33951be2718 -r 10374a7d6720 tryton.cfg
--- a/tryton.cfg        Sun Jul 04 17:54:47 2021 +0200
+++ b/tryton.cfg        Sun Oct 10 22:09:06 2021 +0200
@@ -5,3 +5,4 @@
     product
 xml:
     product.xml
+    message.xml
diff -r d33951be2718 -r 10374a7d6720 view/product_form.xml
--- a/view/product_form.xml     Sun Jul 04 17:54:47 2021 +0200
+++ b/view/product_form.xml     Sun Oct 10 22:09:06 2021 +0200
@@ -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"/>
diff -r d33951be2718 -r 10374a7d6720 view/product_tree.xml
--- a/view/product_tree.xml     Sun Jul 04 17:54:47 2021 +0200
+++ b/view/product_tree.xml     Sun Oct 10 22:09:06 2021 +0200
@@ -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>

Reply via email to