From c1cb7f7007837974612e8d1b30ac2431c4b32d6b Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Fri, 26 Jan 2024 16:25:35 +0100 Subject: [PATCH] [ADD] shopinvader_search_engine_product_multi_price --- ...pinvader_search_engine_product_multi_price | 1 + .../setup.py | 6 + .../README.rst | 71 +++ .../__init__.py | 2 + .../__manifest__.py | 16 + .../models/__init__.py | 3 + .../models/product_product.py | 24 + .../models/se_backend.py | 11 + .../models/se_index.py | 20 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../readme/USAGE.rst | 1 + .../schemas/__init__.py | 1 + .../schemas/product.py | 23 + .../static/description/index.html | 428 ++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_product_binding.py | 51 +++ .../views/se_backend.xml | 19 + .../views/se_index.xml | 22 + 19 files changed, 703 insertions(+) create mode 120000 setup/shopinvader_search_engine_product_multi_price/odoo/addons/shopinvader_search_engine_product_multi_price create mode 100644 setup/shopinvader_search_engine_product_multi_price/setup.py create mode 100644 shopinvader_search_engine_product_multi_price/README.rst create mode 100644 shopinvader_search_engine_product_multi_price/__init__.py create mode 100644 shopinvader_search_engine_product_multi_price/__manifest__.py create mode 100644 shopinvader_search_engine_product_multi_price/models/__init__.py create mode 100644 shopinvader_search_engine_product_multi_price/models/product_product.py create mode 100644 shopinvader_search_engine_product_multi_price/models/se_backend.py create mode 100644 shopinvader_search_engine_product_multi_price/models/se_index.py create mode 100644 shopinvader_search_engine_product_multi_price/readme/CONTRIBUTORS.rst create mode 100644 shopinvader_search_engine_product_multi_price/readme/DESCRIPTION.rst create mode 100644 shopinvader_search_engine_product_multi_price/readme/USAGE.rst create mode 100644 shopinvader_search_engine_product_multi_price/schemas/__init__.py create mode 100644 shopinvader_search_engine_product_multi_price/schemas/product.py create mode 100644 shopinvader_search_engine_product_multi_price/static/description/index.html create mode 100644 shopinvader_search_engine_product_multi_price/tests/__init__.py create mode 100644 shopinvader_search_engine_product_multi_price/tests/test_product_binding.py create mode 100644 shopinvader_search_engine_product_multi_price/views/se_backend.xml create mode 100644 shopinvader_search_engine_product_multi_price/views/se_index.xml diff --git a/setup/shopinvader_search_engine_product_multi_price/odoo/addons/shopinvader_search_engine_product_multi_price b/setup/shopinvader_search_engine_product_multi_price/odoo/addons/shopinvader_search_engine_product_multi_price new file mode 120000 index 0000000000..31576bd8e8 --- /dev/null +++ b/setup/shopinvader_search_engine_product_multi_price/odoo/addons/shopinvader_search_engine_product_multi_price @@ -0,0 +1 @@ +../../../../shopinvader_search_engine_product_multi_price \ No newline at end of file diff --git a/setup/shopinvader_search_engine_product_multi_price/setup.py b/setup/shopinvader_search_engine_product_multi_price/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_search_engine_product_multi_price/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopinvader_search_engine_product_multi_price/README.rst b/shopinvader_search_engine_product_multi_price/README.rst new file mode 100644 index 0000000000..470af3c406 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/README.rst @@ -0,0 +1,71 @@ +============================================= +Shopinvader Search Engine Product Multi Price +============================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:05a73ae4cb7fb4ac83a7800fcb3c61a917f562b886794ae028384f1e1675f201 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github + :target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_search_engine_product_multi_price + :alt: shopinvader/odoo-shopinvader + +|badge1| |badge2| |badge3| + +Adds prices to the export of products for Shopinvader. +One price is exported per pricelist set on the index. + +.. 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 +===== + +Set pricelists per index or on the search engine backend to apply globally. + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Quentin Groulard + +Maintainers +~~~~~~~~~~~ + +This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. + +You are welcome to contribute. diff --git a/shopinvader_search_engine_product_multi_price/__init__.py b/shopinvader_search_engine_product_multi_price/__init__.py new file mode 100644 index 0000000000..106fc57265 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import schemas diff --git a/shopinvader_search_engine_product_multi_price/__manifest__.py b/shopinvader_search_engine_product_multi_price/__manifest__.py new file mode 100644 index 0000000000..5551eebb05 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Search Engine Product Multi Price", + "summary": "Add the export of multiple prices for Shopinvader", + "version": "16.0.1.0.0", + "category": "e-commerce", + "license": "AGPL-3", + "author": "ACSONE SA/NV", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": ["product_get_price_helper", "shopinvader_search_engine"], + "data": ["views/se_backend.xml", "views/se_index.xml"], + "demo": [], + "development_status": "Alpha", +} diff --git a/shopinvader_search_engine_product_multi_price/models/__init__.py b/shopinvader_search_engine_product_multi_price/models/__init__.py new file mode 100644 index 0000000000..f53e7d2a4c --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_product +from . import se_backend +from . import se_index diff --git a/shopinvader_search_engine_product_multi_price/models/product_product.py b/shopinvader_search_engine_product_multi_price/models/product_product.py new file mode 100644 index 0000000000..e9b1b6d345 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/models/product_product.py @@ -0,0 +1,24 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + shopinvader_price_by_pricelist = fields.Json( + compute="_compute_shopinvader_price_by_pricelist" + ) + + @api.depends_context("index_id") + def _compute_shopinvader_price_by_pricelist(self): + index_id = self.env.context.get("index_id", False) + index = self.env["se.index"].browse(index_id) + for product in self: + prices = {} + if index_id: + for pricelist in index._get_pricelists(): + price = product._get_price(pricelist=pricelist) + prices.update({str(pricelist.id): price}) + product.shopinvader_price_by_pricelist = prices diff --git a/shopinvader_search_engine_product_multi_price/models/se_backend.py b/shopinvader_search_engine_product_multi_price/models/se_backend.py new file mode 100644 index 0000000000..302a9d2434 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/models/se_backend.py @@ -0,0 +1,11 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SeBackend(models.Model): + + _inherit = "se.backend" + + pricelist_ids = fields.Many2many("product.pricelist", string="Pricelists") diff --git a/shopinvader_search_engine_product_multi_price/models/se_index.py b/shopinvader_search_engine_product_multi_price/models/se_index.py new file mode 100644 index 0000000000..23fcc8f13b --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/models/se_index.py @@ -0,0 +1,20 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SeIndex(models.Model): + + _inherit = "se.index" + + pricelist_ids = fields.Many2many( + comodel_name="product.pricelist", + string="Pricelists", + help="Define pricelists for price computation, " + "keep empty to take configuration from the backend", + ) + + def _get_pricelists(self): + self.ensure_one() + return self.pricelist_ids or self.backend_id.pricelist_ids diff --git a/shopinvader_search_engine_product_multi_price/readme/CONTRIBUTORS.rst b/shopinvader_search_engine_product_multi_price/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..5914f5529e --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Quentin Groulard diff --git a/shopinvader_search_engine_product_multi_price/readme/DESCRIPTION.rst b/shopinvader_search_engine_product_multi_price/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..99bc4318d5 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Adds prices to the export of products for Shopinvader. +One price is exported per pricelist set on the index. diff --git a/shopinvader_search_engine_product_multi_price/readme/USAGE.rst b/shopinvader_search_engine_product_multi_price/readme/USAGE.rst new file mode 100644 index 0000000000..24074073bd --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/readme/USAGE.rst @@ -0,0 +1 @@ +Set pricelists per index or on the search engine backend to apply globally. diff --git a/shopinvader_search_engine_product_multi_price/schemas/__init__.py b/shopinvader_search_engine_product_multi_price/schemas/__init__.py new file mode 100644 index 0000000000..c7e3359914 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/schemas/__init__.py @@ -0,0 +1 @@ +from .product import ProductPriceInfo, ProductProduct diff --git a/shopinvader_search_engine_product_multi_price/schemas/product.py b/shopinvader_search_engine_product_multi_price/schemas/product.py new file mode 100644 index 0000000000..f129ec37a8 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/schemas/product.py @@ -0,0 +1,23 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from extendable_pydantic import StrictExtendableBaseModel + +from odoo.addons.shopinvader_product.schemas import ProductProduct as BaseProduct + + +class ProductPriceInfo(StrictExtendableBaseModel): + value: float = 0 + tax_included: bool = False + original_value: float = 0 + discount: float = 0 + + +class ProductProduct(BaseProduct, extends=True): + price_by_pricelist: dict[str, ProductPriceInfo] = {} + + @classmethod + def from_product_product(cls, odoo_rec): + obj = super().from_product_product(odoo_rec) + obj.price_by_pricelist = odoo_rec.shopinvader_price_by_pricelist or {} + return obj diff --git a/shopinvader_search_engine_product_multi_price/static/description/index.html b/shopinvader_search_engine_product_multi_price/static/description/index.html new file mode 100644 index 0000000000..eb32bf5280 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +Shopinvader Search Engine Product Multi Price + + + +
+

