From c08d55af41942ecf156a3cbc2db0e2cfb9352453 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Mon, 18 Nov 2024 15:44:33 +0100 Subject: [PATCH] [ADD] website_sale_product_pricelist_alternative --- ...website_sale_product_pricelist_alternative | 1 + .../setup.py | 6 + .../README.rst | 79 ++++ .../__init__.py | 1 + .../__manifest__.py | 20 + .../models/__init__.py | 1 + .../models/product_template.py | 71 +++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 2 + .../static/description/index.html | 425 ++++++++++++++++++ .../tests/__init__.py | 1 + ...site_sale_product_pricelist_alternative.py | 42 ++ 13 files changed, 651 insertions(+) create mode 120000 setup/website_sale_product_pricelist_alternative/odoo/addons/website_sale_product_pricelist_alternative create mode 100644 setup/website_sale_product_pricelist_alternative/setup.py create mode 100644 website_sale_product_pricelist_alternative/README.rst create mode 100644 website_sale_product_pricelist_alternative/__init__.py create mode 100644 website_sale_product_pricelist_alternative/__manifest__.py create mode 100644 website_sale_product_pricelist_alternative/models/__init__.py create mode 100644 website_sale_product_pricelist_alternative/models/product_template.py create mode 100644 website_sale_product_pricelist_alternative/readme/CONTRIBUTORS.rst create mode 100644 website_sale_product_pricelist_alternative/readme/DESCRIPTION.rst create mode 100644 website_sale_product_pricelist_alternative/readme/USAGE.rst create mode 100644 website_sale_product_pricelist_alternative/static/description/index.html create mode 100644 website_sale_product_pricelist_alternative/tests/__init__.py create mode 100644 website_sale_product_pricelist_alternative/tests/test_website_sale_product_pricelist_alternative.py diff --git a/setup/website_sale_product_pricelist_alternative/odoo/addons/website_sale_product_pricelist_alternative b/setup/website_sale_product_pricelist_alternative/odoo/addons/website_sale_product_pricelist_alternative new file mode 120000 index 0000000000..616a151f0f --- /dev/null +++ b/setup/website_sale_product_pricelist_alternative/odoo/addons/website_sale_product_pricelist_alternative @@ -0,0 +1 @@ +../../../../website_sale_product_pricelist_alternative \ No newline at end of file diff --git a/setup/website_sale_product_pricelist_alternative/setup.py b/setup/website_sale_product_pricelist_alternative/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_product_pricelist_alternative/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_product_pricelist_alternative/README.rst b/website_sale_product_pricelist_alternative/README.rst new file mode 100644 index 0000000000..e0acc34c69 --- /dev/null +++ b/website_sale_product_pricelist_alternative/README.rst @@ -0,0 +1,79 @@ +========================================== +Website Sale Product Pricelist Alternative +========================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/16.0/website_sale_product_pricelist_alternative + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-website_sale_product_pricelist_alternative + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/website&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Based on `product_pricelist_alternative` (https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_alternative), it allows you to show in the website alternative vs original product prices. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In product pricelist select discount policy as `Show public price and discount to the customer`. +In the pricelist used in the website, you can set the alternative pricelist with the discounted price. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Telmo Santos + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_product_pricelist_alternative/__init__.py b/website_sale_product_pricelist_alternative/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/website_sale_product_pricelist_alternative/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/website_sale_product_pricelist_alternative/__manifest__.py b/website_sale_product_pricelist_alternative/__manifest__.py new file mode 100644 index 0000000000..9e41545f53 --- /dev/null +++ b/website_sale_product_pricelist_alternative/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Camptocamp (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Website Sale Product Pricelist Alternative", + "version": "16.0.1.0.0", + "development_status": "Beta", + "category": "Website", + "summary": "Show product alternative price versus original price on website cart", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/website", + "license": "AGPL-3", + "depends": [ + "website_sale", + "product_pricelist_alternative", + ], + "data": [], + "installable": True, + "auto_install": False, +} diff --git a/website_sale_product_pricelist_alternative/models/__init__.py b/website_sale_product_pricelist_alternative/models/__init__.py new file mode 100644 index 0000000000..e8fa8f6bf1 --- /dev/null +++ b/website_sale_product_pricelist_alternative/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/website_sale_product_pricelist_alternative/models/product_template.py b/website_sale_product_pricelist_alternative/models/product_template.py new file mode 100644 index 0000000000..cb84bb998c --- /dev/null +++ b/website_sale_product_pricelist_alternative/models/product_template.py @@ -0,0 +1,71 @@ +# Copyright 2024 Camptocamp (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def _get_sales_prices(self, pricelist): + if ( + pricelist + and pricelist.discount_policy == "without_discount" + and self.env.context.get("website_id") + ): + pricelist = pricelist.with_context(skip_alternative_pricelist=True) + res = super()._get_sales_prices(pricelist) + for product_id in res: + res[product_id]["base_price"] = res[product_id]["price_reduce"] + pricelist = pricelist.with_context(skip_alternative_pricelist=False) + product = self.env["product.template"].browse(product_id) + res[product_id]["price_reduce"] = pricelist._get_product_price( + product, 1.0 + ) + return res + return super()._get_sales_prices(pricelist) + + def _get_combination_info( + self, + combination=False, + product_id=False, + add_qty=1, + pricelist=False, + parent_combination=False, + only_template=False, + ): + if ( + pricelist + and pricelist.discount_policy == "without_discount" + and self.env.context.get("website_id") + ): + # Compute original price + pricelist = pricelist.with_context(skip_alternative_pricelist=True) + combination_info = super(ProductTemplate, self)._get_combination_info( + combination, + product_id, + add_qty, + pricelist, + parent_combination, + only_template, + ) + combination_info["list_price"] = combination_info["price"] + combination_info["base_price"] = combination_info["price"] + # Compute alternative price + pricelist = pricelist.with_context(skip_alternative_pricelist=False) + product = self.env["product.product"].browse(combination_info["product_id"]) + combination_info["price"] = pricelist._get_product_price( + product, quantity=self.env.context.get("quantity", add_qty) + ) + combination_info["has_discounted_price"] = ( + pricelist.currency_id.compare_amounts(combination_info["list_price"], combination_info["price"]) == 1 + ) + return combination_info + return super()._get_combination_info( + combination, + product_id, + add_qty, + pricelist, + parent_combination, + only_template, + ) diff --git a/website_sale_product_pricelist_alternative/readme/CONTRIBUTORS.rst b/website_sale_product_pricelist_alternative/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..8ed3aebaca --- /dev/null +++ b/website_sale_product_pricelist_alternative/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Telmo Santos diff --git a/website_sale_product_pricelist_alternative/readme/DESCRIPTION.rst b/website_sale_product_pricelist_alternative/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..ff0356bc24 --- /dev/null +++ b/website_sale_product_pricelist_alternative/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Based on `product_pricelist_alternative` (https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_alternative), it allows you to show in the website alternative vs original product prices. diff --git a/website_sale_product_pricelist_alternative/readme/USAGE.rst b/website_sale_product_pricelist_alternative/readme/USAGE.rst new file mode 100644 index 0000000000..a66aee1969 --- /dev/null +++ b/website_sale_product_pricelist_alternative/readme/USAGE.rst @@ -0,0 +1,2 @@ +In product pricelist select discount policy as `Show public price and discount to the customer`. +In the pricelist used in the website, you can set the alternative pricelist with the discounted price. \ No newline at end of file diff --git a/website_sale_product_pricelist_alternative/static/description/index.html b/website_sale_product_pricelist_alternative/static/description/index.html new file mode 100644 index 0000000000..858e5e08fe --- /dev/null +++ b/website_sale_product_pricelist_alternative/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +Website Sale Product Pricelist Alternative + + + +
+

