diff --git a/fs_import_image_advanced/models/import_image.py b/fs_import_image_advanced/models/import_image.py index f21733bfe1..5f4f529f89 100644 --- a/fs_import_image_advanced/models/import_image.py +++ b/fs_import_image_advanced/models/import_image.py @@ -251,6 +251,10 @@ def _assign_product_tmpl_attr_values(self, product): product["product_template_attribute_value_ids"] ) + @api.model + def _post_process_image(self, image): + pass + def _do_import(self, lines, product_model, options=None): tag_obj = self.env["image.tag"] image_obj = self.env["fs.image"] @@ -309,6 +313,7 @@ def _do_import(self, lines, product_model, options=None): tmpl_id = prod["product_tmpl_id"][0] image = image_obj.create(file_vals) + self._post_process_image(image) if options.get("overwrite"): domain = [ ("image_id.name", "=", image.name), diff --git a/fs_import_image_advanced_thumbnail/README.rst b/fs_import_image_advanced_thumbnail/README.rst new file mode 100644 index 0000000000..056eeb3a0f --- /dev/null +++ b/fs_import_image_advanced_thumbnail/README.rst @@ -0,0 +1,81 @@ +==================================================== +Import Storage product image thumbnail creation tool +==================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:12c7348e725edb528078c94d16ac9f21b523ef9e01cbaa9c369585b41f3d7f13 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github + :target: https://github.com/OCA/storage/tree/16.0/fs_import_image_advanced_thumbnail + :alt: OCA/storage +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_import_image_advanced_thumbnail + :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/storage&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Hook to auto install thumbnail creation when importing massively images with tool + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Christopher Ormaza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/storage `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/fs_import_image_advanced_thumbnail/__init__.py b/fs_import_image_advanced_thumbnail/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fs_import_image_advanced_thumbnail/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fs_import_image_advanced_thumbnail/__manifest__.py b/fs_import_image_advanced_thumbnail/__manifest__.py new file mode 100644 index 0000000000..35a9026bdd --- /dev/null +++ b/fs_import_image_advanced_thumbnail/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com) +# @author Christopher Ormaza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Import Storage product image thumbnail creation tool", + "version": "16.0.1.0.0", + "summary": "Import product images using CSV", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "maintainer": "chris.ormaza@forgeflow.com", + "website": "https://github.com/OCA/storage", + "category": "Product", + "development_status": "Alpha", + "depends": ["fs_import_image_advanced", "fs_image_thumbnail"], + "data": [], + "license": "AGPL-3", + "installable": True, + "auto_install": True, +} diff --git a/fs_import_image_advanced_thumbnail/models/__init__.py b/fs_import_image_advanced_thumbnail/models/__init__.py new file mode 100644 index 0000000000..71872ae248 --- /dev/null +++ b/fs_import_image_advanced_thumbnail/models/__init__.py @@ -0,0 +1 @@ +from . import import_image diff --git a/fs_import_image_advanced_thumbnail/models/import_image.py b/fs_import_image_advanced_thumbnail/models/import_image.py new file mode 100644 index 0000000000..ab18f68642 --- /dev/null +++ b/fs_import_image_advanced_thumbnail/models/import_image.py @@ -0,0 +1,18 @@ +from odoo import api, models + +from odoo.addons.fs_image.fields import FSImageValue + + +class ProductImageImportWizard(models.Model): + _inherit = "storage.import.product_image" + + @api.model + def _post_process_image(self, image): + thumbnail_model = self.env["fs.thumbnail"] + res = super()._post_process_image(image) + fs_image_value = FSImageValue(attachment=image.image.attachment) + # CHECK ME: This values should be setup on a parameter maybe? + thumbnail_model.get_or_create_thumbnails( + fs_image_value, sizes=[(128, 128), (64, 64)] + ) + return res diff --git a/fs_import_image_advanced_thumbnail/readme/CONTRIBUTORS.rst b/fs_import_image_advanced_thumbnail/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..b647a292e4 --- /dev/null +++ b/fs_import_image_advanced_thumbnail/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Christopher Ormaza diff --git a/fs_import_image_advanced_thumbnail/readme/DESCRIPTION.rst b/fs_import_image_advanced_thumbnail/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..86ac524b0f --- /dev/null +++ b/fs_import_image_advanced_thumbnail/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Hook to auto install thumbnail creation when importing massively images with tool diff --git a/fs_import_image_advanced_thumbnail/static/description/index.html b/fs_import_image_advanced_thumbnail/static/description/index.html new file mode 100644 index 0000000000..9123cb17b2 --- /dev/null +++ b/fs_import_image_advanced_thumbnail/static/description/index.html @@ -0,0 +1,429 @@ + + + + + +Import Storage product image thumbnail creation tool + + + +
+

Import Storage product image thumbnail creation tool

+ + +

Alpha License: AGPL-3 OCA/storage Translate me on Weblate Try me on Runboat

+

Hook to auto install thumbnail creation when importing massively images with tool

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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/storage project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/fs_import_image_advanced_thumbnail/tests/__init__.py b/fs_import_image_advanced_thumbnail/tests/__init__.py new file mode 100644 index 0000000000..d8bf9059cd --- /dev/null +++ b/fs_import_image_advanced_thumbnail/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fs_import_image_advanced_thumbnail diff --git a/fs_import_image_advanced_thumbnail/tests/test_fs_import_image_advanced_thumbnail.py b/fs_import_image_advanced_thumbnail/tests/test_fs_import_image_advanced_thumbnail.py new file mode 100644 index 0000000000..dabe3af740 --- /dev/null +++ b/fs_import_image_advanced_thumbnail/tests/test_fs_import_image_advanced_thumbnail.py @@ -0,0 +1,24 @@ +from odoo.addons.fs_import_image_advanced.tests.test_import_image import ( + TestStorageImportImage, +) + + +class TestStorageImportImageThumbnail(TestStorageImportImage): + def setUp(self): + super().setUp() + + def test_thumbnail_creation(self): + wiz = self._get_wizard() + wiz.do_import() + products_with_image_attachments = self.products.filtered( + lambda x: x.default_code in ["A001", "A002"] + ) + images = products_with_image_attachments.mapped("image_ids") + attachments = self.env["ir.attachment"] + for image in images: + attachments |= image.image_id.image.attachment + thumbnails = self.env["fs.thumbnail"] + for attachment in attachments: + for thumbnail in attachment.thumbnail_ids: + thumbnails |= thumbnail + self.assertEqual(len(thumbnails), len(attachments) * 2) diff --git a/setup/fs_import_image_advanced_thumbnail/odoo/addons/fs_import_image_advanced_thumbnail b/setup/fs_import_image_advanced_thumbnail/odoo/addons/fs_import_image_advanced_thumbnail new file mode 120000 index 0000000000..0d2a422fb7 --- /dev/null +++ b/setup/fs_import_image_advanced_thumbnail/odoo/addons/fs_import_image_advanced_thumbnail @@ -0,0 +1 @@ +../../../../fs_import_image_advanced_thumbnail \ No newline at end of file diff --git a/setup/fs_import_image_advanced_thumbnail/setup.py b/setup/fs_import_image_advanced_thumbnail/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/fs_import_image_advanced_thumbnail/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)