Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addons:

env:
global:
- VERSION="8.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- VERSION="10.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- TRANSIFEX_USER='transbot@odoo-community.org'
- secure: nzJrUI6abQi27D2bzd5wswlEoF5LzLqUyUpb/ZKv9+ylgZcPTmqYr1jFTbh68kVSSpepoL5JrjnWHDlh2qDEyB2Iak00mkGGdydxxVl6EJbkZP2kElrN3OGPTa6pImsNGf3lRoZqhE5nXRfWHcxIYCtX/F6GimPZdTJx9hvyyQQ=

Expand Down
38 changes: 19 additions & 19 deletions product_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Multiple Images in Products",
"version": "8.0.2.0.0",
"author": "Serv. Tecnol. Avanzados - Pedro M. Baeza, "
'name': 'Multiple Images in Products',
'version': '10.0.1.0.0',
'author': "Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Antiun Ingeniería, "
"Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "http://www.serviciosbaeza.com",
"category": "Sales Management",
#"pre_init_hook": "pre_init_hook",
"depends": [
"storage_image",
"product",
'license': 'AGPL-3',
'website': 'http://www.serviciosbaeza.com',
'category': 'Sales',
# "pre_init_hook": "pre_init_hook",
'depends': [
'storage_image',
'product',
],
"data": [
'data': [
'security/ir.model.access.csv',
'security/ir.rule.csv',
'views/image_view.xml',
'views/product_template_view.xml',
'views/product_product_view.xml',
'security/ir.model.access.csv',
'security/ir.rule.csv',
],
'installable': False,
"images": [
"images/product.png",
"images/db.png",
"images/file.png",
"images/url.png",
'images': [
'images/product.png',
'images/db.png',
'images/file.png',
'images/url.png',
],
'installable': True,
}
13 changes: 8 additions & 5 deletions product_multi_image/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from openerp import api, fields, models
from odoo import models, fields, api


class Image(models.Model):
_inherit = "storage.image"
_inherit = 'storage.image'

product_variant_ids = fields.Many2many(
comodel_name="product.product", string="Visible in these variants",
comodel_name='product.product',
string='Visible in these variants',
help="If you leave it empty, all variants will show this image. "
"Selecting one or several of the available variants, you "
"restrict the availability of the image to those variants.")
"restrict the availability of the image to those variants."
)
product_variant_count = fields.Integer(
compute="_compute_product_variant_count")
compute='_compute_product_variant_count'
)

@api.multi
def _compute_product_variant_count(self):
Expand Down
48 changes: 19 additions & 29 deletions product_multi_image/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from openerp import api, fields, models
from openerp.osv import orm
from openerp.osv import fields as old_fields
from odoo import models, fields, api


class ProductProduct(models.Model):
_name = "product.product"
_inherit = [_name, "storage.image.owner.compatibility"]
_name = 'product.product'
_inherit = [_name, 'storage.image.owner.compatibility']

image = fields.Binary(
related='image_main',
store=False
)
image_medium = fields.Binary(
related='image_main_medium',
store=False
)
image_small = fields.Binary(
related='image_main_small',
store=False
)
# Make this field computed for getting only the available images
image_ids = fields.One2many(
compute="_compute_image_ids", comodel_name="storage.image",
inverse="_inverse_image_ids")
compute='_compute_image_ids',
comodel_name='storage.image',
inverse='_inverse_image_ids'
)

@api.multi
@api.depends('product_tmpl_id', 'product_tmpl_id.image_ids',
Expand Down Expand Up @@ -75,25 +87,3 @@ def unlink(self):
len(image.product_variant_ids) == 1))
images2remove.unlink()
return super(ProductProduct, obj).unlink()


class ProductProductOld(orm.Model):
"""It is needed to use v7 api here because core model fields use the
``multi`` attribute, that has no equivalent in v8, and it needs to be
disabled or bad things will happen. For more reference, see
https://github.com/odoo/odoo/issues/10799

Needed for getting the correct data in the inheritance chain. Probably
in v10 this won't be needed as the inheritance has been globally
redesigned.
"""
_name = "product.product"
_inherit = [_name, "storage.image.owner.compatibility"]
_columns = {
"image": old_fields.related(
"image_main", type="binary", store=False, multi=False),
"image_medium": old_fields.related(
"image_main_medium", type="binary", store=False, multi=False),
"image_small": old_fields.related(
"image_main_small", type="binary", store=False, multi=False)
}
36 changes: 16 additions & 20 deletions product_multi_image/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,29 @@
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.osv import orm, fields
from odoo import models, fields


class ProductTemplate(orm.Model):
class ProductTemplate(models.Model):
"""Reference core image fields to multi-image variants.

It is needed to use v7 api here because core model fields use the ``multi``
attribute, that has no equivalent in v8, and it needs to be disabled or
bad things will happen. For more reference, see
https://github.com/odoo/odoo/issues/10799
"""
_name = "product.template"
_name = 'product.template'
_inherit = [_name, "storage.image.owner.compatibility"]
_columns = {
"image": fields.related(
"image_main",
type="binary",
store=False,
multi=False),
"image_medium": fields.related(
"image_main_medium",
type="binary",
store=False,
multi=False),
"image_small": fields.related(
"image_main_small",
type="binary",
store=False,
multi=False)
}

