← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image into lp:openerp-product-attributes

 

Sébastien BEAU - http://www.akretion.com has proposed merging lp:~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image into lp:openerp-product-attributes.

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

For more details, see:
https://code.launchpad.net/~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image/+merge/222397

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? 
-- 
https://code.launchpad.net/~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image/+merge/222397
Your team Product Core Editors is requested to review the proposed merge of lp:~akretion-team/openerp-product-attributes/openerp-product-attributes-product-image into lp:openerp-product-attributes.
=== 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-06-06 19:44:24 +0000
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+#   Module for OpenERP
+#   Copyright (C) 2014 Akretion (http://www.akretion.com).
+#   @author Sébastien BEAU <sebastien.beau@xxxxxxxxxxxx>
+#
+#   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/>.
+#
+###############################################################################
+
+from . import product_image
+from . import product

=== added file 'product_image/__openerp__.py'
--- product_image/__openerp__.py	1970-01-01 00:00:00 +0000
+++ product_image/__openerp__.py	2014-06-06 19:44:24 +0000
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+#   Module for OpenERP
+#   Copyright (C) 2014 Akretion (http://www.akretion.com).
+#   @author Sébastien BEAU <sebastien.beau@xxxxxxxxxxxx>
+#
+#   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/>.
+#
+###############################################################################
+
+{'name': 'Product Image',
+ 'version': '0.0.1',
+ 'author': 'Akretion',
+ 'website': 'www.akretion.com',
+ 'license': 'AGPL-3',
+ 'category': 'Generic Modules',
+ 'description': """
+ 
+ """,
+ 'depends': [
+     'product',
+     'binary_field',
+ ],
+ 'data': [
+     'product_image_view.xml',
+ ],
+ 'installable': True,
+ 'application': True,
+}
+
+
+
+

=== added file 'product_image/product.py'
--- product_image/product.py	1970-01-01 00:00:00 +0000
+++ product_image/product.py	2014-06-06 19:44:24 +0000
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+#   Module for OpenERP
+#   Copyright (C) 2009  Sharoon Thomas, Open Labs Business solutions
+#   Copyright (C) 2011-TODAY Akretion (http://www.akretion.com).
+#   @author Sébastien BEAU <sebastien.beau@xxxxxxxxxxxx>
+#
+#   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/>.
+#
+###############################################################################
+
+from openerp.osv import fields, orm
+
+
+class ProductProduct(orm.Model):
+    _inherit = "product.product"
+
+    def copy(self, cr, uid, id, default=None, context=None):
+        if not default:
+            default = {}
+        default.update({
+            'image_ids': False,
+        })
+        return super(ProductProduct, self).\
+            copy(cr, uid, id, default, context=context)
+
+    def _get_main_image_id(self, cr, uid, product_id, context=None):
+        product = self.read(cr, uid, product_id, ['image_ids'],
+                            context=context)
+        if product['image_ids']:
+            return product['image_ids'][0]
+        return None
+
+    def __get_main_image(self, cr, uid, ids, field_name, arg, context=None):
+        res = {}
+        img_obj = self.pool.get('product.image')
+        for product_id in ids:
+            image_id = self._get_main_image_id(
+                cr, uid, product_id, context=context)
+            if image_id:
+                image = img_obj.browse(cr, uid, image_id, context=context)
+                res[product_id] = image[field_name]
+            else:
+                res[product_id] = None
+        return res
+    
+    _columns = {
+        'image_ids': fields.one2many(
+                'product.image',
+                'product_id',
+                string='Product Image'),
+        'image': fields.function(
+            __get_main_image,
+            type="binary",
+            string="Main Image"),
+        'image_medium': fields.function(
+            __get_main_image,
+            type="binary",
+            string="Medium-sized image"),
+        'image_small': fields.function(
+            __get_main_image,
+            type="binary",
+            string="Small-sized image"),
+        }

=== 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-06-06 19:44:24 +0000
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#
+#   Module for OpenERP
+#   Copyright (C) 2009  Sharoon Thomas, Open Labs Business solutions
+#   Copyright (C) 2014 Akretion (http://www.akretion.com).
+#   @author Sébastien BEAU <sebastien.beau@xxxxxxxxxxxx>
+#
+#   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/>.
+#
+###############################################################################
+
+from openerp.osv import fields, orm
+import os
+
+
+class ProductImage(orm.Model):
+    "Products Image"
+    _name = "product.image"
+    _order='sequence,name'
+
+    _columns = {
+        'sequence': fields.integer('Sequence'),
+        'name': fields.char('Image Title'),
+        'file_name': fields.char('File name', required=True),
+        'description': fields.text('Description'),
+        'image': fields.ImageField('Image'),
+        'image_medium': fields.ImageResizeField(
+            related_field='image',
+            string='Image',
+            height=128,
+            width=128,
+            ),
+        'image_small': fields.ImageResizeField(
+            related_field='image',
+            string='Image',
+            height=64,
+            width=64,
+            ),
+        'product_id': fields.many2one('product.product', 'Product'),
+    }
+
+    _defaults= {
+        'sequence': 0,
+    }
+
+    def onchange_name(self, cr, uid, ids, file_name, name, context=None):
+        if not name:
+            name, extension = os.path.splitext(file_name)
+            for mapping in [('_', ' '), ('.', ' ')]:
+                name = name.replace(mapping[0], mapping[1])
+            return {'value': {'name': name}}
+        return {}

=== 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-06-06 19:44:24 +0000
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <record id="view_product_image_form" model="ir.ui.view">
+            <field name="model">product.image</field>
+            <field name="arch" type="xml">
+                <form string="Product Images" version="7.0">
+                    <sheet>
+                        <field name="image_small" widget="image" class="oe_avatar oe_left" filename="file_name"/>
+                        <div class="oe_title">
+                            <div class="oe_edit_only">
+                                <label for="name"/>
+                            </div>
+                            <field name="name"/>
+                            <div class="oe_edit_only">
+                                <label for="file_name"/>
+                            </div>
+                            <field name="file_name" on_change="onchange_name(file_name, name, context)"/>
+                            <label for="sequence"/>
+                            <field name="sequence"/>
+                        </div>
+                    </sheet>
+                </form>
+            </field>
+        </record>
+
+        <record id="view_product_image_tree" model="ir.ui.view">
+            <field name="model">product.image</field>
+            <field name="arch" type="xml">
+                <tree string="Product Images">
+                    <field name="name" />
+                </tree>
+            </field>
+        </record>
+
+        <record id="view_product_form_img_inh" model="ir.ui.view">
+            <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" mode="kanban"/>
+                    </page>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="product_image_kanban_view" model="ir.ui.view">
+            <field name="model">product.image</field>
+            <field name="arch" type="xml">
+                <kanban quick_create="false" create="true" delete="true">
+                    <field name="image_small"/>
+                    <field name="name"/>
+                    <field name="sequence"/>
+                    <templates>
+                        <t t-name="kanban-box">
+                            <div t-attf-class="oe_kanban_card oe_kanban_project oe_kanban_global_click">
+                               <div class="oe_kanban_content">
+                                    <a type="open">
+                                        <img t-att-src="kanban_image('product.image', 'image_small', record.id.value)"
+                                        class="oe_kanban_image"/>
+                                    </a>
+                                </div>
+                                <div class="oe_edit_only oe_right" groups="base.group_user">
+                                    <a type="delete" class="oe_e">[</a>
+                                </div>
+ 
+                            </div>
+                        </t>
+                    </templates>
+                </kanban>
+            </field>
+        </record>
+
+    </data>
+</openerp>