diff --git a/fs_product_public_category_multi_image/README.rst b/fs_product_public_category_multi_image/README.rst new file mode 100644 index 0000000000..17557a420f --- /dev/null +++ b/fs_product_public_category_multi_image/README.rst @@ -0,0 +1,87 @@ +====================================== +Fs Product Public Category Multi Image +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:52faa35306ff117e720655c0ff7d10523f12a5d0f19d1213cd6d183ed81c513f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_product_public_category_multi_image + :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_product_public_category_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/storage&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Attach images to public categories + +.. 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: + +Usage +===== + +A) Public Categories + + Go to Website > eCommerce > Products > eCommerce Categories. + A new section Images is available to upload or use an existing image. + +For uploading and managing the images see the module fs_product_multi_image. + +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 +======= + +Contributors +~~~~~~~~~~~~ + +* Juany Davila +* Bernat Puig + +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_product_public_category_multi_image/__init__.py b/fs_product_public_category_multi_image/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fs_product_public_category_multi_image/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fs_product_public_category_multi_image/__manifest__.py b/fs_product_public_category_multi_image/__manifest__.py new file mode 100644 index 0000000000..608092dfd4 --- /dev/null +++ b/fs_product_public_category_multi_image/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 ForgeFlow (http://www.forgeflow.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Fs Product Public Category Multi Image", + "summary": """ + Manage multi images from extenal file system on eCommerce public categories""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/storage", + "depends": ["fs_product_multi_image", "website_sale"], + "data": [ + "security/fs_product_public_category_image.xml", + "views/fs_product_public_category_image.xml", + "views/product_public_category.xml", + ], + "demo": [], + "development_status": "Alpha", +} diff --git a/fs_product_public_category_multi_image/models/__init__.py b/fs_product_public_category_multi_image/models/__init__.py new file mode 100644 index 0000000000..a9ec9b952e --- /dev/null +++ b/fs_product_public_category_multi_image/models/__init__.py @@ -0,0 +1,3 @@ +from . import fs_product_public_category_image +from . import image_tag +from . import product_public_category diff --git a/fs_product_public_category_multi_image/models/fs_product_public_category_image.py b/fs_product_public_category_multi_image/models/fs_product_public_category_image.py new file mode 100644 index 0000000000..8f06d713c9 --- /dev/null +++ b/fs_product_public_category_multi_image/models/fs_product_public_category_image.py @@ -0,0 +1,22 @@ +# Copyright 2024 ForgeFlow (http://www.forgeflow.com). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class FsProductPublicCategoryImage(models.Model): + _name = "fs.product.public.category.image" + _inherit = "fs.image.relation.mixin" + _description = "Product Public Category Image" + + public_category_id = fields.Many2one( + "product.public.category", + required=True, + ondelete="cascade", + index=True, + ) + tag_id = fields.Many2many( + "image.tag", + string="Tag", + domain=[("apply_on", "=", "public.category")], + ) diff --git a/fs_product_public_category_multi_image/models/image_tag.py b/fs_product_public_category_multi_image/models/image_tag.py new file mode 100644 index 0000000000..3d757b877d --- /dev/null +++ b/fs_product_public_category_multi_image/models/image_tag.py @@ -0,0 +1,23 @@ +# Copyright 2024 ForgeFlow (http://www.forgeflow.com). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + + +from odoo import api, fields, models + + +class ImageTag(models.Model): + _inherit = "image.tag" + + @api.model + def _get_default_apply_on(self): + active_model = self.env.context.get("active_model") + return ( + "public.category" + if active_model == "public.category.image.relation" + else super()._get_default_apply_on() + ) + + apply_on = fields.Selection( + selection_add=[("public.category", "Public Category")], + ondelete={"product": "cascade", "category": "cascade"}, + ) diff --git a/fs_product_public_category_multi_image/models/product_public_category.py b/fs_product_public_category_multi_image/models/product_public_category.py new file mode 100644 index 0000000000..228ccebc2e --- /dev/null +++ b/fs_product_public_category_multi_image/models/product_public_category.py @@ -0,0 +1,18 @@ +# Copyright 2024 ForgeFlow (http://www.forgeflow.com). +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + +from odoo.addons.fs_image.fields import FSImage + + +class ProductPublicCategory(models.Model): + _inherit = "product.public.category" + + image_ids = fields.One2many( + string="Images", + comodel_name="fs.product.public.category.image", + inverse_name="public_category_id", + ) + image = FSImage(related="image_ids.image", readonly=True, store=False) + image_medium = FSImage(related="image_ids.image_medium", readonly=True, store=False) diff --git a/fs_product_public_category_multi_image/readme/CONTRIBUTORS.rst b/fs_product_public_category_multi_image/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..2c8e1c7e86 --- /dev/null +++ b/fs_product_public_category_multi_image/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Juany Davila +* Bernat Puig diff --git a/fs_product_public_category_multi_image/readme/DESCRIPTION.rst b/fs_product_public_category_multi_image/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..e021256b62 --- /dev/null +++ b/fs_product_public_category_multi_image/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Attach images to public categories diff --git a/fs_product_public_category_multi_image/readme/USAGE.rst b/fs_product_public_category_multi_image/readme/USAGE.rst new file mode 100644 index 0000000000..486c849cdc --- /dev/null +++ b/fs_product_public_category_multi_image/readme/USAGE.rst @@ -0,0 +1,6 @@ +A) Public Categories + + Go to Website > eCommerce > Products > eCommerce Categories. + A new section Images is available to upload or use an existing image. + +For uploading and managing the images see the module fs_product_multi_image. diff --git a/fs_product_public_category_multi_image/security/fs_product_public_category_image.xml b/fs_product_public_category_multi_image/security/fs_product_public_category_image.xml new file mode 100644 index 0000000000..12898d8377 --- /dev/null +++ b/fs_product_public_category_multi_image/security/fs_product_public_category_image.xml @@ -0,0 +1,34 @@ + + + + + + fs.product.public.category.image access read + + + + + + + + + fs.product.public.category.image access system admin + + + + + + + + + fs.product.public.category.image access sales manager + + + + + + + + + diff --git a/fs_product_public_category_multi_image/static/description/icon.png b/fs_product_public_category_multi_image/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/fs_product_public_category_multi_image/static/description/icon.png differ diff --git a/fs_product_public_category_multi_image/static/description/index.html b/fs_product_public_category_multi_image/static/description/index.html new file mode 100644 index 0000000000..814b7ecfb9 --- /dev/null +++ b/fs_product_public_category_multi_image/static/description/index.html @@ -0,0 +1,431 @@ + + + + + +Fs Product Public Category Multi Image + + + +
+

Fs Product Public Category Multi Image

+ + +

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

+

Attach images to public categories

+
+

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

+ +
+

Usage

+
    +
  1. Public Categories

    +

    Go to Website > eCommerce > Products > eCommerce Categories. +A new section Images is available to upload or use an existing image.

    +
  2. +
+

For uploading and managing the images see the module fs_product_multi_image.

+
+
+

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

+ +
+

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_product_public_category_multi_image/tests/__init__.py b/fs_product_public_category_multi_image/tests/__init__.py new file mode 100644 index 0000000000..c686b22ff1 --- /dev/null +++ b/fs_product_public_category_multi_image/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fs_product_multi_image diff --git a/fs_product_public_category_multi_image/tests/test_fs_product_multi_image.py b/fs_product_public_category_multi_image/tests/test_fs_product_multi_image.py new file mode 100644 index 0000000000..1ab14a7141 --- /dev/null +++ b/fs_product_public_category_multi_image/tests/test_fs_product_multi_image.py @@ -0,0 +1,88 @@ +# Copyright 2017 Akretion (http://www.akretion.com). +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 +import io + +from PIL import Image + +from odoo.tests.common import TransactionCase + + +class TestFsProductMultiImage(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.white_image = cls._create_image(16, 16, color="#FFFFFF") + cls.logo_image = cls._create_image(16, 16, color="#FFA500") + cls.product_public_category = cls.env.ref("product.public_category_desks") + cls.image_white = cls.env["fs.image"].create( + { + "image": { + "filename": "white.png", + "content": base64.b64encode(cls.white_image), + } + } + ) + cls.image_logo = cls.env["fs.image"].create( + { + "image": { + "filename": "logo.png", + "content": base64.b64encode(cls.logo_image), + } + } + ) + cls.image_tag = cls.env["image.tag"].create( + { + "name": "Icon", + "apply_on": "public.category", + } + ) + + def setUp(self): + super().setUp() + self.temp_dir = self.env["fs.storage"].create( + { + "name": "Temp FS Storage", + "protocol": "memory", + "code": "mem_dir", + "directory_path": "/tmp/", + "model_xmlids": "fs_product_multi_image.model_fs_product_category_image," + "fs_product_multi_image.model_fs_product_image", + } + ) + + @classmethod + def _create_image(cls, width, height, color="#4169E1", img_format="PNG"): + f = io.BytesIO() + Image.new("RGB", (width, height), color).save(f, img_format) + f.seek(0) + return f.read() + + def _create_multiple_images(self): + logo = self.env["fs.product.public.category.image"].create( + { + "public_category_id": self.product_public_category.id, + "tag_id": self.tag_id.id, + "image_id": self.image_logo.id, + "sequence": 10, + "link_existing": True, + } + ) + image_wh = self.env["fs.product.public.category.image"].create( + { + "public_category_id": self.product_public_category.id, + "tag_id": self.tag_id.id, + "image_id": self.image_white.id, + "sequence": 2, + "link_existing": True, + } + ) + return logo, image_wh + + def test_add_image_for_product_public_category(self): + logo, image_wh = self._create_multiple_images() + # White product should have the white image and the logo + self.assertEqual(self.product_public_category.image_ids, image_wh + logo) diff --git a/fs_product_public_category_multi_image/views/fs_product_public_category_image.xml b/fs_product_public_category_multi_image/views/fs_product_public_category_image.xml new file mode 100644 index 0000000000..6fd05b945c --- /dev/null +++ b/fs_product_public_category_multi_image/views/fs_product_public_category_image.xml @@ -0,0 +1,24 @@ + + + + + + product.public.category.fs.image.form + fs.product.public.category.image + + primary + + + + + + + + diff --git a/fs_product_public_category_multi_image/views/product_public_category.xml b/fs_product_public_category_multi_image/views/product_public_category.xml new file mode 100644 index 0000000000..73e3e3961e --- /dev/null +++ b/fs_product_public_category_multi_image/views/product_public_category.xml @@ -0,0 +1,22 @@ + + + + product.public.category + + + +
+ + + + + +
+
+
+
+
diff --git a/setup/fs_product_public_category_multi_image/odoo/addons/fs_product_public_category_multi_image b/setup/fs_product_public_category_multi_image/odoo/addons/fs_product_public_category_multi_image new file mode 120000 index 0000000000..7bd9475bb3 --- /dev/null +++ b/setup/fs_product_public_category_multi_image/odoo/addons/fs_product_public_category_multi_image @@ -0,0 +1 @@ +../../../../fs_product_public_category_multi_image \ No newline at end of file diff --git a/setup/fs_product_public_category_multi_image/setup.py b/setup/fs_product_public_category_multi_image/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/fs_product_public_category_multi_image/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)