← Back to team overview

openerp-community team mailing list archive

lp:~camptocamp/openerp-product-attributes/7.0-product_images-migr into lp:openerp-product-attributes

 

Guewen Baconnier @ Camptocamp has proposed merging lp:~camptocamp/openerp-product-attributes/7.0-product_images-migr into lp:openerp-product-attributes with lp:~camptocamp/openerp-product-attributes/7.0-product_sequence-migr as a prerequisite.

Commit message:
[MIGR] migration of product_images (previously product_images_olbs) to openerp 7.0

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

For more details, see:
https://code.launchpad.net/~camptocamp/openerp-product-attributes/7.0-product_images-migr/+merge/145630

Migration of product_sequence to openerp 7.0

 * updated manifest (version, 'data' key, installable, category)
 * formatting and pep8
 * replaced 'encoding: utf-8' by 'coding: utf-8'
 * fixed the views which where not displayed correctly
 * fixed the image widget which was not working (the <field> should be in a <group>)
 * renamed the field 'extention' to 'extension'


Prerequisite merge for this branch: https://code.launchpad.net/~camptocamp/openerp-product-attributes/7.0-product_sequence-migr/+merge/145627
-- 
https://code.launchpad.net/~camptocamp/openerp-product-attributes/7.0-product_images-migr/+merge/145630
Your team OpenERP Community is subscribed to branch lp:openerp-product-attributes.
=== modified file 'product_images/__init__.py'
--- product_images/__init__.py	2011-11-17 17:48:39 +0000
+++ product_images/__init__.py	2013-01-30 15:16:32 +0000
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 #########################################################################
 # Copyright (C) 2009  Sharoon Thomas Open Labs Business Solutions       #
 #                                                                       #

=== modified file 'product_images/__openerp__.py'
--- product_images/__openerp__.py	2013-01-21 06:49:06 +0000
+++ product_images/__openerp__.py	2013-01-30 15:16:32 +0000
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 #########################################################################
 # Copyright (C) 2009  Sharoon Thomas, Open Labs Business solutions      #
 # Copyright (C) 2012-Today  Akretion www.akretion.com                   #
