Merge lp:~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image into lp:~product-core-editors/openerp-product-attributes/7.0

Proposed by Sébastien BEAU - http://www.akretion.com
Status: Needs review
Proposed branch: lp:~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image
Merge into: lp:~product-core-editors/openerp-product-attributes/7.0
Diff against target: 314 lines (+289/-0)
5 files modified
product_image/__init__.py (+24/-0)
product_image/__openerp__.py (+49/-0)
product_image/product.py (+76/-0)
product_image/product_image.py (+64/-0)
product_image/product_image_view.xml (+76/-0)
To merge this branch: bzr merge lp:~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Fixing
Review via email: mp+222397@code.launchpad.net

Description of the change

Hi, I refactor and simplify the module product image based on the new field ImageField and ImageResizeField.
This merge depend of this one https://code.launchpad.net/~akretion-team/server-env-tools/server-env-tools

Regarding the old Product Images module what do we do? Remove it? set uninstable?

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Sébastien,

Thanks for the refactoring. I haven't seen yet your new module, but for the question you made, I would change the approach a little, having the same module name with a greater version, and making a migration script that converts old data to new approach with the new fields, because having two modules product_image and product_images is not optimal, and setting to uninstallable lets users base that has already installed this module hanged.

Regards.

review: Needs Fixing
Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

Yes I think too, that having a script to migrate it automatically will be the best solution.
The problem is that making is the script will be not so easy as I change ... everything.
In my case I was thinking about directly uninstalling the module and then resynchronise the image from Magento.

I will try to think more about the migration script but I not sure that I will have the time to do it during the two next week. So we can start to review and test the module first and then I will try to propose the script to migrate it.

Thanks for your feedback

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

OK, thanks for considering it. I'm also too busy now to help you in this task, but let's see in a couple of weeks.

Regards.

245. By Sébastien BEAU - http://www.akretion.com

[REF] update field to the new API

246. By Sébastien BEAU - http://www.akretion.com

[FIX] fix new api attribute for image

247. By Sébastien BEAU - http://www.akretion.com

[REF] rename view id

248. By Sébastien BEAU - http://www.akretion.com

[IMP] add description

Unmerged revisions

248. By Sébastien BEAU - http://www.akretion.com

[IMP] add description

247. By Sébastien BEAU - http://www.akretion.com

[REF] rename view id

246. By Sébastien BEAU - http://www.akretion.com

[FIX] fix new api attribute for image

245. By Sébastien BEAU - http://www.akretion.com

[REF] update field to the new API

244. By Sébastien BEAU - http://www.akretion.com

[REF] refactor code product image, improve view, use imageField and imageResizeField

243. By Sébastien BEAU - http://www.akretion.com

