Skip to content

Commit

Permalink
[IMP] Various adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
psugne committed Oct 23, 2024
1 parent 38cd331 commit c5d2efd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 42 deletions.
24 changes: 3 additions & 21 deletions product_multi_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ 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.
#. You can select for which variants you want to make the image available.
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.

Expand All @@ -62,33 +61,16 @@ into account this behaviour:
#. 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.
the variants where it 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/9.0
the variants where it is used.

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
===========
Expand Down
9 changes: 2 additions & 7 deletions product_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/product-attribute",
"category": "Sales Management",
"category": "Product",
"summary": "Add multiple images for a product, a.k.a. an image gallery.",
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
"depends": [
Expand All @@ -23,10 +24,4 @@
"views/product_template_view.xml",
],
"installable": True,
"images": [
"images/product.png",
"images/db.png",
"images/file.png",
"images/url.png",
],
}
12 changes: 6 additions & 6 deletions product_multi_image/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
_logger.info("Cannot import base_multi_image hooks")


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


def uninstall_hook(cr, registry):
def uninstall_hook(env):
"""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(env, "product.template")
uninstall_hook_for_submodules(env, "product.product")
2 changes: 0 additions & 2 deletions product_multi_image/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class ProductProduct(models.Model):
inverse="_inverse_image_ids",
)

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

@api.depends(
"product_tmpl_id",
"product_tmpl_id.image_ids",
Expand Down
2 changes: 0 additions & 2 deletions product_multi_image/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@
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
9 changes: 5 additions & 4 deletions product_multi_image/tests/test_product_multi_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@


class TestProductMultiImage(common.TransactionCase):
def setUp(self):
super().setUp()
@classmethod
def setUpClass(self):
super().setUpClass()
self.transparent_image = ( # 1x1 Transparent GIF
b"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
)
Expand Down Expand Up @@ -204,15 +205,15 @@ def test_11_post_init_hook_template(self):

def test_12_uninstall_hook_product(self):
"""It should remove ``image_ids`` associated with products."""
hooks.uninstall_hook(self.env.cr, self.registry)
hooks.uninstall_hook(self.env.cr)
images = self.env["base_multi_image.image"].search(
[("owner_model", "=", "product.product")],
)
self.assertFalse(len(images))

def test_13_uninstall_hook_template(self):
"""It should remove ``image_ids`` associated with templates."""
hooks.uninstall_hook(self.env.cr, self.registry)
hooks.uninstall_hook(self.env.cr)
images = self.env["base_multi_image.image"].search(
[("owner_model", "=", "product.template")],
)
Expand Down

0 comments on commit c5d2efd

Please sign in to comment.