@@ -19,26 +20,24 @@
 
 {
     "name" : "Product Image Gallery",
-    "version" : "0.1 ",
+    "version" : "7.0",
     "author" : "Sharoon Thomas, Open Labs Business Solutions, Akretion",
     "website" : "http://openlabs.co.in/";,
-    "category" : "Added functionality - Product Extension",
+    "category" : "Generic Modules",
     "depends" : ['product_sequence'],
     "description": """
-    This Module implements an Image Gallery for products.
-    You can add images against every product.
+This Module implements an Image Gallery for products.
+You can add images against every product.
 
-    This module is generic but built for Magento ERP connector and
-    the upcoming e-commerce system for Open ERP by Open Labs
+This module is generic but built for Magento ERP connector and
+the upcoming e-commerce system for Open ERP by Open Labs
     """,
-    "init_xml": [],
-    "update_xml": [
+    "data": [
         'security/ir.model.access.csv',
         'views/product_images_view.xml',
         'views/company_view.xml'
     ],
-    'installable': False,
+    'installable': True,
     "active": False,
 }
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'product_images/company.py'
--- product_images/company.py	2012-08-21 14:10:21 +0000
+++ product_images/company.py	2013-01-30 15:16:32 +0000
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    Author Nicolas Bessi & Guewen Baconnier. Copyright Camptocamp SA
@@ -18,21 +18,23 @@
 #
 ##############################################################################
 
-from openerp.osv.orm import Model
-from openerp.osv import fields
-
-class ResCompany(Model):
+from openerp.osv import orm, fields
+
+
+class ResCompany(orm.Model):
     """Override company to add images configuration"""
     _inherit = "res.company"
     _columns = {
-        'local_media_repository':fields.char(
-                        'Images Repository Path',
-                        size=256,
-                        help='Local mounted path on OpenERP server where all your images are stored.'
-            ),
+        'local_media_repository': fields.char(
+            'Images Repository Path',
+            help='Local mounted path on OpenERP server '
+                 'where all your images are stored.'),
         }
 
     def get_local_media_repository(self, cr, uid, id=None, context=None):
+        if isinstance(id, (tuple, list)):
+            assert len(id) == 1, "One ID expected"
+            id = id[0]
         if id:
             return self.browse(cr, uid, id, context=context).local_media_repository
         user = self.pool.get('res.users').browse(cr, uid, uid, context=context)

=== modified file 'product_images/product.py'
--- product_images/product.py	2012-08-21 14:10:21 +0000
+++ product_images/product.py	2013-01-30 15:16:32 +0000
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 #########################################################################
 # Copyright (C) 2009  Sharoon Thomas, Open Labs Business solutions      #
 # Copyright (C) 2011 Akretion Sébastien BEAU sebastien.beau@xxxxxxxxxxxx#
@@ -19,12 +19,13 @@
 import os
 import shutil
 import logging
-import base64, urllib
-
-from openerp.osv.orm import Model
-from openerp.osv import fields
-
-class product_product(Model):
+import base64
+import urllib
+
+from openerp.osv import orm, fields
+
+
+class product_product(orm.Model):
     _inherit = "product.product"
 
     def copy(self, cr, uid, id, default=None, context=None):
@@ -43,7 +44,10 @@
                         shutil.copytree(old_path, old_path + '-copy')
                     except:
                         logger = logging.getLogger('product_images_olbs')
-                        logger.exception('error while trying to copy images from %s to %s', old_path, old_path+'.copy')
+                        logger.exception('error while trying to copy images '
+                                         'from %s to %s',
+                                         old_path,
+                                         old_path + '.copy')
 
         return super(product_product, self).copy(cr, uid, id, default, context=context)
 
@@ -68,19 +72,21 @@
         return res
 
     _columns = {
-        'image_ids':fields.one2many(
+        'image_ids': fields.one2many(
                 'product.images',
                 'product_id',
-                'Product Images'
-        ),
-        'product_image': fields.function(_get_main_image, type="binary", method=True),
+                string='Product Images'),
+        'product_image': fields.function(
+            _get_main_image,
+            type="binary",
+            string="Main Image"),
     }
 
     def write(self, cr, uid, ids, vals, context=None):
         if isinstance(ids, (int, long)):
             ids = [ids]
         # here we expect that the write on default_code is always on 1 product because there is an unique constraint on the default code
-        if vals.get('default_code', False) and ids:
+        if vals.get('default_code') and ids:
             local_media_repository = self.pool.get('res.company').get_local_media_repository(cr, uid, context=context)
             if local_media_repository:
                 old_product = self.read(cr, uid, ids[0], ['default_code', 'image_ids'], context=context)
@@ -95,15 +101,14 @@
 
     def create_image_from_url(self, cr, uid, id, url, image_name=None, context=None):
         (filename, header) = urllib.urlretrieve(url)
-        f = open(filename , 'rb')
-        data = f.read()
-        f.close()
+        with open(filename, 'rb') as f:
+            data = f.read()
         img = base64.encodestring(data)
-        filename, extention = os.path.splitext(os.path.basename(url))
+        filename, extension = os.path.splitext(os.path.basename(url))
         data = {'name': image_name or filename,
-            'extention': extention,
-            'file': img,
-            'product_id': id,
-            }
+                'extension': extension,
+                'file': img,
+                'product_id': id,
+                }
         new_image_id = self.pool.get('product.images').create(cr, uid, data, context=context)
         return True

=== modified file 'product_images/product_images.py'
--- product_images/product_images.py	2012-12-09 15:51:15 +0000
+++ product_images/product_images.py	2013-01-30 15:16:32 +0000
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 #########################################################################
 # Copyright (C) 2009  Sharoon Thomas, Open Labs Business solutions      #
 # Copyright (C) 2011 Akretion Sébastien BEAU sebastien.beau@xxxxxxxxxxxx#