Shopinvader Search Engine Product Multi Price

+ + +

Alpha License: AGPL-3 shopinvader/odoo-shopinvader

+

Adds prices to the export of products for Shopinvader. +One price is exported per pricelist set on the index.

+
+

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

+

Set pricelists per index or on the search engine backend to apply globally.

+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the shopinvader/odoo-shopinvader project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/shopinvader_search_engine_product_multi_price/tests/__init__.py b/shopinvader_search_engine_product_multi_price/tests/__init__.py new file mode 100644 index 0000000000..76c6a637ed --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_binding diff --git a/shopinvader_search_engine_product_multi_price/tests/test_product_binding.py b/shopinvader_search_engine_product_multi_price/tests/test_product_binding.py new file mode 100644 index 0000000000..8a2002edb4 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/tests/test_product_binding.py @@ -0,0 +1,51 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_search_engine.tests.common import TestBindingIndexBase + + +class TestProductBinding(TestBindingIndexBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.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 = cls.env.ref("product.product_product_4b") + cls.product_binding = cls.product._add_to_index(cls.index) + + def test_binding_prices_no_pricelist(self): + self.product_binding.recompute_json() + data = self.product_binding.data + self.assertEqual(len(data["price_by_pricelist"]), 0) + + def test_binding_price_by_pricelist(self): + pricelist_1 = self.env.ref("product.list0") + pricelist_2 = self.env.ref("product_get_price_helper.pricelist_1") + self.index.backend_id.pricelist_ids = [(6, 0, (pricelist_1 | pricelist_2).ids)] + self.product_binding.recompute_json() + data = self.product_binding.data + self.assertEqual(len(data["price_by_pricelist"]), 1) + self.assertEqual( + data["price_by_pricelist"][str(pricelist_1.id)], + { + "value": 750.0, + "tax_included": False, + "discount": 0.0, + "original_value": 750.0, + }, + ) + self.assertEqual( + data["price_by_pricelist"][str(pricelist_2.id)], + { + "value": 600.0, + "tax_included": False, + "discount": 0.0, + "original_value": 600.0, + }, + ) diff --git a/shopinvader_search_engine_product_multi_price/views/se_backend.xml b/shopinvader_search_engine_product_multi_price/views/se_backend.xml new file mode 100644 index 0000000000..aa9d441c03 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/views/se_backend.xml @@ -0,0 +1,19 @@ + + + + + + se.backend.form (in shopinvader_search_engine_product_multi_price) + se.backend + + + + + + + + + diff --git a/shopinvader_search_engine_product_multi_price/views/se_index.xml b/shopinvader_search_engine_product_multi_price/views/se_index.xml new file mode 100644 index 0000000000..96144abae1 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/views/se_index.xml @@ -0,0 +1,22 @@ + + + + + + se.index.form (in shopinvader_search_engine_product_multi_price) + se.index + + + + + + + + +