Website Sale Product Pricelist Alternative

+ + +

Beta License: AGPL-3 OCA/website Translate me on Weblate Try me on Runboat

+

Based on product_pricelist_alternative (https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_alternative), it allows you to show in the website alternative vs original product prices.

+

Table of contents

+ +
+

Usage

+

In product pricelist select discount policy as Show public price and discount to the customer. +In the pricelist used in the website, you can set the alternative pricelist with the discounted price.

+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/website project on GitHub.

+

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

+
+
+
+ + diff --git a/website_sale_product_pricelist_alternative/tests/__init__.py b/website_sale_product_pricelist_alternative/tests/__init__.py new file mode 100644 index 0000000000..e223af574c --- /dev/null +++ b/website_sale_product_pricelist_alternative/tests/__init__.py @@ -0,0 +1 @@ +from . import test_website_sale_product_pricelist_alternative diff --git a/website_sale_product_pricelist_alternative/tests/test_website_sale_product_pricelist_alternative.py b/website_sale_product_pricelist_alternative/tests/test_website_sale_product_pricelist_alternative.py new file mode 100644 index 0000000000..cb972d83e7 --- /dev/null +++ b/website_sale_product_pricelist_alternative/tests/test_website_sale_product_pricelist_alternative.py @@ -0,0 +1,42 @@ +# Copyright 2024 Camptocamp (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import Command + +from odoo.addons.product_pricelist_alternative.tests.common import ( + CommonProductPricelistAlternative, +) + + +class TestWebsiteSaleProductPricelistAlternative(CommonProductPricelistAlternative): + def test_get_combination_info(self): + # Setup website. + website = self.env["website"].create( + { + "name": "Test website", + "company_id": self.env.company.id, + "user_id": self.env.user.id, + "pricelist_ids": [Command.set(self.pricelist01.ids)], + } + ) + # Without discount policy. + self.pricelist01.discount_policy = "without_discount" + datacard = self.datacard.product_tmpl_id.with_context(website_id=website.id) + combination_info = datacard._get_combination_info(pricelist=self.pricelist01) + self.assertEqual(combination_info["list_price"], 70.0) + self.assertEqual(combination_info["price"], 70.0) + self.assertFalse(combination_info["has_discounted_price"]) + res = datacard._get_sales_prices(pricelist=self.pricelist01) + self.assertEqual(res[datacard.id]["base_price"], 70.0) + self.assertEqual(res[datacard.id]["price_reduce"], 70.0) + + usb_adapter = self.usb_adapter.product_tmpl_id.with_context( + website_id=website.id + ) + combination_info = usb_adapter._get_combination_info(pricelist=self.pricelist01) + self.assertEqual(combination_info["list_price"], 95.0) + self.assertEqual(combination_info["price"], 70.0) + self.assertTrue(combination_info["has_discounted_price"]) + res = usb_adapter._get_sales_prices(pricelist=self.pricelist01) + self.assertEqual(res[usb_adapter.id]["base_price"], 95.0) + self.assertEqual(res[usb_adapter.id]["price_reduce"], 70.0)