diff --git a/setup/shopinvader_search_engine_update/odoo/addons/shopinvader_search_engine_update b/setup/shopinvader_search_engine_update/odoo/addons/shopinvader_search_engine_update new file mode 120000 index 0000000000..bd774115c5 --- /dev/null +++ b/setup/shopinvader_search_engine_update/odoo/addons/shopinvader_search_engine_update @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_update \ No newline at end of file diff --git a/setup/shopinvader_search_engine_update/setup.py b/setup/shopinvader_search_engine_update/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_update/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_search_engine_update_image/odoo/addons/shopinvader_search_engine_update_image b/setup/shopinvader_search_engine_update_image/odoo/addons/shopinvader_search_engine_update_image new file mode 120000 index 0000000000..e823e710c6 --- /dev/null +++ b/setup/shopinvader_search_engine_update_image/odoo/addons/shopinvader_search_engine_update_image @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_update_image \ No newline at end of file diff --git a/setup/shopinvader_search_engine_update_image/setup.py b/setup/shopinvader_search_engine_update_image/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_update_image/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_search_engine_update_product_brand/odoo/addons/shopinvader_search_engine_update_product_brand b/setup/shopinvader_search_engine_update_product_brand/odoo/addons/shopinvader_search_engine_update_product_brand new file mode 120000 index 0000000000..fa1fd3d4f5 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_brand/odoo/addons/shopinvader_search_engine_update_product_brand @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_update_product_brand \ No newline at end of file diff --git a/setup/shopinvader_search_engine_update_product_brand/setup.py b/setup/shopinvader_search_engine_update_product_brand/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_brand/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_search_engine_update_product_brand_image/odoo/addons/shopinvader_search_engine_update_product_brand_image b/setup/shopinvader_search_engine_update_product_brand_image/odoo/addons/shopinvader_search_engine_update_product_brand_image new file mode 120000 index 0000000000..93ae7fdcd3 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_brand_image/odoo/addons/shopinvader_search_engine_update_product_brand_image @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_update_product_brand_image \ No newline at end of file diff --git a/setup/shopinvader_search_engine_update_product_brand_image/setup.py b/setup/shopinvader_search_engine_update_product_brand_image/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_brand_image/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_search_engine_update_product_brand_tag/odoo/addons/shopinvader_search_engine_update_product_brand_tag b/setup/shopinvader_search_engine_update_product_brand_tag/odoo/addons/shopinvader_search_engine_update_product_brand_tag new file mode 120000 index 0000000000..21ec028012 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_brand_tag/odoo/addons/shopinvader_search_engine_update_product_brand_tag @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_update_product_brand_tag \ No newline at end of file diff --git a/setup/shopinvader_search_engine_update_product_brand_tag/setup.py b/setup/shopinvader_search_engine_update_product_brand_tag/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_brand_tag/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_search_engine_update_product_media/odoo/addons/shopinvader_search_engine_update_product_media b/setup/shopinvader_search_engine_update_product_media/odoo/addons/shopinvader_search_engine_update_product_media new file mode 120000 index 0000000000..4076734c7c --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_media/odoo/addons/shopinvader_search_engine_update_product_media @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_update_product_media \ No newline at end of file diff --git a/setup/shopinvader_search_engine_update_product_media/setup.py b/setup/shopinvader_search_engine_update_product_media/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_update_product_media/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopinvader_search_engine/tests/common.py b/shopinvader_search_engine/tests/common.py index f32b600549..c09bda6738 100644 --- a/shopinvader_search_engine/tests/common.py +++ b/shopinvader_search_engine/tests/common.py @@ -36,3 +36,71 @@ def tearDownClass(cls): cls.loader.restore_registry() cls.reset_extendable_registry() super().tearDownClass() + + +class TestCategoryBindingBase(TestBindingIndexBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.setup_records() + + @classmethod + def _prepare_index_values(cls, backend=None): + backend = backend or cls.backend + return { + "name": "Category Index", + "backend_id": backend.id, + "model_id": cls.env["ir.model"] + .search([("model", "=", "product.category")], limit=1) + .id, + "lang_id": cls.env.ref("base.lang_en").id, + "serializer_type": "shopinvader_category_exports", + } + + @classmethod + def setup_records(cls, backend=None): + backend = backend or cls.backend + # create an index for category model + cls.se_index = cls.se_index_model.create(cls._prepare_index_values(backend)) + # create a binding + category alltogether + cls.category = cls.env["product.category"].create({"name": "Test category"}) + cls.category_binding = cls.category._add_to_index(cls.se_index) + + +class TestProductBindingMixin: + @classmethod + def _prepare_index_values(cls, tst_cls, backend=None): + backend = backend or tst_cls.backend + return { + "name": "Product Index", + "backend_id": backend.id, + "model_id": tst_cls.env["ir.model"] + .search([("model", "=", "product.product")], limit=1) + .id, + "lang_id": tst_cls.env.ref("base.lang_en").id, + "serializer_type": "shopinvader_product_exports", + } + + @classmethod + def setup_records(cls, tst_cls, backend=None): + backend = backend or tst_cls.backend + # create an index for product model + tst_cls.se_index = tst_cls.env["se.index"].create( + cls._prepare_index_values(tst_cls, backend) + ) + # create a binding + product alltogether + tst_cls.product = tst_cls.env.ref( + "shopinvader_product.product_product_chair_vortex_white" + ) + tst_cls.product_binding = tst_cls.product._add_to_index(tst_cls.se_index) + tst_cls.product_expected = { + "id": tst_cls.product.id, + "name": tst_cls.product.name, + } + + +class TestProductBindingBase(TestBindingIndexBase, TestProductBindingMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + TestProductBindingMixin.setup_records(cls) diff --git a/shopinvader_search_engine/tests/test_category_binding.py b/shopinvader_search_engine/tests/test_category_binding.py index a09f42319c..46a596f26f 100644 --- a/shopinvader_search_engine/tests/test_category_binding.py +++ b/shopinvader_search_engine/tests/test_category_binding.py @@ -1,36 +1,16 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from .common import TestBindingIndexBase +from .common import TestCategoryBindingBase -class TestCategoryBinding(TestBindingIndexBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.setup_records() - - @classmethod - def _prepare_index_values(cls, backend=None): - backend = backend or cls.backend - return { - "name": "Category Index", - "backend_id": backend.id, - "model_id": cls.env["ir.model"] - .search([("model", "=", "product.category")], limit=1) - .id, - "lang_id": cls.env.ref("base.lang_en").id, - "serializer_type": "shopinvader_category_exports", - } - - @classmethod - def setup_records(cls, backend=None): - backend = backend or cls.backend - # create an index for category model - cls.se_index = cls.se_index_model.create(cls._prepare_index_values(backend)) - # create a binding + category alltogether - cls.category = cls.env["product.category"].create({"name": "Test category"}) - cls.category_binding = cls.category._add_to_index(cls.se_index) +class TestCategoryBinding(TestCategoryBindingBase): + def _create_parent_category(self): + parent_category = self.env["product.category"].create( + {"name": "Parent category"} + ) + self.category.parent_id = parent_category + return parent_category def test_serialize(self): self.category_binding.recompute_json() @@ -39,13 +19,6 @@ def test_serialize(self): self.assertEqual(data["name"], self.category.name) self.assertEqual(data["level"], 0) - def _create_parent_category(self): - parent_category = self.env["product.category"].create( - {"name": "Parent category"} - ) - self.category.parent_id = parent_category - return parent_category - def test_serialize_hierarchy_parent_not_in_index(self): self._create_parent_category() self.category_binding.recompute_json() diff --git a/shopinvader_search_engine/tests/test_product_binding.py b/shopinvader_search_engine/tests/test_product_binding.py index 05e88bc239..e7f94da93e 100644 --- a/shopinvader_search_engine/tests/test_product_binding.py +++ b/shopinvader_search_engine/tests/test_product_binding.py @@ -1,39 +1,10 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from .common import TestBindingIndexBase +from .common import TestProductBindingBase -class TestProductBinding(TestBindingIndexBase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.setup_records() - - @classmethod - def _prepare_index_values(cls, backend=None): - backend = backend or cls.backend - return { - "name": "Product Index", - "backend_id": backend.id, - "model_id": cls.env["ir.model"] - .search([("model", "=", "product.product")], limit=1) - .id, - "lang_id": cls.env.ref("base.lang_en").id, - "serializer_type": "shopinvader_product_exports", - } - - @classmethod - def setup_records(cls, backend=None): - backend = backend or cls.backend - # create an index for product model - cls.se_index = cls.se_index_model.create(cls._prepare_index_values(backend)) - # create a binding + product alltogether - cls.product = cls.env.ref( - "shopinvader_product.product_product_chair_vortex_white" - ) - cls.product_binding = cls.product._add_to_index(cls.se_index) - +class TestProductBinding(TestProductBindingBase): def test_serialize(self): self.product_binding.recompute_json() data = self.product_binding.data diff --git a/shopinvader_search_engine_product_brand_image/tests/common.py b/shopinvader_search_engine_product_brand_image/tests/common.py new file mode 100644 index 0000000000..613211b185 --- /dev/null +++ b/shopinvader_search_engine_product_brand_image/tests/common.py @@ -0,0 +1,76 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import base64 + +from odoo.addons.shopinvader_search_engine_image.tests.common import ( + TestSeMultiImageThumbnailCase, +) + + +class ProductBrandImageCase(TestSeMultiImageThumbnailCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.backend.image_data_url_strategy = "odoo" + # create index for brands + cls.brand_index = cls.env["se.index"].create( + { + "name": "brand", + "backend_id": cls.backend.id, + "model_id": cls.env.ref("product_brand.model_product_brand").id, + "serializer_type": "shopinvader_brand_exports", + } + ) + # create sizes for brands + cls.env["se.image.field.thumbnail.size"].create( + { + "model_id": cls.env.ref("product_brand.model_product_brand").id, + "field_id": cls.env.ref( + "fs_product_brand_multi_image.field_product_brand__image_ids" + ).id, + "backend_id": cls.backend.id, + "size_ids": [(6, 0, [cls.size_small.id, cls.size_medium.id])], + } + ) + cls.brand = cls.env["product.brand"].create( + { + "name": "Test Brand", + } + ) + cls.brand_white_image = cls.env["fs.product.brand.image"].create( + { + "sequence": 1, + "brand_id": cls.brand.id, + "specific_image": { + "filename": "white.png", + "content": base64.b64encode(cls.white_image), + }, + "tag_id": cls.tag1.id, + } + ) + cls.brand_black_image = cls.env["fs.product.brand.image"].create( + { + "sequence": 2, + "brand_id": cls.brand.id, + "specific_image": { + "filename": "black.png", + "content": base64.b64encode(cls.black_image), + }, + "tag_id": cls.tag2.id, + } + ) + cls.brand_binding = cls.brand._add_to_index(cls.brand_index) + + def setUp(self): + super().setUp() + self.fs_storage = self.env["fs.storage"].create( + { + "name": "Temp FS Storage", + "protocol": "memory", + "code": "mem_dir_brand", + "directory_path": "/tmp/", + "model_xmlids": "fs_product_brand_multi_image.model_fs_product_brand_image", + "base_url": "https://media.alcyonbelux.be/", + "is_directory_path_in_url": False, + } + ) diff --git a/shopinvader_search_engine_product_brand_image/tests/test_brand.py b/shopinvader_search_engine_product_brand_image/tests/test_brand.py index 4c3e969d90..93ef1d0010 100644 --- a/shopinvader_search_engine_product_brand_image/tests/test_brand.py +++ b/shopinvader_search_engine_product_brand_image/tests/test_brand.py @@ -2,81 +2,10 @@ # @author Sébastien BEAU # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -import base64 +from .common import ProductBrandImageCase -from odoo.addons.shopinvader_search_engine_image.tests.common import ( - TestSeMultiImageThumbnailCase, -) - - -class ProductBrandCase(TestSeMultiImageThumbnailCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.backend.image_data_url_strategy = "odoo" - # create index for brands - cls.brand_index = cls.env["se.index"].create( - { - "name": "brand", - "backend_id": cls.backend.id, - "model_id": cls.env.ref("product_brand.model_product_brand").id, - "serializer_type": "shopinvader_brand_exports", - } - ) - # create sizes for brands - cls.env["se.image.field.thumbnail.size"].create( - { - "model_id": cls.env.ref("product_brand.model_product_brand").id, - "field_id": cls.env.ref( - "fs_product_brand_multi_image.field_product_brand__image_ids" - ).id, - "backend_id": cls.backend.id, - "size_ids": [(6, 0, [cls.size_small.id, cls.size_medium.id])], - } - ) - cls.brand = cls.env["product.brand"].create( - { - "name": "Test Brand", - } - ) - cls.brand_white_image = cls.env["fs.product.brand.image"].create( - { - "sequence": 1, - "brand_id": cls.brand.id, - "specific_image": { - "filename": "white.png", - "content": base64.b64encode(cls.white_image), - }, - "tag_id": cls.tag1.id, - } - ) - cls.brand_black_image = cls.env["fs.product.brand.image"].create( - { - "sequence": 2, - "brand_id": cls.brand.id, - "specific_image": { - "filename": "black.png", - "content": base64.b64encode(cls.black_image), - }, - "tag_id": cls.tag2.id, - } - ) - cls.brand_binding = cls.brand._add_to_index(cls.brand_index) - - def setUp(self): - super().setUp() - self.fs_storage = self.env["fs.storage"].create( - { - "name": "Temp FS Storage", - "protocol": "memory", - "code": "mem_dir_brand", - "directory_path": "/tmp/", - "model_xmlids": "fs_product_brand_multi_image.model_fs_product_brand_image", - "base_url": "https://media.alcyonbelux.be/", - "is_directory_path_in_url": False, - } - ) +class TestBrand(ProductBrandImageCase): def test_basic_images_compute(self): brand = self.brand_binding._contextualize(self.brand_binding) data = self.brand_index.model_serializer.serialize(brand.record) diff --git a/shopinvader_search_engine_product_media/tests/common.py b/shopinvader_search_engine_product_media/tests/common.py new file mode 100644 index 0000000000..0c2a18573e --- /dev/null +++ b/shopinvader_search_engine_product_media/tests/common.py @@ -0,0 +1,55 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo_test_helper import FakeModelLoader + +from odoo.addons.connector_search_engine.tests.common import TestSeBackendCaseBase +from odoo.addons.extendable.tests.common import ExtendableMixin +from odoo.addons.fs_product_multi_media.tests.test_fs_product_multi_media import ( + TestFsProductMultiMedia, +) + + +class ProductMediaCase(TestFsProductMultiMedia, TestSeBackendCaseBase, ExtendableMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.init_extendable_registry() + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from odoo.addons.connector_search_engine.tests.models import SeBackend, SeIndex + + cls.loader.update_registry( + ( + SeIndex, + SeBackend, + ) + ) + cls.backend = cls.env["se.backend"].create( + {"name": "Fake SE", "tech_name": "fake_se", "backend_type": "fake"} + ) + cls.product_index = cls.env["se.index"].create( + { + "name": "product", + "backend_id": cls.backend.id, + "model_id": cls.env.ref("product.model_product_product").id, + "serializer_type": "shopinvader_product_exports", + } + ) + cls.product_binding = cls.product_a._add_to_index(cls.product_index) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + cls.reset_extendable_registry() + super().tearDownClass() + + def _default_media(self, media): + return { + "name": media.media_id.name, + "url": media.media_id.file.internal_url, + "type": { + "name": media.media_id.media_type_id.name, + "code": media.media_id.media_type_id.code, + }, + "sequence": media.sequence, + } diff --git a/shopinvader_search_engine_product_media/tests/test_shopinvader_search_engine_media.py b/shopinvader_search_engine_product_media/tests/test_shopinvader_search_engine_media.py index 4c3639b946..09590acbde 100644 --- a/shopinvader_search_engine_product_media/tests/test_shopinvader_search_engine_media.py +++ b/shopinvader_search_engine_product_media/tests/test_shopinvader_search_engine_media.py @@ -1,61 +1,9 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo_test_helper import FakeModelLoader +from .common import ProductMediaCase -from odoo.addons.connector_search_engine.tests.common import TestSeBackendCaseBase -from odoo.addons.extendable.tests.common import ExtendableMixin -from odoo.addons.fs_product_multi_media.tests.test_fs_product_multi_media import ( - TestFsProductMultiMedia, -) - - -class TestShopinvaderSearchEngineMedia( - TestFsProductMultiMedia, TestSeBackendCaseBase, ExtendableMixin -): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.init_extendable_registry() - cls.loader = FakeModelLoader(cls.env, cls.__module__) - cls.loader.backup_registry() - from odoo.addons.connector_search_engine.tests.models import SeBackend, SeIndex - - cls.loader.update_registry( - ( - SeIndex, - SeBackend, - ) - ) - cls.backend = cls.env["se.backend"].create( - {"name": "Fake SE", "tech_name": "fake_se", "backend_type": "fake"} - ) - cls.product_index = cls.env["se.index"].create( - { - "name": "product", - "backend_id": cls.backend.id, - "model_id": cls.env.ref("product.model_product_product").id, - "serializer_type": "shopinvader_product_exports", - } - ) - cls.product_binding = cls.product_a._add_to_index(cls.product_index) - - @classmethod - def tearDownClass(cls): - cls.loader.restore_registry() - cls.reset_extendable_registry() - super().tearDownClass() - - def _default_media(self, media): - return { - "name": media.media_id.name, - "url": media.media_id.file.internal_url, - "type": { - "name": media.media_id.media_type_id.name, - "code": media.media_id.media_type_id.code, - }, - "sequence": media.sequence, - } +class TestShopinvaderSearchEngineMedia(ProductMediaCase): def test_product_media(self): self.backend.media_data_url_strategy = "odoo" product = self.product_binding._contextualize(self.product_binding) diff --git a/shopinvader_search_engine_update/README.rst b/shopinvader_search_engine_update/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/shopinvader_search_engine_update/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/shopinvader_search_engine_update/__init__.py b/shopinvader_search_engine_update/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_search_engine_update/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_search_engine_update/__manifest__.py b/shopinvader_search_engine_update/__manifest__.py new file mode 100644 index 0000000000..5502b9e4f3 --- /dev/null +++ b/shopinvader_search_engine_update/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Search Engine Update", + "summary": """ + Shopinvader: Mark product binding to export on product update""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "shopinvader_search_engine", + ], + "data": [], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_update/models/__init__.py b/shopinvader_search_engine_update/models/__init__.py new file mode 100644 index 0000000000..8b215bebbc --- /dev/null +++ b/shopinvader_search_engine_update/models/__init__.py @@ -0,0 +1,4 @@ +from . import product_product +from . import product_template +from . import se_indexable_record +from . import se_product_update_mixin diff --git a/shopinvader_search_engine_update/models/product_product.py b/shopinvader_search_engine_update/models/product_product.py new file mode 100644 index 0000000000..fb54854f82 --- /dev/null +++ b/shopinvader_search_engine_update/models/product_product.py @@ -0,0 +1,13 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def write(self, vals): + res = super(ProductProduct, self).write(vals) + self.shopinvader_mark_to_update() + return res diff --git a/shopinvader_search_engine_update/models/product_template.py b/shopinvader_search_engine_update/models/product_template.py new file mode 100644 index 0000000000..0d9b1fe7a8 --- /dev/null +++ b/shopinvader_search_engine_update/models/product_template.py @@ -0,0 +1,16 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def write(self, vals): + res = super(ProductTemplate, self).write(vals) + self.mapped("product_variant_ids").shopinvader_mark_to_update() + return res + + def shopinvader_mark_to_update(self): + self.mapped("product_variant_ids").shopinvader_mark_to_update() diff --git a/shopinvader_search_engine_update/models/se_indexable_record.py b/shopinvader_search_engine_update/models/se_indexable_record.py new file mode 100644 index 0000000000..9f1867919c --- /dev/null +++ b/shopinvader_search_engine_update/models/se_indexable_record.py @@ -0,0 +1,15 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class SeIndexableRecord(models.AbstractModel): + + _inherit = "se.indexable.record" + + def shopinvader_mark_to_update(self): + """This method is called in the context of shopinvader to mark a binding + linked to this record to be updated in the search engine. + + """ + self.sudo()._se_mark_to_update() diff --git a/shopinvader_search_engine_update/models/se_product_update_mixin.py b/shopinvader_search_engine_update/models/se_product_update_mixin.py new file mode 100644 index 0000000000..5990f3b25a --- /dev/null +++ b/shopinvader_search_engine_update/models/se_product_update_mixin.py @@ -0,0 +1,37 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, models + + +class SEProductUpdateMixin(models.AbstractModel): + _name = "se.product.update.mixin" + _description = "Search Engine Product Update Mixin" + + @api.model_create_multi + def create(self, vals_list): + res = super(SEProductUpdateMixin, self).create(vals_list) + res.get_products().shopinvader_mark_to_update() + return res + + def write(self, vals): + needs_update = self.needs_product_update(vals) + if needs_update: + products = self.get_products() + res = super(SEProductUpdateMixin, self).write(vals) + if needs_update: + (products | self.get_products()).shopinvader_mark_to_update() + return res + + def unlink(self): + products = self.get_products() + res = super(SEProductUpdateMixin, self).unlink() + products.shopinvader_mark_to_update() + return res + + def get_products(self): + raise NotImplementedError + + def needs_product_update(self, vals): + return True diff --git a/shopinvader_search_engine_update/readme/CONTEXT.md b/shopinvader_search_engine_update/readme/CONTEXT.md new file mode 100644 index 0000000000..16a365dc96 --- /dev/null +++ b/shopinvader_search_engine_update/readme/CONTEXT.md @@ -0,0 +1,2 @@ +When you update your product data and this information is exposed by the search engine, +you expect to see your changes applied into the search engine as soon as possible. diff --git a/shopinvader_search_engine_update/readme/CONTRIBUTORS.md b/shopinvader_search_engine_update/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a15e3ef244 --- /dev/null +++ b/shopinvader_search_engine_update/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/shopinvader_search_engine_update/readme/DESCRIPTION.md b/shopinvader_search_engine_update/readme/DESCRIPTION.md new file mode 100644 index 0000000000..3fbc0c4e00 --- /dev/null +++ b/shopinvader_search_engine_update/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of the `shopinvader_search_engine` to mark the +information exported to the search engine as to be recomputed when the product data are +updated. diff --git a/shopinvader_search_engine_update/static/description/icon.png b/shopinvader_search_engine_update/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopinvader_search_engine_update/static/description/icon.png differ diff --git a/shopinvader_search_engine_update/tests/__init__.py b/shopinvader_search_engine_update/tests/__init__.py new file mode 100644 index 0000000000..1693032ed6 --- /dev/null +++ b/shopinvader_search_engine_update/tests/__init__.py @@ -0,0 +1 @@ +from . import test_update diff --git a/shopinvader_search_engine_update/tests/common.py b/shopinvader_search_engine_update/tests/common.py new file mode 100644 index 0000000000..f4d99becfe --- /dev/null +++ b/shopinvader_search_engine_update/tests/common.py @@ -0,0 +1,11 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_search_engine.tests.common import TestProductBindingBase + + +class TestProductBindingUpdateBase(TestProductBindingBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_binding.state = "done" diff --git a/shopinvader_search_engine_update/tests/test_update.py b/shopinvader_search_engine_update/tests/test_update.py new file mode 100644 index 0000000000..03e103e5e4 --- /dev/null +++ b/shopinvader_search_engine_update/tests/test_update.py @@ -0,0 +1,14 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from .common import TestProductBindingUpdateBase + + +class TestUpdate(TestProductBindingUpdateBase): + def test_simple_update(self): + self.product.name = "new name" + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_template(self): + self.product.product_tmpl_id.name = "new name" + self.assertEqual(self.product_binding.state, "to_recompute") diff --git a/shopinvader_search_engine_update_image/README.rst b/shopinvader_search_engine_update_image/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/shopinvader_search_engine_update_image/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/shopinvader_search_engine_update_image/__init__.py b/shopinvader_search_engine_update_image/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_search_engine_update_image/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_search_engine_update_image/__manifest__.py b/shopinvader_search_engine_update_image/__manifest__.py new file mode 100644 index 0000000000..93656cafbb --- /dev/null +++ b/shopinvader_search_engine_update_image/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Search Engine Update Image", + "summary": """ + Shopinvader: Mark products linked to an image to be updated when the + image change""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "shopinvader_search_engine_image", + "shopinvader_search_engine_update", + ], + "data": [], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_update_image/models/__init__.py b/shopinvader_search_engine_update_image/models/__init__.py new file mode 100644 index 0000000000..bb7c4093a5 --- /dev/null +++ b/shopinvader_search_engine_update_image/models/__init__.py @@ -0,0 +1 @@ +from . import fs_product_image diff --git a/shopinvader_search_engine_update_image/models/fs_product_image.py b/shopinvader_search_engine_update_image/models/fs_product_image.py new file mode 100644 index 0000000000..755e05efb8 --- /dev/null +++ b/shopinvader_search_engine_update_image/models/fs_product_image.py @@ -0,0 +1,12 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class FsProductImage(models.Model): + _name = "fs.product.image" + _inherit = ["fs.product.image", "se.product.update.mixin"] + + def get_products(self): + return self.mapped("product_tmpl_id") diff --git a/shopinvader_search_engine_update_image/readme/CONTEXT.md b/shopinvader_search_engine_update_image/readme/CONTEXT.md new file mode 100644 index 0000000000..08ad903fb7 --- /dev/null +++ b/shopinvader_search_engine_update_image/readme/CONTEXT.md @@ -0,0 +1,3 @@ +When you update the images associated to a product and this information is exposed by +the search engine, you expect to see your changes applied into the search engine as soon +as possible. diff --git a/shopinvader_search_engine_update_image/readme/CONTRIBUTORS.md b/shopinvader_search_engine_update_image/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a15e3ef244 --- /dev/null +++ b/shopinvader_search_engine_update_image/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/shopinvader_search_engine_update_image/readme/DESCRIPTION.md b/shopinvader_search_engine_update_image/readme/DESCRIPTION.md new file mode 100644 index 0000000000..3095908066 --- /dev/null +++ b/shopinvader_search_engine_update_image/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of the `shopinvader_search_engine_update` and +`shopinvader_search_engine_image` modules to mark the information exported to the search +engine as to be recomputed when the images of a product are updated. diff --git a/shopinvader_search_engine_update_image/static/description/icon.png b/shopinvader_search_engine_update_image/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopinvader_search_engine_update_image/static/description/icon.png differ diff --git a/shopinvader_search_engine_update_image/tests/__init__.py b/shopinvader_search_engine_update_image/tests/__init__.py new file mode 100644 index 0000000000..1693032ed6 --- /dev/null +++ b/shopinvader_search_engine_update_image/tests/__init__.py @@ -0,0 +1 @@ +from . import test_update diff --git a/shopinvader_search_engine_update_image/tests/test_update.py b/shopinvader_search_engine_update_image/tests/test_update.py new file mode 100644 index 0000000000..b71f3d2182 --- /dev/null +++ b/shopinvader_search_engine_update_image/tests/test_update.py @@ -0,0 +1,40 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import base64 + +from odoo.addons.shopinvader_search_engine_image.tests.common import ( + TestSeMultiImageThumbnailCase, +) + + +class TestUpdate(TestSeMultiImageThumbnailCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_binding.state = "done" + cls.new_tag = cls.env["image.tag"].create( + { + "name": "new_tag", + } + ) + + def test_unlink_image(self): + self.product.variant_image_ids.unlink() + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_add_image(self): + self.env["fs.product.image"].create( + { + "sequence": 1, + "product_tmpl_id": self.product.product_tmpl_id.id, + "specific_image": { + "filename": "white2.png", + "content": base64.b64encode(self.white_image), + }, + } + ) + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_image(self): + self.product.variant_image_ids[0].tag_id = self.new_tag + self.assertEqual(self.product_binding.state, "to_recompute") diff --git a/shopinvader_search_engine_update_product_brand/README.rst b/shopinvader_search_engine_update_product_brand/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/shopinvader_search_engine_update_product_brand/__init__.py b/shopinvader_search_engine_update_product_brand/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_search_engine_update_product_brand/__manifest__.py b/shopinvader_search_engine_update_product_brand/__manifest__.py new file mode 100644 index 0000000000..0c328a7eaf --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Search Engine Update Product Brand", + "summary": """ + Shopinvader: Mark brand and product bindings to export on product brand update""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "shopinvader_search_engine_update", + "shopinvader_search_engine_product_brand", + ], + "data": [], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_update_product_brand/models/__init__.py b/shopinvader_search_engine_update_product_brand/models/__init__.py new file mode 100644 index 0000000000..6cb55ac7f7 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/models/__init__.py @@ -0,0 +1 @@ +from . import product_brand diff --git a/shopinvader_search_engine_update_product_brand/models/product_brand.py b/shopinvader_search_engine_update_product_brand/models/product_brand.py new file mode 100644 index 0000000000..abbcf7f27c --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/models/product_brand.py @@ -0,0 +1,21 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProductBrand(models.Model): + _inherit = "product.brand" + + def write(self, vals): + res = super(ProductBrand, self).write(vals) + self.shopinvader_mark_to_update() + return res + + def shopinvader_mark_to_update(self): + res = super(ProductBrand, self).shopinvader_mark_to_update() + self._shopinvader_mark_to_update_associated_products() + return res + + def _shopinvader_mark_to_update_associated_products(self): + self.product_ids.shopinvader_mark_to_update() diff --git a/shopinvader_search_engine_update_product_brand/readme/CONTEXT.md b/shopinvader_search_engine_update_product_brand/readme/CONTEXT.md new file mode 100644 index 0000000000..b26a9952bf --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/readme/CONTEXT.md @@ -0,0 +1,3 @@ +When you update the product brand associated to a product and this information is +exposed by the search engine, you expect to see your changes applied into the search +engine as soon as possible. diff --git a/shopinvader_search_engine_update_product_brand/readme/CONTRIBUTORS.md b/shopinvader_search_engine_update_product_brand/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a15e3ef244 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/shopinvader_search_engine_update_product_brand/readme/DESCRIPTION.md b/shopinvader_search_engine_update_product_brand/readme/DESCRIPTION.md new file mode 100644 index 0000000000..e40b055a12 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of the `shopinvader_search_engine_update` and +`shopinvader_search_engine_product_brand` modules to mark the information exported to +the search engine as to be recomputed when the brand of a product are updated. diff --git a/shopinvader_search_engine_update_product_brand/static/description/icon.png b/shopinvader_search_engine_update_product_brand/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopinvader_search_engine_update_product_brand/static/description/icon.png differ diff --git a/shopinvader_search_engine_update_product_brand/tests/__init__.py b/shopinvader_search_engine_update_product_brand/tests/__init__.py new file mode 100644 index 0000000000..1693032ed6 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/tests/__init__.py @@ -0,0 +1 @@ +from . import test_update diff --git a/shopinvader_search_engine_update_product_brand/tests/common.py b/shopinvader_search_engine_update_product_brand/tests/common.py new file mode 100644 index 0000000000..634f1fb7c3 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/tests/common.py @@ -0,0 +1,27 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_search_engine_update.tests.common import ( + TestProductBindingUpdateBase, +) + + +class TestProductBrandUpdateBase(TestProductBindingUpdateBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.brand = cls.env["product.brand"].create({"name": "brand"}) + cls.brand_index = cls.env["se.index"].create( + { + "name": "brand", + "backend_id": cls.backend.id, + "model_id": cls.env.ref("product_brand.model_product_brand").id, + "serializer_type": "shopinvader_brand_exports", + } + ) + cls.product.product_brand_id = cls.brand + cls.brand_binding = cls.brand._add_to_index(cls.brand_index) + cls.brand_binding.state = "done" + cls.new_brand = cls.env["product.brand"].create({"name": "new brand"}) + cls.new_brand_binding = cls.new_brand._add_to_index(cls.brand_index) + cls.new_brand_binding.state = "done" diff --git a/shopinvader_search_engine_update_product_brand/tests/test_update.py b/shopinvader_search_engine_update_product_brand/tests/test_update.py new file mode 100644 index 0000000000..b6bda6b064 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand/tests/test_update.py @@ -0,0 +1,20 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from .common import TestProductBrandUpdateBase + + +class TestUpdate(TestProductBrandUpdateBase): + def test_update_brand_update_product(self): + self.product.product_brand_id.name = "new brand name" + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_brand_update_brand_binding(self): + self.brand.name = "new brand name" + self.assertEqual(self.brand_binding.state, "to_recompute") + # the product is also marked to recompute + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_brand_field_on_product_update_product(self): + self.product.product_brand_id = self.new_brand + self.assertEqual(self.product_binding.state, "to_recompute") diff --git a/shopinvader_search_engine_update_product_brand_image/README.rst b/shopinvader_search_engine_update_product_brand_image/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/shopinvader_search_engine_update_product_brand_image/__init__.py b/shopinvader_search_engine_update_product_brand_image/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_search_engine_update_product_brand_image/__manifest__.py b/shopinvader_search_engine_update_product_brand_image/__manifest__.py new file mode 100644 index 0000000000..0c0b323e80 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Search Engine Update Product Brand Image", + "summary": """ + Mark brand and product bindings to export on product image brand update""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "shopinvader_search_engine_update", + "shopinvader_search_engine_product_brand_image", + ], + "data": [], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_update_product_brand_image/models/__init__.py b/shopinvader_search_engine_update_product_brand_image/models/__init__.py new file mode 100644 index 0000000000..d119b1d4b1 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/models/__init__.py @@ -0,0 +1 @@ +from . import fs_product_brand_image diff --git a/shopinvader_search_engine_update_product_brand_image/models/fs_product_brand_image.py b/shopinvader_search_engine_update_product_brand_image/models/fs_product_brand_image.py new file mode 100644 index 0000000000..508e37c7e1 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/models/fs_product_brand_image.py @@ -0,0 +1,35 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class FsProductBrandImage(models.Model): + _inherit = "fs.product.brand.image" + + def get_brands(self): + return self.mapped("brand_id") + + @api.model_create_multi + def create(self, vals_list): + res = super(FsProductBrandImage, self).create(vals_list) + res.get_brands().shopinvader_mark_to_update() + return res + + def write(self, vals): + needs_update = self.needs_brand_update(vals) + if needs_update: + products = self.get_brands() + res = super(FsProductBrandImage, self).write(vals) + if needs_update: + (products | self.get_brands()).shopinvader_mark_to_update() + return res + + def unlink(self): + products = self.get_brands() + res = super(FsProductBrandImage, self).unlink() + products.shopinvader_mark_to_update() + return res + + def needs_brand_update(self, vals): + return True diff --git a/shopinvader_search_engine_update_product_brand_image/readme/CONTEXT.md b/shopinvader_search_engine_update_product_brand_image/readme/CONTEXT.md new file mode 100644 index 0000000000..0e49a1b5e2 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/readme/CONTEXT.md @@ -0,0 +1,3 @@ +When you update the image associated to a product brand and this information is exposed +by the search engine on the product and or on a product brand index, you expect to see +your changes applied into the search engine as soon as possible. diff --git a/shopinvader_search_engine_update_product_brand_image/readme/CONTRIBUTORS.md b/shopinvader_search_engine_update_product_brand_image/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a15e3ef244 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/shopinvader_search_engine_update_product_brand_image/readme/DESCRIPTION.md b/shopinvader_search_engine_update_product_brand_image/readme/DESCRIPTION.md new file mode 100644 index 0000000000..8595b4e143 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of the `shopinvader_search_engine_update` and +`shopinvader_search_engine_product_brand_image` modules to mark the information exported +to the search engine as to be recomputed when the images of a product brand are updated. diff --git a/shopinvader_search_engine_update_product_brand_image/static/description/icon.png b/shopinvader_search_engine_update_product_brand_image/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopinvader_search_engine_update_product_brand_image/static/description/icon.png differ diff --git a/shopinvader_search_engine_update_product_brand_image/tests/__init__.py b/shopinvader_search_engine_update_product_brand_image/tests/__init__.py new file mode 100644 index 0000000000..1693032ed6 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/tests/__init__.py @@ -0,0 +1 @@ +from . import test_update diff --git a/shopinvader_search_engine_update_product_brand_image/tests/test_update.py b/shopinvader_search_engine_update_product_brand_image/tests/test_update.py new file mode 100644 index 0000000000..003f51ec10 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_image/tests/test_update.py @@ -0,0 +1,47 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import base64 + +from odoo.addons.shopinvader_search_engine.tests.common import TestProductBindingMixin +from odoo.addons.shopinvader_search_engine_product_brand_image.tests.common import ( + ProductBrandImageCase, +) + + +class TestUpdate(ProductBrandImageCase, TestProductBindingMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + TestProductBindingMixin.setup_records(cls) + cls.product.product_brand_id = cls.brand + cls.product_binding.state = "done" + cls.brand_binding.state = "done" + cls.new_tag = cls.env["image.tag"].create( + { + "name": "new_tag", + } + ) + + def test_unlink_image(self): + self.brand.image_ids.unlink() + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_add_image(self): + self.env["fs.product.brand.image"].create( + { + "sequence": 3, + "brand_id": self.brand.id, + "specific_image": { + "filename": "white2.png", + "content": base64.b64encode(self.white_image), + }, + } + ) + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_image(self): + self.brand.image_ids[0].tag_id = self.new_tag + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") diff --git a/shopinvader_search_engine_update_product_brand_tag/README.rst b/shopinvader_search_engine_update_product_brand_tag/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/shopinvader_search_engine_update_product_brand_tag/__init__.py b/shopinvader_search_engine_update_product_brand_tag/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_search_engine_update_product_brand_tag/__manifest__.py b/shopinvader_search_engine_update_product_brand_tag/__manifest__.py new file mode 100644 index 0000000000..dcb415b41d --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Seach Engine Product Brand Tag", + "summary": """ + Mark brand and product bindings to export on product image tag update""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "shopinvader_search_engine_update_product_brand", + "shopinvader_product_brand_tag", + ], + "data": [], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_update_product_brand_tag/models/__init__.py b/shopinvader_search_engine_update_product_brand_tag/models/__init__.py new file mode 100644 index 0000000000..1f1898fda1 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/models/__init__.py @@ -0,0 +1 @@ +from . import product_brand_tag diff --git a/shopinvader_search_engine_update_product_brand_tag/models/product_brand_tag.py b/shopinvader_search_engine_update_product_brand_tag/models/product_brand_tag.py new file mode 100644 index 0000000000..d526bbff38 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/models/product_brand_tag.py @@ -0,0 +1,24 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProductBrandTag(models.Model): + _inherit = "product.brand.tag" + + @api.model_create_multi + def create(self, vals_list): + res = super(ProductBrandTag, self).create(vals_list) + res.product_brand_ids.shopinvader_mark_to_update() + return res + + def write(self, vals): + res = super(ProductBrandTag, self).write(vals) + if "name" in vals or "product_brand_ids" in vals: + self.product_brand_ids.shopinvader_mark_to_update() + return res + + def unlink(self): + self.product_brand_ids.shopinvader_mark_to_update() + return super(ProductBrandTag, self).unlink() diff --git a/shopinvader_search_engine_update_product_brand_tag/readme/CONTEXT.md b/shopinvader_search_engine_update_product_brand_tag/readme/CONTEXT.md new file mode 100644 index 0000000000..d1cf175b8f --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/readme/CONTEXT.md @@ -0,0 +1,3 @@ +When you update the tag associated to a product brand and this information is exposed by +the search engine on the product and or on a product brand index, you expect to see your +changes applied into the search engine as soon as possible. diff --git a/shopinvader_search_engine_update_product_brand_tag/readme/CONTRIBUTORS.md b/shopinvader_search_engine_update_product_brand_tag/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a15e3ef244 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/shopinvader_search_engine_update_product_brand_tag/readme/DESCRIPTION.md b/shopinvader_search_engine_update_product_brand_tag/readme/DESCRIPTION.md new file mode 100644 index 0000000000..6eae3d67ae --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module extends the functionality of the `shopinvader_product_brand_tag` and +`shopinvader_search_engine_update_product_brand` modules to mark the information +exported to the search engine as to be recomputed when the tag of a product brand is +updated. diff --git a/shopinvader_search_engine_update_product_brand_tag/static/description/icon.png b/shopinvader_search_engine_update_product_brand_tag/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopinvader_search_engine_update_product_brand_tag/static/description/icon.png differ diff --git a/shopinvader_search_engine_update_product_brand_tag/tests/__init__.py b/shopinvader_search_engine_update_product_brand_tag/tests/__init__.py new file mode 100644 index 0000000000..1693032ed6 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/tests/__init__.py @@ -0,0 +1 @@ +from . import test_update diff --git a/shopinvader_search_engine_update_product_brand_tag/tests/test_update.py b/shopinvader_search_engine_update_product_brand_tag/tests/test_update.py new file mode 100644 index 0000000000..6d60b80a54 --- /dev/null +++ b/shopinvader_search_engine_update_product_brand_tag/tests/test_update.py @@ -0,0 +1,45 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_search_engine_update_product_brand.tests.common import ( + TestProductBrandUpdateBase, +) + + +class TestUpdate(TestProductBrandUpdateBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.tag = cls.env["product.brand.tag"].create( + { + "name": "tag", + } + ) + cls.new_tag = cls.env["product.brand.tag"].create( + { + "name": "new_tag", + } + ) + cls.brand.tag_ids = cls.tag + cls.brand_binding.state = "done" + cls.product_binding.state = "done" + + def test_unlink_tag(self): + self.brand.tag_ids.unlink() + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_add_tag(self): + self.brand.tag_ids = self.new_tag + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") + self.brand_binding.state = "done" + self.product_binding.state = "done" + self.tag.product_brand_ids = self.brand + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_tag(self): + self.brand.tag_ids[0].name = "new name" + self.assertEqual(self.brand_binding.state, "to_recompute") + self.assertEqual(self.product_binding.state, "to_recompute") diff --git a/shopinvader_search_engine_update_product_media/README.rst b/shopinvader_search_engine_update_product_media/README.rst new file mode 100644 index 0000000000..38929e8775 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/shopinvader_search_engine_update_product_media/__init__.py b/shopinvader_search_engine_update_product_media/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_search_engine_update_product_media/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_search_engine_update_product_media/__manifest__.py b/shopinvader_search_engine_update_product_media/__manifest__.py new file mode 100644 index 0000000000..17ca2084f5 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Search Engine Update Media", + "summary": """ + Shopinvader: Mark products linked to a media to be updated when the media change""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "shopinvader_search_engine_update", + "shopinvader_search_engine_product_media", + ], + "data": [], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_update_product_media/models/__init__.py b/shopinvader_search_engine_update_product_media/models/__init__.py new file mode 100644 index 0000000000..f31e523df6 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/models/__init__.py @@ -0,0 +1 @@ +from . import fs_product_media diff --git a/shopinvader_search_engine_update_product_media/models/fs_product_media.py b/shopinvader_search_engine_update_product_media/models/fs_product_media.py new file mode 100644 index 0000000000..5b4d1d2ae0 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/models/fs_product_media.py @@ -0,0 +1,12 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class FsProductMedia(models.Model): + _name = "fs.product.media" + _inherit = ["fs.product.media", "se.product.update.mixin"] + + def get_products(self): + return self.mapped("product_tmpl_id") diff --git a/shopinvader_search_engine_update_product_media/readme/CONTEXT.md b/shopinvader_search_engine_update_product_media/readme/CONTEXT.md new file mode 100644 index 0000000000..41ea1775c0 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/readme/CONTEXT.md @@ -0,0 +1,3 @@ +When you update the medias associated to a product and this information is exposed by +the search engine, you expect to see your changes applied into the search engine as soon +as possible. diff --git a/shopinvader_search_engine_update_product_media/readme/CONTRIBUTORS.md b/shopinvader_search_engine_update_product_media/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a15e3ef244 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Laurent Mignon (https://www.acsone.eu) diff --git a/shopinvader_search_engine_update_product_media/readme/DESCRIPTION.md b/shopinvader_search_engine_update_product_media/readme/DESCRIPTION.md new file mode 100644 index 0000000000..d5314a1568 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of the `shopinvader_search_engine_update` and +`shopinvader_search_engine_product_media` modules to mark the information exported to +the search engine as to be recomputed when the medias of a product are updated. diff --git a/shopinvader_search_engine_update_product_media/static/description/icon.png b/shopinvader_search_engine_update_product_media/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/shopinvader_search_engine_update_product_media/static/description/icon.png differ diff --git a/shopinvader_search_engine_update_product_media/tests/__init__.py b/shopinvader_search_engine_update_product_media/tests/__init__.py new file mode 100644 index 0000000000..1693032ed6 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/tests/__init__.py @@ -0,0 +1 @@ +from . import test_update diff --git a/shopinvader_search_engine_update_product_media/tests/test_update.py b/shopinvader_search_engine_update_product_media/tests/test_update.py new file mode 100644 index 0000000000..e48bb810b5 --- /dev/null +++ b/shopinvader_search_engine_update_product_media/tests/test_update.py @@ -0,0 +1,45 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import base64 + +from odoo.addons.shopinvader_search_engine.tests.common import TestProductBindingMixin +from odoo.addons.shopinvader_search_engine_product_media.tests.common import ( + ProductMediaCase, +) + + +class TestUpdate(ProductMediaCase, TestProductBindingMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + TestProductBindingMixin.setup_records(cls) + cls.env["fs.product.media"].create( + { + "product_tmpl_id": cls.product.product_tmpl_id.id, + "media_id": cls.media_c.id, + "sequence": 10, + "link_existing": True, + } + ) + cls.product_binding.state = "done" + + def test_unlink_media(self): + self.product.media_ids.unlink() + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_add_media(self): + self.env["fs.product.media"].create( + { + "product_tmpl_id": self.product.product_tmpl_id.id, + "file": { + "filename": "new.txt", + "content": base64.b64encode(b"new media"), + }, + "media_type_id": self.media_type_b.id, + } + ) + self.assertEqual(self.product_binding.state, "to_recompute") + + def test_update_media(self): + self.product.media_ids[0].media_type_id = self.media_type_a.id + self.assertEqual(self.product_binding.state, "to_recompute")