changeset d50bbca84559 in modules/product_image_attribute:default
details:
https://hg.tryton.org/modules/product_image_attribute?cmd=changeset&node=d50bbca84559
description:
Compute attributes name for variant
issue10844
review362271002
diffstat:
product.py | 25 +++++++++++++++++++++++++
product.xml | 6 ++++++
view/image_list.xml | 8 ++++++++
3 files changed, 39 insertions(+), 0 deletions(-)
diffs (73 lines):
diff -r 698a2372a798 -r d50bbca84559 product.py
--- a/product.py Thu Sep 30 23:04:46 2021 +0200
+++ b/product.py Tue Oct 12 10:09:51 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 fields
from trytond.pool import PoolMeta
from trytond.pyson import Eval
@@ -34,6 +35,13 @@
'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 @@
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 -r 698a2372a798 -r d50bbca84559 product.xml
--- a/product.xml Thu Sep 30 23:04:46 2021 +0200
+++ b/product.xml Tue Oct 12 10:09:51 2021 +0200
@@ -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"/>
diff -r 698a2372a798 -r d50bbca84559 view/image_list.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/image_list.xml Tue Oct 12 10:09:51 2021 +0200
@@ -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>