← Back to team overview

openerp-community team mailing list archive

lp:~openerp-community/openerp-product-attributes/7.0-product_custom_attributes-attribute_set_id_on_template-gbr into lp:openerp-product-attributes

 

Guewen Baconnier @ Camptocamp has proposed merging lp:~openerp-community/openerp-product-attributes/7.0-product_custom_attributes-attribute_set_id_on_template-gbr into lp:openerp-product-attributes.

Requested reviews:
  Product Core Editors (product-core-editors)

For more details, see:
https://code.launchpad.net/~openerp-community/openerp-product-attributes/7.0-product_custom_attributes-attribute_set_id_on_template-gbr/+merge/188309

Hi,

In product_custom_attributes, actually the many2one to the attribute set is stored on the product.product.
However, an attribute set can contains attributes stored on the variant or on the template.
Thus, it makes sense to have the attribute set stored on the template instead of the variants.

Example:
I create an attribute set "Wine". It contains the attributes "Appellation", "AOC" and "Color".
The formers are stored on the template while the color is stored on the variants.
When I read a template, I should be able to know which attributes I need to read, but actually I can't because I don't know what is the set of the template.

This change moves the many2one to the template.

Note for the migration: if a template has several variants with a different set, it takes the first one. I tried first to raise an exception if such an issue happen [0] but it leaves the server in a broken state and prevents it to start while the data is not fixed in the DB. 

[0] http://bazaar.launchpad.net/~openerp-community/openerp-product-attributes/7.0-product_custom_attributes-attribute_set_id_on_template-gbr/view/213/product_custom_attributes/migrations/7.0.0.2/pre-migration.py#L29
-- 
https://code.launchpad.net/~openerp-community/openerp-product-attributes/7.0-product_custom_attributes-attribute_set_id_on_template-gbr/+merge/188309
Your team OpenERP Community is subscribed to branch lp:openerp-product-attributes.
=== modified file 'product_custom_attributes/__openerp__.py'
--- product_custom_attributes/__openerp__.py	2013-03-02 00:06:19 +0000
+++ product_custom_attributes/__openerp__.py	2013-09-30 11:43:08 +0000
@@ -23,7 +23,7 @@
 
 {
     'name': 'product_custom_attributes',
-    'version': '0.1',
+    'version': '0.2',
     'category': 'Generic Modules/Others',
     'license': 'AGPL-3',
     'description': """This module adds the possibility to easily create custom fields on products.

=== added directory 'product_custom_attributes/migrations'
=== added directory 'product_custom_attributes/migrations/7.0.0.2'
=== added file 'product_custom_attributes/migrations/7.0.0.2/post-migration.py'
--- product_custom_attributes/migrations/7.0.0.2/post-migration.py	1970-01-01 00:00:00 +0000
+++ product_custom_attributes/migrations/7.0.0.2/post-migration.py	2013-09-30 11:43:08 +0000
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Author: Guewen Baconnier
+#    Copyright 2013 Camptocamp SA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import logging
+
+logger = logging.getLogger('upgrade')
+
+
+def migrate(cr, version):
+    logger.info("Migrating product_custom_attributes from version %s", version)
+    cr.execute("UPDATE product_template pt "
+               "SET attribute_set_id = (SELECT pp.attribute_set_id "
+               "                        FROM product_product pp WHERE "
+               "                        pp.product_tmpl_id = pt.id "
+               "                        LIMIT 1)"
+               "WHERE pt.attribute_set_id IS NULL")
+    cr.execute('ALTER TABLE product_product DROP COLUMN attribute_set_id')

=== modified file 'product_custom_attributes/product.py'
--- product_custom_attributes/product.py	2013-09-30 07:10:31 +0000
+++ product_custom_attributes/product.py	2013-09-30 11:43:08 +0000
@@ -26,6 +26,13 @@
 from tools.translate import _
 from lxml import etree
 
+class product_template(Model):
+    _inherit = "product.template"
+
+    _columns = {
+        'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'),
+    }
+
 
 class product_product(Model):
     _inherit = "product.product"
@@ -43,8 +50,12 @@
         return res
 
     _columns = {
+<<<<<<< TREE
         'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'),
         'attribute_group_ids': fields.function(_attr_grp_ids, type='many2many',
+=======
+        'attribute_group_ids': fields.function(_attr_grp_ids, type='one2many',
+>>>>>>> MERGE-SOURCE
         relation='attribute.group', string='Groups')
     }
 


Follow ups