@@ -16,24 +16,25 @@
 #You should have received a copy of the GNU General Public License      #
 #along with this program.  If not, see <http://www.gnu.org/licenses/>.  #
 #########################################################################
-from openerp.osv.orm import Model
-from openerp.osv import fields
-from openerp.osv.osv import except_osv
-import base64, urllib
-from tools.translate import _
+import base64
+import urllib
 import os
 
+from openerp.osv import fields, orm, osv
+from openerp.tools.translate import _
+
 import logging
 _logger = logging.getLogger(__name__)
 
 #TODO find a good solution in order to roll back changed done on file system
-#TODO add the posibility to move from a store system to an other (example : moving existing image on database to file system)
-
-class product_images(Model):
+#TODO add the posibility to move from a store system to an other
+# (example : moving existing image on database to file system)
+
+
+class product_images(orm.Model):
     "Products Image gallery"
     _name = "product.images"
     _description = __doc__
-    _table = "product_images"
 
     def unlink(self, cr, uid, ids, context=None):
         if isinstance(ids, (int, long)):
@@ -45,17 +46,17 @@
         return super(product_images, self).unlink(cr, uid, ids, context=context)
 
     def create(self, cr, uid, vals, context=None):
-        if vals.get('name', False) and not vals.get('extention', False):
-            vals['name'], vals['extention'] = os.path.splitext(vals['name'])
+        if vals.get('name', False) and not vals.get('extension', False):
+            vals['name'], vals['extension'] = os.path.splitext(vals['name'])
         return super(product_images, self).create(cr, uid, vals, context=context)
 
     def write(self, cr, uid, ids, vals, context=None):
         if not isinstance(ids, list):
             ids = [ids]
-        if vals.get('name', False) and not vals.get('extention', False):
-            vals['name'], vals['extention'] = os.path.splitext(vals['name'])
+        if vals.get('name', False) and not vals.get('extension', False):
+            vals['name'], vals['extension'] = os.path.splitext(vals['name'])
         upd_ids = ids[:]
-        if vals.get('name', False) or vals.get('extention', False):
+        if vals.get('name', False) or vals.get('extension', False):
             images = self.browse(cr, uid, upd_ids, context=context)
             for image in images:
                 old_full_path = self._image_path(cr, uid, image, context=context)
@@ -63,7 +64,7 @@
                     continue
                 # all the stuff below is there to manage the files on the filesystem
                 if vals.get('name', False) and (image.name != vals['name']) \
-                    or vals.get('extention', False) and (image.extention != vals['extention']):
+                    or vals.get('extension', False) and (image.extension != vals['extension']):
                     super(product_images, self).write(
                         cr, uid, image.id, vals, context=context)
                     upd_ids.remove(image.id)
@@ -89,7 +90,7 @@
             full_path = os.path.join(
                 local_media_repository,
                 image.product_id.default_code,
-                '%s%s' % (image.name or '', image.extention or ''))
+                '%s%s' % (image.name or '', image.extension or ''))
         return full_path
 
     def get_image(self, cr, uid, id, context=None):
@@ -97,7 +98,7 @@
         if image.link:
             if image.url:
                 (filename, header) = urllib.urlretrieve(image.url)
-                with open(filename , 'rb') as f:
+                with open(filename, 'rb') as f:
                     img = base64.b64encode(f.read())
             else:
                 return False
@@ -117,7 +118,8 @@
                         with open(full_path, 'rb') as f:
                             img = base64.b64encode(f.read())
                     except Exception, e:
-                        _logger.error("Can not open the image %s, error : %s", full_path, e, exc_info=True)
+                        _logger.error("Can not open the image %s, error : %s",
+                                      full_path, e, exc_info=True)
                         return False
                 else:
                     _logger.error("The image %s doesn't exist ", full_path)
@@ -133,13 +135,17 @@
         return res
 
     def _check_filestore(self, image_filestore):
