From 18b0b2ca0681cbd384f553cd38a3cf6c99aa3e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 26 Sep 2014 14:10:34 +0200 Subject: [PATCH] The attributes doesn't work when product is viewed outside the template Use a Function field to always get the attribute_set. issue4209 review12581002 --- product.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/product.py b/product.py index 460266653d..26a19167c2 100644 --- a/product.py +++ b/product.py @@ -42,9 +42,18 @@ class Product: __name__ = 'product.product' attributes = fields.Dict('product.attribute', 'Attributes', domain=[ - ('sets', '=', - Eval('_parent_template', {}).get('attribute_set', -1)), + ('sets', '=', Eval('_parent_template', {}).get('attribute_set', + Eval('attribute_set', -1))), ], states={ - 'readonly': ~Eval('_parent_template', {}), - }) + 'readonly': (~Eval('attribute_set') + & ~Eval('_parent_template', {}).get('attribute_set')), + }, + depends=['attribute_set']) + attribute_set = fields.Function(fields.Many2One('product.attribute.set', + 'Set'), 'on_change_with_attribute_set') + + @fields.depends('template') + def on_change_with_attribute_set(self, name=None): + if self.template and getattr(self.template, 'attribute_set', None): + return self.template.attribute_set.id