Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0] [MIG] product_multi_image (supersede) #359

Closed
Closed
Show file tree
Hide file tree
Changes from 11 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
14 changes: 11 additions & 3 deletions product_default_image/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
def find_templates_with_imgs(cr, registry):
with cr.savepoint():
env = api.Environment(cr, SUPERUSER_ID, {})
tmpls = env['product.template'].search([
('image', '!=', False),
])
ProductTemplate = env['product.template']
if ProductTemplate._fields['image'].store:
tmpls = ProductTemplate.search([
('image', '!=', False),
])
else:
# some modules (like product_multi_image) could change image to
# non-store, so it is necessary to get all product templates and
# filter them
tmpls = ProductTemplate.search([])
tmpls = tmpls.filtered(lambda tmpl: tmpl.image)
tmpls.write({
'image_type': CUSTOM,
})
106 changes: 106 additions & 0 deletions product_multi_image/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===========================
Multiple Images in Products
===========================

This module implements the possibility to have multiple images for a product
template, a.k.a. an image gallery.

Installation
============

To install this module, you need to:

* Install ``base_multi_image`` from
`OCA/server-tools <https://github.com/OCA/server-tools>`_.

Usage
=====

You can manage your images at Product template level:

#. Go to *Sales > Products > Products* and choose a product template.
#. Go to the *Images* tab.
#. Add a new image or edit the existing ones.
#. You can select for which variants you want to make available the image.
Keep it empty for making visible in all.
#. Refresh the page.
#. The first image in the collection is the main image for the product
template.

Going to product variants form, you can manage also your images, but take
into account this behaviour:

#. Go to *Sales > Products > Product Variants* and choose a product variant.
#. If you add an image here, the image is actually added to the product
template, and restricted to this variant.
#. When editing an existing image, the image is changed generally for all
the variants where is enabled, not only for this variant.
#. When removing an image from this form, if the image is only in this variant,
the image is removed. Otherwise, the image gets restricted to the rest of
the variants where is available.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/135/10.0

Known issues / Roadmap
======================

* When you change the image on the product variant, the preview image of the
*Images* tab doesn't get refreshed until you refresh the browser, or if you
go to its template, but the image has been actually saved!
* The field "Available in these variants" appears when opening the image
from the product variant.
* Add logic for handling to add images with the same name that another variant
of the same template, renaming the new image to a unique name.
* Add logic for handling to add the same image in several variants to a
already in another variant for not duplicating bytes.
* Provide proper migration scripts from module product_images from 7.0.
* Migrate to v8 api when https://github.com/odoo/odoo/issues/10799 gets fixed.
* If you try to sort images before saving the product variant or template, you
will get an error similar to ``DataError: invalid input syntax for integer:
"one2many_v_id_62"``. This bug has not been fixed yet, but a workaround is to
save and edit again to sort images.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/product-attribute/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Original implementation
-----------------------
This module is inspired in previous module *product_images* from OpenLabs
and Akretion.

Contributors
------------

* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Rafael Blasco <rafabn@antiun.com>
* Jairo Llopis <yajo.sk8@gmail.com>
* Dave Lasley <dave@laslabs.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
5 changes: 5 additions & 0 deletions product_multi_image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from . import models
from .hooks import pre_init_hook, uninstall_hook
33 changes: 33 additions & 0 deletions product_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Multiple Images in Products",
"version": "10.0.1.0.0",
"author": "Antiun Ingeniería, "
"Tecnativa, "
"LasLabs, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://www.tecnativa.com",
FFernandez-PlanetaTIC marked this conversation as resolved.
Show resolved Hide resolved
"category": "Sales Management",
"pre_init_hook": "pre_init_hook",
"uninstall_hook": "uninstall_hook",
"depends": [
"base_multi_image",
"product",
],
"data": [
'views/image_view.xml',
'views/product_template_view.xml',
],
'installable': True,
"images": [
"images/product.png",
"images/db.png",
"images/file.png",
"images/url.png",
],
}
24 changes: 24 additions & 0 deletions product_multi_image/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# © 2016 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