-        """check if the filestore is created, if not it create it automatically"""
+        """check if the filestore is created, if not it create it
+        automatically
+        """
         try:
             dir_path = os.path.dirname(image_filestore)
             if not os.path.exists(dir_path):
                 os.makedirs(dir_path)
         except OSError, e:
-            raise except_osv(_('Error'), _('The image filestore can not be created, %s')%e)
+            raise osv.except_osv(
+                    _('Error'),
+                    _('The image filestore can not be created, %s') % e)
         return True
 
     def _save_file(self, path, b64_file):
@@ -154,21 +160,30 @@
         full_path = self._image_path(cr, uid, image, context=context)
         if full_path:
             return self._save_file(full_path, value)
-        return self.write(cr, uid, id, {'file_db_store' : value}, context=context)
+        return self.write(cr, uid, id, {'file_db_store': value}, context=context)
 
     _columns = {
-        'name':fields.char('Image Title', size=100, required=True),
-        'extention': fields.char('file extention', size=6),
-        'link':fields.boolean('Link?', help="Images can be linked from files on your file system or remote (Preferred)"),
-        'file_db_store':fields.binary('Image stored in database'),
-        'file':fields.function(_get_image, fnct_inv=_set_image, type="binary", filters='*.png,*.jpg,*.gif'),
-        'url':fields.char('File Location', size=250),
-        'comments':fields.text('Comments'),
-        'product_id':fields.many2one('product.product', 'Product')
+        'name': fields.char('Image Title', required=True),
+        'extension': fields.char('file extension', oldname='extention'),
+        'link': fields.boolean('Link?',
+                               help="Images can be linked from files on "
+                                    "your file system or remote (Preferred)"),
+        'file_db_store': fields.binary('Image stored in database'),
+        'file': fields.function(_get_image,
+                                fnct_inv=_set_image,
+                                type="binary",
+                                string="File",
+                                filters='*.png,*.jpg,*.gif'),
+        'url': fields.char('File Location'),
+        'comments': fields.text('Comments'),
+        'product_id': fields.many2one('product.product', 'Product')
         }
+
     _defaults = {
-        'link': lambda *a: False,
+        'link': False,
         }
-    _sql_constraints = [('uniq_name_product_id', 'UNIQUE(product_id, name)',
-                         _('A product can have only one image with the same name'))]
 
+    _sql_constraints = [('uniq_name_product_id',
+                         'UNIQUE(product_id, name)',
+                         _('A product can have only one '
+                           'image with the same name'))]

=== modified file 'product_images/views/company_view.xml'
--- product_images/views/company_view.xml	2011-11-18 10:13:17 +0000
+++ product_images/views/company_view.xml	2013-01-30 15:16:32 +0000
@@ -1,16 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <openerp>
     <data>
         <record model="ir.ui.view" id="view_company_form_product_images">
             <field name="name">res.company.form.inherit</field>
             <field name="model">res.company</field>
             <field name="inherit_id" ref="base.view_company_form"/>
-            <field name="type">form</field>
             <field name="arch" type="xml">
-                <notebook  position="inside">
-            		<page string="Product images">
+                <xpath expr="//page[@string='Configuration']/group[1]" position="inside">
+                    <group name="product_images_grp" string="Product Images">
                         <field name="local_media_repository"/>
-                    </page>
-                </notebook>
+                    </group>
+                </xpath>
             </field>
         </record>
     </data>

