Skip to content

Commit

Permalink
[MIG] product_multi_image: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
IJOL committed Sep 30, 2024
1 parent 96a11bb commit 2cc4f89
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 31 deletions.
10 changes: 5 additions & 5 deletions product_multi_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Multiple Images in Products
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/15.0/product_multi_image
:target: https://github.com/OCA/product-attribute/tree/16.0/product_multi_image
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-15-0/product-attribute-15-0-product_multi_image
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_multi_image
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -99,7 +99,7 @@ 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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_multi_image%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_multi_image%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -151,6 +151,6 @@ 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.

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/15.0/product_multi_image>`_ project on GitHub.
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_multi_image>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion product_multi_image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3).

from . import models
from .hooks import pre_init_hook, uninstall_hook
from .hooks import post_init_hook, uninstall_hook
4 changes: 2 additions & 2 deletions product_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

{
"name": "Multiple Images in Products",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Antiun Ingeniería, "
"Tecnativa, "
"LasLabs, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/product-attribute",
"category": "Sales Management",
"pre_init_hook": "pre_init_hook",
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
"depends": [
"base_multi_image",
Expand Down
12 changes: 6 additions & 6 deletions product_multi_image/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

try:
from odoo.addons.base_multi_image.hooks import (
pre_init_hook_for_submodules,
post_init_hook_for_submodules,
uninstall_hook_for_submodules,
)
except ImportError:
_logger.info("Cannot import base_multi_image hooks")


def pre_init_hook(cr):
pre_init_hook_for_submodules(cr, "product.template", "image_1920")
pre_init_hook_for_submodules(cr, "product.product", "image_variant_1920")
def post_init_hook(cr, registry):
post_init_hook_for_submodules(cr, "product.template", "image_1920")
post_init_hook_for_submodules(cr, "product.product", "image_variant_1920")


def uninstall_hook(cr, registry):
"""Remove multi images for models that no longer use them."""
uninstall_hook_for_submodules(cr, registry, "product.template")
uninstall_hook_for_submodules(cr, registry, "product.product")
uninstall_hook_for_submodules(cr, "product.template", "image_1920")
uninstall_hook_for_submodules(cr, "product.product", "image_variant_1920")
6 changes: 4 additions & 2 deletions product_multi_image/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def _compute_image_ids(self):
)
product.image_ids = [(6, 0, images.ids)]
if product.image_ids:
product.image_1920 = product.image_ids[0].image_main
product.image_1920 = (
product.with_context(bin_size=False).image_ids[0].image_1920
)

def _inverse_image_ids(self):
for product in self:
Expand Down Expand Up @@ -66,7 +68,7 @@ def _inverse_image_ids(self):
# Leave the images for the rest of the variants
image.product_variant_ids = [(6, 0, variants.ids)]
product.image_1920 = (
False if len(product.image_ids) < 1 else product.image_ids[0].image_main
False if len(product.image_ids) < 1 else product.image_ids[0].image_1920
)

def unlink(self):
Expand Down
46 changes: 45 additions & 1 deletion product_multi_image/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,55 @@
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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


class ProductTemplate(models.Model):
_name = "product.template"
_inherit = [_name, "base_multi_image.owner"]

# image, image_medium, image_small fields are not available since 13.0

image_1920 = fields.Binary(
compute="_compute_image_1920",
inverse="_inverse_image_1920",
store=True,
)

@api.depends(
"image_ids",
)
def _compute_image_1920(self):
for product in self:
images = product.image_ids.filtered(
lambda x: not x.product_variant_ids
or product.product_variant_count == 1
)
if images:
product.image_1920 = images[0].with_context(bin_size=False).image_1920

def _inverse_image_1920(self):
for product in self:
images = product.image_ids.filtered(
lambda x: not x.product_variant_ids
or product.product_variant_count == 1
)
if images:
img_new = product.with_context(bin_size=False).image_1920
if images[0].image_1920 != img_new:
images[0].image_1920 = img_new
else:
product.image_ids = [
(
0,
False,
{
"name": product.name,
"image_1920": product.with_context(
bin_size=False
).image_1920,
"owner_id": product.id,
"owner_model": "product.template",
},
)
]
7 changes: 3 additions & 4 deletions product_multi_image/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">Multiple Images in Products</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6dc98dd3fc0494ff6c8f8250d65117a27e8f2cc176db276ff0573ad890116609
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/15.0/product_multi_image"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-15-0/product-attribute-15-0-product_multi_image"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/16.0/product_multi_image"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_multi_image"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module implements the possibility to have multiple images for a product
template, a.k.a. an image gallery.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -451,7 +450,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-attribute/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_multi_image%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_multi_image%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -501,7 +500,7 @@ <h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/15.0/product_multi_image">OCA/product-attribute</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/16.0/product_multi_image">OCA/product-attribute</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
20 changes: 13 additions & 7 deletions product_multi_image/tests/test_product_multi_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,17 @@ def setUp(self):
0,
0,
{
"storage": "db",
"name": "Image 1",
"file_db_store": self.transparent_image,
"image_1920": self.transparent_image,
"owner_model": "product.template",
},
),
(
0,
0,
{
"storage": "db",
"name": "Image 2",
"file_db_store": self.black_image,
"image_1920": self.black_image,
"owner_model": "product.template",
},
),
Expand All @@ -92,7 +90,14 @@ def test_restrict_one_image(self):

def test_add_image_variant(self):
self.product_1.image_ids = [
(0, 0, {"storage": "db", "file_db_store": self.grey_image})
(
0,
0,
{
# "storage": "db",
"image_1920": self.grey_image
},
)
]
self.product_template.refresh()
self.assertEqual(len(self.product_template.image_ids), 3)
Expand Down Expand Up @@ -132,9 +137,10 @@ def test_create_variant_afterwards(self):
0,
0,
{
"storage": "db",
# "storage": "db",
"name": "Image 1",
"file_db_store": self.transparent_image,
# "file_db_store": self.transparent_image,
"image_1920": self.transparent_image,
"owner_model": "product.template",
},
)
Expand Down
6 changes: 3 additions & 3 deletions product_multi_image/views/image_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field name="inherit_id" ref="base_multi_image.image_form_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="file_db_store" position="after">
<field name="load_from" position="after">
<field
name="product_variant_ids"
widget="many2many_tags"
Expand All @@ -26,11 +26,11 @@
<field name="inherit_id" ref="base_multi_image.image_kanban_view" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="/kanban/field[@name='storage']" position="after">
<xpath expr="/kanban/field[@name='name']" position="after">
<field name="product_variant_ids" />
<field name="product_variant_count" />
</xpath>
<xpath expr="//field[@name='storage']/../.." position="after">
<xpath expr="//field[@name='name']/../.." position="after">
<tr>
<td>
<span t-if="record.product_variant_count.value == 0">
Expand Down
1 change: 1 addition & 0 deletions setup/product_multi_image/odoo/addons/product_multi_image
6 changes: 6 additions & 0 deletions setup/product_multi_image/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 2cc4f89

Please sign in to comment.