try:
from openerp.addons.base_multi_image.hooks import (
pre_init_hook_for_submodules,
uninstall_hook_for_submodules,
)
except ImportError:
pass


def pre_init_hook(cr):
pre_init_hook_for_submodules(cr, "product.template", "image")
pre_init_hook_for_submodules(cr, "product.product", "image_variant")


def uninstall_hook(cr, registry):
"""Remove multi images for models that no longer use them."""
uninstall_hook_for_submodules(cr, registry, "product.template",
field="image", field_medium="image_medium",
field_small="image_small")
uninstall_hook_for_submodules(cr, registry, "product.product")
87 changes: 87 additions & 0 deletions product_multi_image/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_multi_image
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-04-26 18:40+0000\n"
"PO-Revision-Date: 2016-04-26 18:40+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: product_multi_image
#: view:base_multi_image.image:product_multi_image.image_form_view
msgid "(keep empty for being visible for all variants)"
msgstr "(dejar vacío para hacerlo visible para todas las variantes)"

#. module: product_multi_image
#: help:base_multi_image.image,product_variant_ids:0
msgid "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 that variants."
msgstr "Si lo deja vacío, todas las variantes mostrarán esta imagen. Seleccionando una o más de las variantes disponibles, restringirá la disponibilidad de la imagen a esas variantes."

#. module: product_multi_image
#: field:product.product,image_ids:0
#: view:product.template:product_multi_image.view_product_template_form_img_inh
#: field:product.template,image_ids:0
msgid "Images"
msgstr "Imágenes"

#. module: product_multi_image
#: field:product.product,image_main:0
#: field:product.template,image_main:0
msgid "Main image"
msgstr "Imagen principal"

#. module: product_multi_image
#: field:product.product,image_main_medium:0
#: field:product.template,image_main_medium:0
msgid "Medium image"
msgstr "Imagen media"

#. module: product_multi_image
#: model:ir.model,name:product_multi_image.model_product_product
msgid "Product"
msgstr "Producto"

#. module: product_multi_image
#: model:ir.model,name:product_multi_image.model_product_template
msgid "Product Template"
msgstr "Plantilla de producto"

#. module: product_multi_image
#: field:base_multi_image.image,product_variant_count:0
msgid "Product variant count"
msgstr "Nº de variantes"

#. module: product_multi_image
#: field:product.product,image_main_small:0
#: field:product.template,image_main_small:0
msgid "Small image"
msgstr "Imagen pequeña"

#. module: product_multi_image
#: view:base_multi_image.image:product_multi_image.image_kanban_view
msgid "Visible in"
msgstr "Visible en"

#. module: product_multi_image
#: view:base_multi_image.image:product_multi_image.image_kanban_view
msgid "Visible in all variants"
msgstr "Visible en todas las variantes"

#. module: product_multi_image
#: field:base_multi_image.image,product_variant_ids:0
msgid "Visible in these variants"
msgstr "Visible en estas variantes"

#. module: product_multi_image
#: view:base_multi_image.image:product_multi_image.image_kanban_view
msgid "variant(s)"
msgstr "variante(s)"

22 changes: 22 additions & 0 deletions product_multi_image/i18n/sv.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * product_images_olbs
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 5.0.14\n"
"Report-Msgid-Bugs-To: support@odoo.com\n"
"POT-Creation-Date: 2010-11-22 10:19:32+0000\n"
"PO-Revision-Date: 2010-11-22 10:19:32+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: product_images_olbs
#: model:ir.module.module,shortdesc:product_images_olbs.module_meta_information
msgid "Product Image Gallery"
msgstr "Product Image Gallery"

Binary file added product_multi_image/images/db.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added product_multi_image/images/file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added product_multi_image/images/product.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added product_multi_image/images/url.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions product_multi_image/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from . import image
from . import product_template
from . import product_product
22 changes: 22 additions & 0 deletions product_multi_image/models/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from odoo import api, fields, models


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

product_variant_ids = fields.Many2many(
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.")
product_variant_count = fields.Integer(
compute="_compute_product_variant_count")

@api.multi
def _compute_product_variant_count(self):
for image in self:
image.product_variant_count = len(image.product_variant_ids)
Loading