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
1=== added directory 'product_image'
2=== added file 'product_image/__init__.py'
3--- product_image/__init__.py 1970-01-01 00:00:00 +0000
4+++ product_image/__init__.py 2014-07-01 18:57:09 +0000
5@@ -0,0 +1,24 @@
6+# -*- coding: utf-8 -*-
7+###############################################################################
8+#
9+# Module for OpenERP
10+# Copyright (C) 2014 Akretion (http://www.akretion.com).
11+# @author Sébastien BEAU <sebastien.beau@akretion.com>
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+###############################################################################
27+
28+from . import product_image
29+from . import product
30
31=== added file 'product_image/__openerp__.py'
32--- product_image/__openerp__.py 1970-01-01 00:00:00 +0000
33+++ product_image/__openerp__.py 2014-07-01 18:57:09 +0000
34@@ -0,0 +1,49 @@
35+# -*- coding: utf-8 -*-
36+###############################################################################
37+#
38+# Module for OpenERP
39+# Copyright (C) 2014 Akretion (http://www.akretion.com).
40+# @author Sébastien BEAU <sebastien.beau@akretion.com>
41+#
42+# This program is free software: you can redistribute it and/or modify
43+# it under the terms of the GNU Affero General Public License as
44+# published by the Free Software Foundation, either version 3 of the
45+# License, or (at your option) any later version.
46+#
47+# This program is distributed in the hope that it will be useful,
48+# but WITHOUT ANY WARRANTY; without even the implied warranty of
49+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+# GNU Affero General Public License for more details.
51+#
52+# You should have received a copy of the GNU Affero General Public License
53+# along with this program. If not, see <http://www.gnu.org/licenses/>.
54+#
55+###############################################################################
56+
57+{'name': 'Product Image',
58+ 'version': '0.0.1',
59+ 'author': 'Akretion',
60+ 'website': 'www.akretion.com',
61+ 'license': 'AGPL-3',
62+ 'category': 'Generic Modules',
63+ 'description': """
64+This Module implements an Image Gallery for products.
65+You can add images to every product.
66+A thumbnail of every image is visible in the product form view
67+in the tab 'Images'.
68+This module replace the module 'product_images'
69+ """,
70+ 'depends': [
71+ 'product',
72+ 'binary_field',
73+ ],
74+ 'data': [
75+ 'product_image_view.xml',
76+ ],
77+ 'installable': True,
78+ 'application': True,
79+}
80+
81+
82+
83+
84
85=== added file 'product_image/product.py'
86--- product_image/product.py 1970-01-01 00:00:00 +0000
87+++ product_image/product.py 2014-07-01 18:57:09 +0000
88@@ -0,0 +1,76 @@
89+# -*- coding: utf-8 -*-
90+###############################################################################
91+#
92+# Module for OpenERP
93+# Copyright (C) 2009 Sharoon Thomas, Open Labs Business solutions
94+# Copyright (C) 2011-TODAY Akretion (http://www.akretion.com).
95+# @author Sébastien BEAU <sebastien.beau@akretion.com>
96+#
97+# This program is free software: you can redistribute it and/or modify
98+# it under the terms of the GNU Affero General Public License as
99+# published by the Free Software Foundation, either version 3 of the
100+# License, or (at your option) any later version.
101+#
102+# This program is distributed in the hope that it will be useful,
103+# but WITHOUT ANY WARRANTY; without even the implied warranty of
104+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105+# GNU Affero General Public License for more details.
106+#
107+# You should have received a copy of the GNU Affero General Public License
108+# along with this program. If not, see <http://www.gnu.org/licenses/>.
109+#
110+###############################################################################
111+
112+from openerp.osv import fields, orm
113+
114+
115+class ProductProduct(orm.Model):
116+ _inherit = "product.product"
117+
118+ def copy(self, cr, uid, id, default=None, context=None):
119+ if not default:
120+ default = {}
121+ default.update({
122+ 'image_ids': False,
123+ })
124+ return super(ProductProduct, self).\
125+ copy(cr, uid, id, default, context=context)
126+
127+ def _get_main_image_id(self, cr, uid, product_id, context=None):
128+ product = self.read(cr, uid, product_id, ['image_ids'],
129+ context=context)
130+ if product['image_ids']:
131+ return product['image_ids'][0]
132+ return None
133+
134+ def __get_main_image(self, cr, uid, ids, field_name, arg, context=None):
135+ res = {}
136+ img_obj = self.pool.get('product.image')
137+ for product_id in ids:
138+ image_id = self._get_main_image_id(
139+ cr, uid, product_id, context=context)
140+ if image_id:
141+ image = img_obj.browse(cr, uid, image_id, context=context)
142+ res[product_id] = image[field_name]
143+ else:
144+ res[product_id] = None
145+ return res
146+
147+ _columns = {
148+ 'image_ids': fields.one2many(
149+ 'product.image',
150+ 'product_id',
151+ string='Product Image'),
152+ 'image': fields.function(
153+ __get_main_image,
154+ type="binary",
155+ string="Main Image"),
156+ 'image_medium': fields.function(
157+ __get_main_image,
158+ type="binary",
159+ string="Medium-sized image"),
160+ 'image_small': fields.function(
161+ __get_main_image,
162+ type="binary",
163+ string="Small-sized image"),
164+ }
165
166=== added file 'product_image/product_image.py'
167--- product_image/product_image.py 1970-01-01 00:00:00 +0000
168+++ product_image/product_image.py 2014-07-01 18:57:09 +0000
169@@ -0,0 +1,64 @@
170+# -*- coding: utf-8 -*-
171+###############################################################################
172+#
173+# Module for OpenERP
174+# Copyright (C) 2009 Sharoon Thomas, Open Labs Business solutions
175+# Copyright (C) 2014 Akretion (http://www.akretion.com).
176+# @author Sébastien BEAU <sebastien.beau@akretion.com>
177+#
178+# This program is free software: you can redistribute it and/or modify
179+# it under the terms of the GNU Affero General Public License as
180+# published by the Free Software Foundation, either version 3 of the
181+# License, or (at your option) any later version.
182+#
183+# This program is distributed in the hope that it will be useful,
184+# but WITHOUT ANY WARRANTY; without even the implied warranty of
185+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
186+# GNU Affero General Public License for more details.
187+#
188+# You should have received a copy of the GNU Affero General Public License
189+# along with this program. If not, see <http://www.gnu.org/licenses/>.
190+#
191+###############################################################################
192+
193+from openerp.osv import fields, orm
194+import os
195+
196+
197+class ProductImage(orm.Model):
198+ "Products Image"
199+ _name = "product.image"
200+ _order='sequence,name'
201+
202+ _columns = {
203+ 'sequence': fields.integer('Sequence'),
204+ 'name': fields.char('Image Title'),
205+ 'file_name': fields.char('File name', required=True),
206+ 'description': fields.text('Description'),
207+ 'image': fields.ImageField('Image'),
208+ 'image_medium': fields.ImageField(
209+ 'Image',
210+ resize_based_on='image',
211+ height=128,
212+ width=128,
213+ ),
214+ 'image_small': fields.ImageField(
215+ 'Image',
216+ resize_based_on='image',
217+ height=64,
218+ width=64,
219+ ),
220+ 'product_id': fields.many2one('product.product', 'Product'),
221+ }
222+
223+ _defaults= {
224+ 'sequence': 0,
225+ }
226+
227+ def onchange_name(self, cr, uid, ids, file_name, name, context=None):
228+ if not name:
229+ name, extension = os.path.splitext(file_name)
230+ for mapping in [('_', ' '), ('.', ' ')]:
231+ name = name.replace(mapping[0], mapping[1])
232+ return {'value': {'name': name}}
233+ return {}
234
235=== added file 'product_image/product_image_view.xml'
236--- product_image/product_image_view.xml 1970-01-01 00:00:00 +0000
237+++ product_image/product_image_view.xml 2014-07-01 18:57:09 +0000
238@@ -0,0 +1,76 @@
239+<?xml version="1.0" encoding="UTF-8"?>
240+<openerp>
241+ <data>
242+ <record id="view_product_image_form" model="ir.ui.view">
243+ <field name="model">product.image</field>
244+ <field name="arch" type="xml">
245+ <form string="Product Images" version="7.0">
246+ <sheet>
247+ <field name="image_small" widget="image" class="oe_avatar oe_left" filename="file_name"/>
248+ <div class="oe_title">
249+ <div class="oe_edit_only">
250+ <label for="name"/>
251+ </div>
252+ <field name="name"/>
253+ <div class="oe_edit_only">
254+ <label for="file_name"/>
255+ </div>
256+ <field name="file_name" on_change="onchange_name(file_name, name, context)"/>
257+ <label for="sequence"/>
258+ <field name="sequence"/>
259+ </div>
260+ </sheet>
261+ </form>
262+ </field>
263+ </record>
264+
265+ <record id="view_product_image_tree" model="ir.ui.view">
266+ <field name="model">product.image</field>
267+ <field name="arch" type="xml">
268+ <tree string="Product Images">
269+ <field name="name" />
270+ </tree>
271+ </field>
272+ </record>
273+
274+ <record id="product_normal_form_view" model="ir.ui.view">
275+ <field name="model">product.product</field>
276+ <field name="inherit_id" ref="product.product_normal_form_view" />
277+ <field name="arch" type="xml">
278+ <xpath expr="/form/sheet/notebook" position="inside">
279+ <page string="Images">
280+ <field name="image_ids" nolabel="1" mode="kanban"/>
281+ </page>
282+ </xpath>
283+ </field>
284+ </record>
285+
286+ <record id="product_image_kanban_view" model="ir.ui.view">
287+ <field name="model">product.image</field>
288+ <field name="arch" type="xml">
289+ <kanban quick_create="false" create="true" delete="true">
290+ <field name="image_small"/>
291+ <field name="name"/>
292+ <field name="sequence"/>
293+ <templates>
294+ <t t-name="kanban-box">
295+ <div t-attf-class="oe_kanban_card oe_kanban_project oe_kanban_global_click">
296+ <div class="oe_kanban_content">
297+ <a type="open">
298+ <img t-att-src="kanban_image('product.image', 'image_small', record.id.value)"
299+ class="oe_kanban_image"/>
300+ </a>
301+ </div>
302+ <div class="oe_edit_only oe_right" groups="base.group_user">
303+ <a type="delete" class="oe_e">[</a>
304+ </div>
305+
306+ </div>
307+ </t>
308+ </templates>
309+ </kanban>
310+ </field>
311+ </record>
312+
313+ </data>
314+</openerp>

Subscribers

People subscribed via source and target branches