From 091fb348235e28e81facfa5b59a5c64b87edf531 Mon Sep 17 00:00:00 2001 From: trisdoan Date: Fri, 5 Jul 2024 18:11:11 +0700 Subject: [PATCH] [ADD] pos_loyalty_exclude --- pos_loyalty_exclude/README.rst | 79 ++++ pos_loyalty_exclude/__init__.py | 1 + pos_loyalty_exclude/__manifest__.py | 20 + pos_loyalty_exclude/models/__init__.py | 1 + pos_loyalty_exclude/models/loyalty_rule.py | 40 ++ pos_loyalty_exclude/readme/CONTRIBUTORS.rst | 3 + pos_loyalty_exclude/readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 427 ++++++++++++++++++ .../src/tours/PosLoyaltyExcludeTour.esm.js | 24 + pos_loyalty_exclude/tests/__init__.py | 1 + .../tests/test_pos_loyalty_exclude.py | 86 ++++ .../odoo/addons/pos_loyalty_exclude | 1 + setup/pos_loyalty_exclude/setup.py | 6 + 13 files changed, 691 insertions(+) create mode 100644 pos_loyalty_exclude/README.rst create mode 100644 pos_loyalty_exclude/__init__.py create mode 100644 pos_loyalty_exclude/__manifest__.py create mode 100644 pos_loyalty_exclude/models/__init__.py create mode 100644 pos_loyalty_exclude/models/loyalty_rule.py create mode 100644 pos_loyalty_exclude/readme/CONTRIBUTORS.rst create mode 100644 pos_loyalty_exclude/readme/DESCRIPTION.rst create mode 100644 pos_loyalty_exclude/static/description/index.html create mode 100644 pos_loyalty_exclude/static/src/tours/PosLoyaltyExcludeTour.esm.js create mode 100644 pos_loyalty_exclude/tests/__init__.py create mode 100644 pos_loyalty_exclude/tests/test_pos_loyalty_exclude.py create mode 120000 setup/pos_loyalty_exclude/odoo/addons/pos_loyalty_exclude create mode 100644 setup/pos_loyalty_exclude/setup.py diff --git a/pos_loyalty_exclude/README.rst b/pos_loyalty_exclude/README.rst new file mode 100644 index 0000000000..ad89c39143 --- /dev/null +++ b/pos_loyalty_exclude/README.rst @@ -0,0 +1,79 @@ +=================== +POS Loyalty Exclude +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:70e53bcb716cc8128d6f60bee192550f22176bd54d034ba51bcd4888cb5b2550 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_loyalty_exclude + :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_loyalty_exclude + :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| + +Integrate 'Loyalty Exclude' functionality to POS +The behavior is similar to the module [sale_loyalty_exclude](https://github.com/OCA/sale-workflow/tree/16.0/sale_loyalty_exclude) + +**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_loyalty_exclude/__init__.py b/pos_loyalty_exclude/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_loyalty_exclude/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_loyalty_exclude/__manifest__.py b/pos_loyalty_exclude/__manifest__.py new file mode 100644 index 0000000000..f07561b5b3 --- /dev/null +++ b/pos_loyalty_exclude/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "POS Loyalty Exclude", + "summary": "Exclude products from sale loyalty program in POS", + "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": ["sale_loyalty_exclude", "pos_loyalty"], + "installable": True, + "assets": { + "web.assets_tests": [ + "pos_loyalty_exclude/static/src/tours/**/*", + ], + }, + "auto_install": True, +} diff --git a/pos_loyalty_exclude/models/__init__.py b/pos_loyalty_exclude/models/__init__.py new file mode 100644 index 0000000000..a1128c3a5b --- /dev/null +++ b/pos_loyalty_exclude/models/__init__.py @@ -0,0 +1 @@ +from . import loyalty_rule diff --git a/pos_loyalty_exclude/models/loyalty_rule.py b/pos_loyalty_exclude/models/loyalty_rule.py new file mode 100644 index 0000000000..5c14d77196 --- /dev/null +++ b/pos_loyalty_exclude/models/loyalty_rule.py @@ -0,0 +1,40 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models +from odoo.osv import expression + + +class LoyaltyRule(models.Model): + _inherit = "loyalty.rule" + + @api.depends("product_ids", "product_category_id", "product_tag_id") + def _compute_valid_product_ids(self): + super()._compute_valid_product_ids() + excluded_products = self.env["product.product"].search_count( + [("loyalty_exclude", "=", True), ("available_in_pos", "=", True)] + ) + # this check ensures that it only runs when there are loyalty-excluded products + if excluded_products: + for rule in self: + # exclude product when no config in loyalty rule + if not ( + rule.product_ids + or rule.product_category_id + or rule.product_tag_id + or rule.product_domain not in ("[]", "[['sale_ok', '=', True]]") + ): + rule.any_product = False + rule.valid_product_ids = self.env["product.product"].search( + [ + ("loyalty_exclude", "=", False), + ("available_in_pos", "=", True), + ], + order="id", + ) + return True + + def _get_valid_product_domain(self): + domain = super()._get_valid_product_domain() + domain = expression.AND([domain, [("loyalty_exclude", "=", False)]]) + return domain diff --git a/pos_loyalty_exclude/readme/CONTRIBUTORS.rst b/pos_loyalty_exclude/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..b4bdca8a7c --- /dev/null +++ b/pos_loyalty_exclude/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Camptocamp `_ + + * Tri Doan diff --git a/pos_loyalty_exclude/readme/DESCRIPTION.rst b/pos_loyalty_exclude/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..e7ecdfafde --- /dev/null +++ b/pos_loyalty_exclude/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Integrate 'Loyalty Exclude' functionality to POS +The behavior is similar to the module [sale_loyalty_exclude](https://github.com/OCA/sale-workflow/tree/16.0/sale_loyalty_exclude) diff --git a/pos_loyalty_exclude/static/description/index.html b/pos_loyalty_exclude/static/description/index.html new file mode 100644 index 0000000000..b422bc1cb5 --- /dev/null +++ b/pos_loyalty_exclude/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +POS Loyalty Exclude + + + +
+

POS Loyalty Exclude

+ + +

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

+

Integrate ‘Loyalty Exclude’ functionality to POS +The behavior is similar to the module [sale_loyalty_exclude](https://github.com/OCA/sale-workflow/tree/16.0/sale_loyalty_exclude)

+

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_loyalty_exclude/static/src/tours/PosLoyaltyExcludeTour.esm.js b/pos_loyalty_exclude/static/src/tours/PosLoyaltyExcludeTour.esm.js new file mode 100644 index 0000000000..edba97aae0 --- /dev/null +++ b/pos_loyalty_exclude/static/src/tours/PosLoyaltyExcludeTour.esm.js @@ -0,0 +1,24 @@ +/** @odoo-module **/ + +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.do.clickPartnerButton(); +ProductScreen.do.clickCustomer("Mr Odoo"); +ProductScreen.exec.addOrderline("Product Include Loyalty", "1.00", "90"); +ProductScreen.check.totalAmountIs("90.00"); +// Excluded-loyalty product has no effect on the minimum amount required to apply for the loyalty program. +ProductScreen.exec.addOrderline("Product Exclude Loyalty", "1.00", "100"); +ProductScreen.check.totalAmountIs("190.00"); + +// Increase the quantity of applicable product for loyalty program +ProductScreen.do.clickOrderline("Product Include Loyalty", "1.00"); +ProductScreen.do.pressNumpad("Qty 2"); // Change the quantity of the product to 2 +ProductScreen.check.totalAmountIs("270.00"); + +Tour.register("PosExcludeLoyaltyPromotion", {test: true, url: "/pos/web"}, getSteps()); diff --git a/pos_loyalty_exclude/tests/__init__.py b/pos_loyalty_exclude/tests/__init__.py new file mode 100644 index 0000000000..6075535796 --- /dev/null +++ b/pos_loyalty_exclude/tests/__init__.py @@ -0,0 +1 @@ +from . import test_pos_loyalty_exclude diff --git a/pos_loyalty_exclude/tests/test_pos_loyalty_exclude.py b/pos_loyalty_exclude/tests/test_pos_loyalty_exclude.py new file mode 100644 index 0000000000..309265f0c6 --- /dev/null +++ b/pos_loyalty_exclude/tests/test_pos_loyalty_exclude.py @@ -0,0 +1,86 @@ +# 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 TestPosLoyaltyExclude(TestPointOfSaleHttpCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env["base"].with_context(**DISABLED_MAIL_CONTEXT).env + + def test_exclude_loyalty_program(self): + self.env["loyalty.program"].search([]).write({"active": False}) + self.test_product_1 = self.env["product.product"].create( + { + "name": "Product Exclude Loyalty", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "loyalty_exclude": True, + "taxes_id": False, + } + ) + self.test_product_2 = self.env["product.product"].create( + { + "name": "Product Include Loyalty", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "loyalty_exclude": False, + "taxes_id": False, + } + ) + self.loyalty_program = self.env["loyalty.program"].create( + { + "name": "Loyalty Program", + "program_type": "loyalty", + "pos_ok": True, + "rule_ids": [ + ( + 0, + 0, + { + "minimum_amount": 100, + "minimum_qty": 1, + "reward_point_mode": "order", + "reward_point_amount": 500, + }, + ) + ], + "reward_ids": [ + ( + 0, + 0, + { + "required_points": 500, + "reward_type": "discount", + "discount": "10", + "discount_mode": "per_order", # -10$ per order + }, + ) + ], + } + ) + + partner = self.env["res.partner"].create({"name": "Mr Odoo"}) + self.env["loyalty.card"].create( + { + "partner_id": partner.id, + "program_id": self.loyalty_program.id, + "points": 500, + } + ) + + self.main_pos_config.open_ui() + + self.start_tour( + "/pos/web?config_id=%d" % self.main_pos_config.id, + "PosExcludeLoyaltyPromotion", + login="accountman", + ) diff --git a/setup/pos_loyalty_exclude/odoo/addons/pos_loyalty_exclude b/setup/pos_loyalty_exclude/odoo/addons/pos_loyalty_exclude new file mode 120000 index 0000000000..034956f522 --- /dev/null +++ b/setup/pos_loyalty_exclude/odoo/addons/pos_loyalty_exclude @@ -0,0 +1 @@ +../../../../pos_loyalty_exclude \ No newline at end of file diff --git a/setup/pos_loyalty_exclude/setup.py b/setup/pos_loyalty_exclude/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_loyalty_exclude/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)