image = fields.Binary(
related='image_main',
store=False
)
image_medium = fields.Binary(
related='image_main_medium',
store=False
)
image_small = fields.Binary(
related='image_main_small',
store=False
)
4 changes: 2 additions & 2 deletions product_multi_image/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_image_edit,product_image edit,storage_image.model_storage_image,base.group_sale_manager,1,1,1,1
access_product_image_file_edit,product_image file edit,storage_file.model_storage_file,base.group_sale_manager,1,1,1,1
access_product_image_edit,product_image edit,storage_image.model_storage_image,product.group_mrp_properties,1,1,1,1
access_product_image_file_edit,product_image file edit,storage_file.model_storage_file,product.group_mrp_properties,1,1,1,1
4 changes: 2 additions & 2 deletions product_multi_image/security/ir.rule.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
id,name,model_id:id,groups:id,perm_read,perm_write,perm_create,perm_unlink,domain_force
access_product_image_retrict_edit,Product image restrict edit,storage_image.model_storage_image,base.group_sale_manager,True,True,True,True,"[('res_model','=', 'product.template')]"
access_product_image_file_retrict_edit,Product image file restrict edit,storage_file.model_storage_file,base.group_sale_manager,True,True,True,True,"[('res_model','=', 'product.template')]"
access_product_image_retrict_edit,Product image restrict edit,storage_image.model_storage_image,product.group_mrp_properties,True,True,True,True,"[('res_model','=', 'product.template')]"
access_product_image_file_retrict_edit,Product image file restrict edit,storage_file.model_storage_file,product.group_mrp_properties,True,True,True,True,"[('res_model','=', 'product.template')]"
86 changes: 42 additions & 44 deletions product_multi_image/views/image_view.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<openerp>
<data>
<odoo>

<record id="image_form_view" model="ir.ui.view">
<field name="name">Multi image form</field>
<field name="model">storage.image</field>
<field name="inherit_id" ref="storage_image.storage_image_view_form"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="alt_name" position="after">
<field name="product_variant_ids"
widget="many2many_tags"
invisible="context.get('default_res_model') != 'product.template'"
domain="[('product_tmpl_id', '=', parent.id)]"
placeholder="(keep empty for being visible for all variants)"
/>
</field>
</field>
</record>
<record id="image_form_view" model="ir.ui.view">
<field name="name">Multi image form</field>
<field name="model">storage.image</field>
<field name="inherit_id" ref="storage_image.storage_image_view_form"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="alt_name" position="after">
<field name="product_variant_ids"
widget="many2many_tags"
invisible="context.get('default_res_model') != 'product.template'"
domain="[('product_tmpl_id', '=', parent.id)]"
placeholder="(keep empty for being visible for all variants)"
/>
</field>
</field>
</record>

<record id="image_kanban_view" model="ir.ui.view">
<field name="name">Product multi image kanban</field>
<field name="model">storage.image</field>
<field name="inherit_id" ref="storage_image.storage_image_view_kanban"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="/kanban/field[@name='alt_name']" position="after">
<field name="product_variant_ids"/>
<field name="product_variant_count"/>
</xpath>
<xpath expr="//field[@name='alt_name']/../.." position="after">
<tr>
<td>
<span t-if="record.product_variant_count.value == 0">
<i>Visible in all variants</i>
</span>
<span t-if="record.product_variant_count.value != 0">
<i>Visible in <field name="product_variant_count"/> variant(s)</i>
</span>
</td>
</tr>
</xpath>
</field>
</record>
<record id="image_kanban_view" model="ir.ui.view">
<field name="name">Product multi image kanban</field>
<field name="model">storage.image</field>
<field name="inherit_id" ref="storage_image.storage_image_view_kanban"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="/kanban/field[@name='alt_name']" position="after">
<field name="product_variant_ids"/>
<field name="product_variant_count"/>
</xpath>
<xpath expr="//field[@name='alt_name']/../.." position="after">
<tr>
<td>
<span t-if="record.product_variant_count.value == 0">
<i>Visible in all variants</i>
</span>
<span t-if="record.product_variant_count.value != 0">
<i>Visible in <field name="product_variant_count"/> variant(s)</i>
</span>
</td>
</tr>
</xpath>
</field>
</record>

</data>
</openerp>
</odoo>
28 changes: 15 additions & 13 deletions product_multi_image/views/product_product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
<!-- © 2015 Antiun Ingeniería S.L. - Jairo Llopis
© 2014-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<openerp>
<data>
<odoo>

<record id="product_kanban_view" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_kanban_view"/>
<field name="arch" type="xml">
<field name="image_small" position="replace">
<field name="image_small_url"/>
</field>
<img class="oe_kanban_image" position="replace">
<img t-att-src="record.image_small_url.value" class="oe_kanban_image"/>
</img>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_kanban_view"/>
<field name="arch" type="xml">
<field name="image_small" position="replace">
<field name="image_small_url"/>
</field>
<div class="o_kanban_image" position="replace">
<div class="o_kanban_image">
<img t-att-src="record.image_small_url.value" class="o_kanban_image"/>
</div>
</div>
</field>
</record>
</data>
</openerp>

</odoo>
Loading