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..fc9f60acf5 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/README.rst @@ -0,0 +1,72 @@ +============================================= +Shopinvader Search Engine Product Multi Price +============================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:15618ad98952080455ec267d53acf6cab531be0a4b0be9f9f642f4a8c5755de7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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, plus a default price +computed without pricelist. + +.. 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 gloabally. + +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..071e3754f8 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/models/product_product.py @@ -0,0 +1,22 @@ +# 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_prices = fields.Json(compute="_compute_shopinvader_prices") + + @api.depends_context("index_id") + def _compute_shopinvader_prices(self): + index_id = self.env.context.get("index_id", False) + index = self.env["se.index"].browse(index_id) + for product in self: + prices = {"default": product._get_price()} + if index_id: + for pricelist in index._get_pricelists(): + price = product._get_price(pricelist=pricelist) + prices.update({f"{pricelist.id}": price}) + product.shopinvader_prices = 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..3a91fc0d35 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Adds prices to the export of products for Shopinvader. +One price is exported per pricelist set on the index, plus a default price +computed without pricelist. 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..14b42d8368 --- /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 gloabally. 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..42bee9171b --- /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): + prices: dict[str, ProductPriceInfo] = {} + + @classmethod + def from_product_product(cls, odoo_rec): + obj = super().from_product_product(odoo_rec) + obj.prices = odoo_rec.shopinvader_prices 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..d6c6fc970b --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +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, plus a default price +computed without pricelist.

+
+

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 gloabally.

+
+
+

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..3ba0275f38 --- /dev/null +++ b/shopinvader_search_engine_product_multi_price/tests/test_product_binding.py @@ -0,0 +1,59 @@ +# 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["prices"]), 1) + self.assertEqual( + data["prices"]["default"], + { + "value": 750.0, + "tax_included": False, + "discount": 0.0, + "original_value": 750.0, + }, + ) + + def test_binding_prices_pricelist(self): + pricelist = self.env.ref("product_get_price_helper.pricelist_1") + self.index.backend_id.pricelist_ids = [(6, 0, pricelist.ids)] + self.product_binding.recompute_json() + data = self.product_binding.data + self.assertEqual(len(data["prices"]), 2) + self.assertEqual( + data["prices"]["default"], + { + "value": 750.0, + "tax_included": False, + "discount": 0.0, + "original_value": 750.0, + }, + ) + self.assertEqual( + data["prices"][f"{pricelist.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 + + + + + + + + +