[ADD] create the module product_image. This module is a kind of fork of product_images. As it will be hard to migrate it maybe the best solution will to have the both module installed and then to run a script and uninstall product_images. This is why I fork in order to have the both modules installable. First step is to copy paste from product_images what I need for my new module

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'product_image'
=== added file 'product_image/__init__.py'
--- product_image/__init__.py 1970-01-01 00:00:00 +0000
+++ product_image/__init__.py 2014-07-01 18:57:09 +0000
@@ -0,0 +1,24 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3#
4# Module for OpenERP
5# Copyright (C) 2014 Akretion (http://www.akretion.com).
6# @author Sébastien BEAU <sebastien.beau@akretion.com>
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23from . import product_image
24from . import product
025
=== added file 'product_image/__openerp__.py'
--- product_image/__openerp__.py 1970-01-01 00:00:00 +0000
+++ product_image/__openerp__.py 2014-07-01 18:57:09 +0000
@@ -0,0 +1,49 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3#
4# Module for OpenERP
5# Copyright (C) 2014 Akretion (http://www.akretion.com).
6# @author Sébastien BEAU <sebastien.beau@akretion.com>
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23{'name': 'Product Image',
24 'version': '0.0.1',
25 'author': 'Akretion',
26 'website': 'www.akretion.com',
27 'license': 'AGPL-3',
28 'category': 'Generic Modules',
29 'description': """
30This Module implements an Image Gallery for products.
31You can add images to every product.
32A thumbnail of every image is visible in the product form view
33in the tab 'Images'.
34This module replace the module 'product_images'
35 """,
36 'depends': [
37 'product',
38 'binary_field',
39 ],
40 'data': [
41 'product_image_view.xml',
42 ],
43 'installable': True,
44 'application': True,
45}
46
47
48
49
050
=== added file 'product_image/product.py'
--- product_image/product.py 1970-01-01 00:00:00 +0000
+++ product_image/product.py 2014-07-01 18:57:09 +0000
@@ -0,0 +1,76 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3#
4# Module for OpenERP
5# Copyright (C) 2009 Sharoon Thomas, Open Labs Business solutions
6# Copyright (C) 2011-TODAY Akretion (http://www.akretion.com).
7# @author Sébastien BEAU <sebastien.beau@akretion.com>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU Affero General Public License as
11# published by the Free Software Foundation, either version 3 of the
12# License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU Affero General Public License for more details.
18#
19# You should have received a copy of the GNU Affero General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21#
22###############################################################################
23
24from openerp.osv import fields, orm
25
26
27class ProductProduct(orm.Model):
28 _inherit = "product.product"
29
30 def copy(self, cr, uid, id, default=None, context=None):
31 if not default:
32 default = {}
33 default.update({
34 'image_ids': False,
35 })
36 return super(ProductProduct, self).\
37 copy(cr, uid, id, default, context=context)
38
39 def _get_main_image_id(self, cr, uid, product_id, context=None):
40 product = self.read(cr, uid, product_id, ['image_ids'],
41 context=context)
42 if product['image_ids']:
43 return product['image_ids'][0]
44 return None
45
46 def __get_main_image(self, cr, uid, ids, field_name, arg, context=None):
47 res = {}
48 img_obj = self.pool.get('product.image')
49 for product_id in ids:
50 image_id = self._get_main_image_id(
51 cr, uid, product_id, context=context)
52 if image_id:
53 image = img_obj.browse(cr, uid, image_id, context=context)
54 res[product_id] = image[field_name]
55 else:
56 res[product_id] = None
57 return res
58
59 _columns = {
60 'image_ids': fields.one2many(
61 'product.image',
62 'product_id',
63 string='Product Image'),
64 'image': fields.function(
65 __get_main_image,
66 type="binary",
67 string="Main Image"),
68 'image_medium': fields.function(
69 __get_main_image,
70 type="binary",
71 string="Medium-sized image"),
72 'image_small': fields.function(
73 __get_main_image,
74 type="binary",
75 string="Small-sized image"),
76 }
077
=== added file 'product_image/product_image.py'
--- product_image/product_image.py 1970-01-01 00:00:00 +0000
+++ product_image/product_image.py 2014-07-01 18:57:09 +0000
@@ -0,0 +1,64 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3#
4# Module for OpenERP
5# Copyright (C) 2009 Sharoon Thomas, Open Labs Business solutions
6# Copyright (C) 2014 Akretion (http://www.akretion.com).
7# @author Sébastien BEAU <sebastien.beau@akretion.com>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU Affero General Public License as
11# published by the Free Software Foundation, either version 3 of the
12# License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU Affero General Public License for more details.
18#
19# You should have received a copy of the GNU Affero General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21#
22###############################################################################
23
24from openerp.osv import fields, orm
25import os
26
27
28class ProductImage(orm.Model):
29 "Products Image"
30 _name = "product.image"
31 _order='sequence,name'
32
33 _columns = {
34 'sequence': fields.integer('Sequence'),
35 'name': fields.char('Image Title'),
36 'file_name': fields.char('File name', required=True),
37 'description': fields.text('Description'),
38 'image': fields.ImageField('Image'),
39 'image_medium': fields.ImageField(
40 'Image',
41 resize_based_on='image',
42 height=128,
43 width=128,
44 ),
45 'image_small': fields.ImageField(
46 'Image',
47 resize_based_on='image',
48 height=64,
49 width=64,
50 ),
51 'product_id': fields.many2one('product.product', 'Product'),
52 }
53
54 _defaults= {
55 'sequence': 0,
56 }
57
58 def onchange_name(self, cr, uid, ids, file_name, name, context=None):
59 if not name:
60 name, extension = os.path.splitext(file_name)
61 for mapping in [('_', ' '), ('.', ' ')]:
62 name = name.replace(mapping[0], mapping[1])
63 return {'value': {'name': name}}
64 return {}
065
=== added file 'product_image/product_image_view.xml'
--- product_image/product_image_view.xml 1970-01-01 00:00:00 +0000
+++ product_image/product_image_view.xml 2014-07-01 18:57:09 +0000
@@ -0,0 +1,76 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<openerp>
3 <data>
4 <record id="view_product_image_form" model="ir.ui.view">
5 <field name="model">product.image</field>
6 <field name="arch" type="xml">
7 <form string="Product Images" version="7.0">
8 <sheet>
9 <field name="image_small" widget="image" class="oe_avatar oe_left" filename="file_name"/>
10 <div class="oe_title">
11 <div class="oe_edit_only">
12 <label for="name"/>
13 </div>
14 <field name="name"/>
15 <div class="oe_edit_only">
16 <label for="file_name"/>
17 </div>
18 <field name="file_name" on_change="onchange_name(file_name, name, context)"/>
19 <label for="sequence"/>
20 <field name="sequence"/>
21 </div>
22 </sheet>
23 </form>
24 </field>
25 </record>
26
27 <record id="view_product_image_tree" model="ir.ui.view">
28 <field name="model">product.image</field>
29 <field name="arch" type="xml">
30 <tree string="Product Images">
31 <field name="name" />
32 </tree>
33 </field>
34 </record>
35
36 <record id="product_normal_form_view" model="ir.ui.view">
37 <field name="model">product.product</field>
38 <field name="inherit_id" ref="product.product_normal_form_view" />
39 <field name="arch" type="xml">
40 <xpath expr="/form/sheet/notebook" position="inside">
41 <page string="Images">
42 <field name="image_ids" nolabel="1" mode="kanban"/>
43 </page>
44 </xpath>
45 </field>
46 </record>
47
48 <record id="product_image_kanban_view" model="ir.ui.view">
49 <field name="model">product.image</field>
50 <field name="arch" type="xml">
51 <kanban quick_create="false" create="true" delete="true">
52 <field name="image_small"/>
53 <field name="name"/>
54 <field name="sequence"/>
55 <templates>
56 <t t-name="kanban-box">
57 <div t-attf-class="oe_kanban_card oe_kanban_project oe_kanban_global_click">
58 <div class="oe_kanban_content">
59 <a type="open">
60 <img t-att-src="kanban_image('product.image', 'image_small', record.id.value)"
61 class="oe_kanban_image"/>
62 </a>
63 </div>
64 <div class="oe_edit_only oe_right" groups="base.group_user">
65 <a type="delete" class="oe_e">[</a>
66 </div>
67
68 </div>
69 </t>
70 </templates>
71 </kanban>
72 </field>
73 </record>
74
75 </data>
76</openerp>

Subscribers

People subscribed via source and target branches