diff --git a/pos_bypass_global_discount/README.rst b/pos_bypass_global_discount/README.rst new file mode 100644 index 0000000000..28d7f12cda --- /dev/null +++ b/pos_bypass_global_discount/README.rst @@ -0,0 +1,79 @@ +========================== +POS Bypass Global Discount +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5f77c0acfa94c44cf02d9d34e69c09a5f8258fc46c7dd93c51c5bcce55f230ff + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/16.0/pos_bypass_global_discount + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_bypass_global_discount + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Field `bypass_global_discount` was introduced in [base_global_discount](https://github.com/OCA/server-backend/tree/16.0/base_global_discount). It's used to exclude some products from global discounts calculations. +This module is meant to be installed as a companion to `sale_global_discount`. It makes sure the POS will also honors the `bypass_global_discount` field when user inputs a Discount at the Order level. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* `Camptocamp `_ + + * Tri Doan + +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/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_bypass_global_discount/__init__.py b/pos_bypass_global_discount/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_bypass_global_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_bypass_global_discount/__manifest__.py b/pos_bypass_global_discount/__manifest__.py new file mode 100644 index 0000000000..c44a34d8b7 --- /dev/null +++ b/pos_bypass_global_discount/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2024 Camptocamp (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "POS Bypass Global Discount", + "summary": "", + "version": "16.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "category": "Point of Sale", + "depends": ["pos_discount", "pos_loyalty", "sale_global_discount"], + "installable": True, + "assets": { + "point_of_sale.assets": [ + "pos_bypass_global_discount/static/src/js/**/*.js", + ], + "web.assets_tests": [ + "pos_bypass_global_discount/static/src/tours/**/*", + ], + }, +} diff --git a/pos_bypass_global_discount/models/__init__.py b/pos_bypass_global_discount/models/__init__.py new file mode 100644 index 0000000000..f7116e3d45 --- /dev/null +++ b/pos_bypass_global_discount/models/__init__.py @@ -0,0 +1 @@ +from . import pos_session diff --git a/pos_bypass_global_discount/models/pos_session.py b/pos_bypass_global_discount/models/pos_session.py new file mode 100644 index 0000000000..e26802d2f4 --- /dev/null +++ b/pos_bypass_global_discount/models/pos_session.py @@ -0,0 +1,13 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class POSSession(models.Model): + _inherit = "pos.session" + + def _loader_params_product_product(self): + params = super()._loader_params_product_product() + if "search_params" in params and "fields" in params["search_params"]: + params["search_params"]["fields"].append("bypass_global_discount") + return params diff --git a/pos_bypass_global_discount/readme/CONTRIBUTORS.rst b/pos_bypass_global_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..b4bdca8a7c --- /dev/null +++ b/pos_bypass_global_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Camptocamp `_ + + * Tri Doan diff --git a/pos_bypass_global_discount/readme/DESCRIPTION.rst b/pos_bypass_global_discount/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..e34cc239b1 --- /dev/null +++ b/pos_bypass_global_discount/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Field `bypass_global_discount` was introduced in [base_global_discount](https://github.com/OCA/server-backend/tree/16.0/base_global_discount). It's used to exclude some products from global discounts calculations. +This module is meant to be installed as a companion to `sale_global_discount`. It makes sure the POS will also honors the `bypass_global_discount` field when user inputs a Discount at the Order level. diff --git a/pos_bypass_global_discount/static/description/index.html b/pos_bypass_global_discount/static/description/index.html new file mode 100644 index 0000000000..35792e195f --- /dev/null +++ b/pos_bypass_global_discount/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +POS Bypass Global Discount + + + +
+

POS Bypass Global Discount

+ + +

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

+

Field bypass_global_discount was introduced in [base_global_discount](https://github.com/OCA/server-backend/tree/16.0/base_global_discount). It’s used to exclude some products from global discounts calculations. +This module is meant to be installed as a companion to sale_global_discount. It makes sure the POS will also honors the bypass_global_discount field when user inputs a Discount at the Order level.

+

Table of contents

+ +
+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

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/pos project on GitHub.

+

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

+
+
+
+ + diff --git a/pos_bypass_global_discount/static/src/js/models.js b/pos_bypass_global_discount/static/src/js/models.js new file mode 100644 index 0000000000..c814db7bc8 --- /dev/null +++ b/pos_bypass_global_discount/static/src/js/models.js @@ -0,0 +1,15 @@ +odoo.define("pos_bypass_global_discount.models", function (require) { + "use strict"; + + const {Orderline} = require("point_of_sale.models"); + const Registries = require("point_of_sale.Registries"); + + const PosBypassDiscountOrderline = (Orderline) => + class PosBypassDiscountOrderline extends Orderline { + isGlobalDiscountApplicable() { + const res = super.isGlobalDiscountApplicable(); + return !this.product.bypass_global_discount && res; + } + }; + Registries.Model.extend(Orderline, PosBypassDiscountOrderline); +}); diff --git a/pos_bypass_global_discount/static/src/tours/PosBypassGlobalDiscount.esm.js b/pos_bypass_global_discount/static/src/tours/PosBypassGlobalDiscount.esm.js new file mode 100644 index 0000000000..43f6b6b5fa --- /dev/null +++ b/pos_bypass_global_discount/static/src/tours/PosBypassGlobalDiscount.esm.js @@ -0,0 +1,20 @@ +/** @odoo-module **/ +import {PosLoyalty} from "pos_loyalty.tour.PosCouponTourMethods"; +import {ProductScreen} from "point_of_sale.tour.ProductScreenTourMethods"; +import {getSteps, startSteps} from "point_of_sale.tour.utils"; +import Tour from "web_tour.tour"; + +startSteps(); +ProductScreen.do.clickHomeCategory(); +ProductScreen.do.confirmOpeningPopup(); +ProductScreen.exec.addOrderline("Product 1", "1.00", "100"); +PosLoyalty.do.clickDiscountButton(); +PosLoyalty.do.clickConfirmButton(); +ProductScreen.check.totalAmountIs("100.00"); +ProductScreen.exec.addOrderline("Product 2", "1.00", "100"); +PosLoyalty.do.clickDiscountButton(); +PosLoyalty.do.clickConfirmButton(); +// Total = Product 1 + Product 2 - 10% (Product 2) +ProductScreen.check.totalAmountIs("190.00"); + +Tour.register("PosBypassGlobalDiscount", {test: true, url: "/pos/web"}, getSteps()); diff --git a/pos_bypass_global_discount/tests/__init__.py b/pos_bypass_global_discount/tests/__init__.py new file mode 100644 index 0000000000..3a7f351b4c --- /dev/null +++ b/pos_bypass_global_discount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_bypass_global_discount diff --git a/pos_bypass_global_discount/tests/test_bypass_global_discount.py b/pos_bypass_global_discount/tests/test_bypass_global_discount.py new file mode 100644 index 0000000000..d9a3c4ef83 --- /dev/null +++ b/pos_bypass_global_discount/tests/test_bypass_global_discount.py @@ -0,0 +1,66 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import tagged + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT +from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon + + +@tagged("post_install", "-at_install") +class TestPosBypassGlobalDiscount(TestPointOfSaleHttpCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env["base"].with_context(**DISABLED_MAIL_CONTEXT).env + + def test_bypass_global_discount(self): + # this benefits the tour + # because the DiscountButton is hide after the module is installed + if self.env["ir.module.module"].search( + [("name", "=", "pos_minimize_menu"), ("state", "=", "installed")] + ): + self.main_pos_config.write({"iface_important_buttons": "DiscountButton"}) + + self.discount_product = self.env["product.product"].create( + { + "name": "Discount Product", + "type": "service", + "list_price": 0, + "available_in_pos": True, + "taxes_id": False, + } + ) + self.main_pos_config.write( + { + "module_pos_discount": True, + "discount_product_id": self.discount_product.id, + "discount_pc": 10, + } + ) + self.product01 = self.env["product.product"].create( + { + "name": "Product 1", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "bypass_global_discount": True, + "taxes_id": False, + } + ) + self.product02 = self.env["product.product"].create( + { + "name": "Product 2", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "bypass_global_discount": False, + "taxes_id": False, + } + ) + self.main_pos_config.open_ui() + self.start_tour( + "/pos/web?config_id=%d" % self.main_pos_config.id, + "PosBypassGlobalDiscount", + login="accountman", + ) diff --git a/setup/pos_bypass_global_discount/odoo/addons/pos_bypass_global_discount b/setup/pos_bypass_global_discount/odoo/addons/pos_bypass_global_discount new file mode 120000 index 0000000000..fb9080eeec --- /dev/null +++ b/setup/pos_bypass_global_discount/odoo/addons/pos_bypass_global_discount @@ -0,0 +1 @@ +../../../../pos_bypass_global_discount \ No newline at end of file diff --git a/setup/pos_bypass_global_discount/setup.py b/setup/pos_bypass_global_discount/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_bypass_global_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)