=== modified file 'product_images/views/product_images_view.xml'
--- product_images/views/product_images_view.xml	2013-01-21 06:47:53 +0000
+++ product_images/views/product_images_view.xml	2013-01-30 15:16:32 +0000
@@ -1,55 +1,58 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
-	<data>
-		<record id="view_product_image_form" model="ir.ui.view">
-			<field name="name">product.images.form</field>
-			<field name="model">product.images</field>
-			<field name="type">form</field>
-			<field name="arch" type="xml">
-				<form string="Product Images">
-					<notebook colspan="4">
-						<page string="Image">
-							<group col="6" colspan="4">
-								<field name="name" colspan="2" />
-                                <field name="extention" colspan="2" />
-								<field name="link" colspan="2" />
-							</group>
-                            <group attrs="{'invisible':[('link','=',0)]}" colspan="4">
-							    <separator string="File Location and Preview (Only when saved)" colspan="4"/>
-                                <field name="url" colspan="4" widget="url" nolabel="1"/>
-                            </group>
-							<field name="file" widget="image" nolabel="1" filename="name" colspan="4" attrs="{'readonly':[('link','!=',0)]}"/>
-						</page>
-						<page string="Comments">
-							<field name="comments" nolabel="1" colspan="4" />
-						</page>
-					</notebook>
-				</form>
-			</field>
-		</record>
-		<record id="view_product_image_tree" model="ir.ui.view">
-			<field name="name">product.images.tree</field>
-			<field name="model">product.images</field>
-			<field name="type">tree</field>
-			<field name="arch" type="xml">
-				<tree string="Product Images">
-					<field name="name" select="1" />
-					<field name="comments" select="2" />
-				</tree>
-			</field>
-		</record>
-		<record id="view_product_form_img_inh" model="ir.ui.view">
-			<field name="name">product.product.images</field>
-			<field name="model">product.product</field>
-			<field name="inherit_id" ref="product.product_normal_form_view" />
-			<field name="type">form</field>
-			<field name="arch" type="xml">
-				<xpath expr="/form/sheet/notebook" position="inside">
-					<page string="Images">
-						<field name="image_ids" nolabel="1" />
-					</page>
-				</xpath>
-			</field>
-		</record>
-	</data>
+    <data>
+        <record id="view_product_image_form" model="ir.ui.view">
+            <field name="name">product.images.form</field>
+            <field name="model">product.images</field>
+            <field name="arch" type="xml">
+                <form string="Product Images">
+                    <notebook colspan="4">
+                        <page string="Image">
+                            <group col="6" colspan="4">
+                                <field name="name" colspan="2" />
+                                <field name="extension" colspan="2" />
+                                <field name="link" colspan="2" />
+                            </group>
+                            <group attrs="{'invisible': [('link', '=', False)]}" colspan="4">
+                                <field name="url" colspan="4" widget="url"/>
+                            </group>
+                            <group>
+                                <field name="file" widget="image" nolabel="1" filename="name"
+                                    colspan="4" attrs="{'readonly': [('link', '=', True)]}"/>
+                            </group>
+                        </page>
+                        <page string="Comments">
+                            <group>
+                                <field name="comments" nolabel="1" colspan="4" />
+                        </group>
+                        </page>
+                    </notebook>
+                </form>
+            </field>
+        </record>
+
+        <record id="view_product_image_tree" model="ir.ui.view">
+            <field name="name">product.images.tree</field>
+            <field name="model">product.images</field>
+            <field name="arch" type="xml">
+                <tree string="Product Images">
+                    <field name="name" select="1" />
+                    <field name="comments" select="2" />
+                </tree>
+            </field>
+        </record>
+
+        <record id="view_product_form_img_inh" model="ir.ui.view">
+            <field name="name">product.product.images</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_normal_form_view" />
+            <field name="arch" type="xml">
+                <xpath expr="/form/sheet/notebook" position="inside">
+                    <page string="Images">
+                        <field name="image_ids" nolabel="1" />
+                    </page>
+                </xpath>
+            </field>
+        </record>
+    </data>
 </openerp>

=== modified file 'product_sequence/__openerp__.py'
--- product_sequence/__openerp__.py	2013-01-21 06:49:06 +0000
+++ product_sequence/__openerp__.py	2013-01-30 15:16:32 +0000
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
@@ -22,7 +22,7 @@
 
 {
     'name' : 'Product Sequence',
-    'version' : '6.1.0',
+    'version' : '7.0',
     "author": "Zikzakmedia SL",
     "website": "http://www.zikzakmedia.com";,
     "license" : "AGPL-3",
@@ -35,11 +35,9 @@
     'depends' : [
         'product',
     ],
-    "init_xml" : [
+    "data" : [
         'product_sequence.xml',
     ],
-    "update_xml" : [
-    ],
-    'installable': False,
+    'installable': True,
     'active': False,
 }

=== modified file 'product_sequence/product_product.py'
--- product_sequence/product_product.py	2012-09-26 15:54:15 +0000
+++ product_sequence/product_product.py	2013-01-30 15:16:32 +0000
@@ -19,47 +19,64 @@
 #
 ##############################################################################
 
-from openerp.osv.orm import Model
-from openerp.osv import fields
+from openerp.osv import orm, fields
 from openerp.tools.translate import _
 
-class product_product(Model):
+
+class product_product(orm.Model):
     _inherit = 'product.product'
+
     _columns = {
-        'default_code' : fields.char('Reference', size=64, required=True),
+        'default_code': fields.char('Reference',
+                                    size=64,
+                                    select=True,
+                                    required=True),
         }
+
     _sql_constraints = [
-        ('uniq_default_code', 'unique(default_code)', "The reference must be unique"),
-        ]
+        ('uniq_default_code',
+         'unique(default_code)',
+         'The reference must be unique'),
+    ]
+
     _defaults = {
-        'default_code': lambda * a: '/',
+        'default_code': '/',
         }
 
     def create(self, cr, uid, vals, context=None):
-        if context is None:
-            context = {}
         if not 'default_code' in vals or vals['default_code'] == '/':
-            vals['default_code'] = self.pool.get('ir.sequence').get(cr, uid, 'product.product')
+            vals['default_code'] = self.pool.get('ir.sequence').get(
+                    cr, uid, 'product.product')
         return super(product_product, self).create(cr, uid, vals, context)
 
     def write(self, cr, uid, ids, vals, context=None):
         if not hasattr(ids, '__iter__'):
             ids = [ids]
-        if context is None:
-            context = {}
-        products_without_code = self.search(cr, uid, [('default_code', 'in', [False, '/']),('id', 'in', ids)], context=context)
+        products_without_code = self.search(
+                cr, uid,
+                [('default_code', 'in', [False, '/']),
+                 ('id', 'in', ids)],
+                context=context)
         direct_write_ids = set(ids) - set(products_without_code)
-        super(product_product, self).write(cr, uid, list(direct_write_ids), vals, context)
+        super(product_product, self).write(cr, uid,
+                                           list(direct_write_ids),
+                                           vals, context=context)
         for product_id in products_without_code:
-            vals['default_code'] = self.pool.get('ir.sequence').get(cr, uid, 'product.product')
-            super(product_product, self).write(cr, uid, product_id, vals, context)
+            vals['default_code'] = self.pool.get('ir.sequence').get(
+                    cr, uid, 'product.product')
+            super(product_product, self).write(cr, uid,
+                                               product_id,
+                                               vals,
+                                               context=context)
         return True
 
-    def copy(self, cr, uid, id, default={}, context=None):
+    def copy(self, cr, uid, id, default=None, context=None):
+        if default is None:
+            default = {}
         product = self.read(cr, uid, id, ['default_code'], context=context)
-        if  product['default_code']:
+        if product['default_code']:
             default.update({
-                'default_code': product['default_code']+ _('-copy'),
+                'default_code': product['default_code'] + _('-copy'),
             })
 
         return super(product_product, self).copy(cr, uid, id, default, context)

=== modified file 'product_sequence/product_sequence.xml'
--- product_sequence/product_sequence.xml	2012-08-02 10:43:21 +0000
+++ product_sequence/product_sequence.xml	2013-01-30 15:16:32 +0000
@@ -1,11 +1,12 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <openerp>
     <data noupdate="1">
+
         <record id="seq_product_auto_type" model="ir.sequence.type">
             <field name="name">Product</field>
             <field name="code">product.product</field>
         </record>
-        
+
         <record id="seq_product_auto" model="ir.sequence">
             <field name="name">Product</field>
             <field name="code">product.product</field>


Follow ups