From b8f191fff6f8b743cc4350ef746a73b39599ee42 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Thu, 26 Oct 2023 13:30:03 +0200 Subject: [PATCH] [ADD] sale_loyalty_initial_date_validity: New module 45685 --- sale_loyalty_initial_date_validity/README.rst | 96 ++++ .../__init__.py | 1 + .../__manifest__.py | 12 + .../sale_loyalty_initial_date_validity.pot | 21 + .../models/__init__.py | 1 + .../models/sale_order.py | 34 ++ .../readme/CONTEXT.rst | 1 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 2 + .../readme/ROADMAP.rst | 2 + .../readme/USAGE.rst | 2 + .../static/description/index.html | 442 ++++++++++++++++++ .../tests/__init__.py | 1 + ...test_sale_loyalty_initial_date_validity.py | 119 +++++ .../addons/sale_loyalty_initial_date_validity | 1 + .../setup.py | 6 + 16 files changed, 744 insertions(+) create mode 100644 sale_loyalty_initial_date_validity/README.rst create mode 100644 sale_loyalty_initial_date_validity/__init__.py create mode 100644 sale_loyalty_initial_date_validity/__manifest__.py create mode 100644 sale_loyalty_initial_date_validity/i18n/sale_loyalty_initial_date_validity.pot create mode 100644 sale_loyalty_initial_date_validity/models/__init__.py create mode 100644 sale_loyalty_initial_date_validity/models/sale_order.py create mode 100644 sale_loyalty_initial_date_validity/readme/CONTEXT.rst create mode 100644 sale_loyalty_initial_date_validity/readme/CONTRIBUTORS.rst create mode 100644 sale_loyalty_initial_date_validity/readme/DESCRIPTION.rst create mode 100644 sale_loyalty_initial_date_validity/readme/ROADMAP.rst create mode 100644 sale_loyalty_initial_date_validity/readme/USAGE.rst create mode 100644 sale_loyalty_initial_date_validity/static/description/index.html create mode 100644 sale_loyalty_initial_date_validity/tests/__init__.py create mode 100644 sale_loyalty_initial_date_validity/tests/test_sale_loyalty_initial_date_validity.py create mode 120000 setup/sale_loyalty_initial_date_validity/odoo/addons/sale_loyalty_initial_date_validity create mode 100644 setup/sale_loyalty_initial_date_validity/setup.py diff --git a/sale_loyalty_initial_date_validity/README.rst b/sale_loyalty_initial_date_validity/README.rst new file mode 100644 index 00000000..f0ef7899 --- /dev/null +++ b/sale_loyalty_initial_date_validity/README.rst @@ -0,0 +1,96 @@ +================================== +Sale Loyalty Initial Date Validity +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2d01e4e9ea5054e103feba82525c0c13dd362089aa805aaf26f92ed3ed601c38 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--promotion-lightgray.png?logo=github + :target: https://github.com/OCA/sale-promotion/tree/16.0/sale_loyalty_initial_date_validity + :alt: OCA/sale-promotion +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-sale_loyalty_initial_date_validity + :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/sale-promotion&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of loyalty_initial_date_validity to make checks +when applying a promotion based on the start date of the promotion. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +This module is required to complete the loyalty_initial_date_validity functionality. + +Usage +===== + +To use this module, simply go to edit or create a promotion and set a start date in the +"Start date" field and then apply the promotion to a sales order. + +Known issues / Roadmap +====================== + +This module will not be needed in v17 as this functionality is reinstated. +https://github.com/odoo/odoo/commit/bce4aededc37bac40c89aae44a157f20a873528f + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Pilar Vargas + +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/sale-promotion `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_loyalty_initial_date_validity/__init__.py b/sale_loyalty_initial_date_validity/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/sale_loyalty_initial_date_validity/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_loyalty_initial_date_validity/__manifest__.py b/sale_loyalty_initial_date_validity/__manifest__.py new file mode 100644 index 00000000..ec9453fd --- /dev/null +++ b/sale_loyalty_initial_date_validity/__manifest__.py @@ -0,0 +1,12 @@ +# Copyright 2023 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Loyalty Initial Date Validity", + "summary": "", + "version": "16.0.1.0.0", + "category": "Sale", + "website": "https://github.com/OCA/sale-promotion", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["sale_loyalty", "loyalty_initial_date_validity"], +} diff --git a/sale_loyalty_initial_date_validity/i18n/sale_loyalty_initial_date_validity.pot b/sale_loyalty_initial_date_validity/i18n/sale_loyalty_initial_date_validity.pot new file mode 100644 index 00000000..36a90d89 --- /dev/null +++ b/sale_loyalty_initial_date_validity/i18n/sale_loyalty_initial_date_validity.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_loyalty_initial_date_validity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 11:10+0000\n" +"PO-Revision-Date: 2023-10-26 11:10+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_loyalty_initial_date_validity +#: model:ir.model,name:sale_loyalty_initial_date_validity.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/sale_loyalty_initial_date_validity/models/__init__.py b/sale_loyalty_initial_date_validity/models/__init__.py new file mode 100644 index 00000000..6aacb753 --- /dev/null +++ b/sale_loyalty_initial_date_validity/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_loyalty_initial_date_validity/models/sale_order.py b/sale_loyalty_initial_date_validity/models/sale_order.py new file mode 100644 index 00000000..00b89bfd --- /dev/null +++ b/sale_loyalty_initial_date_validity/models/sale_order.py @@ -0,0 +1,34 @@ +# Copyright 2023 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models +from odoo.osv import expression + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _get_program_domain(self): + res = super()._get_program_domain() + return expression.AND( + [ + res, + [ + "|", + ("date_from", "=", False), + ("date_from", "<=", fields.Date.context_today(self)), + ], + ] + ) + + def _get_trigger_domain(self): + res = super()._get_trigger_domain() + return expression.AND( + [ + res, + [ + "|", + ("date_from", "=", False), + ("date_from", "<=", fields.Date.context_today(self)), + ], + ] + ) diff --git a/sale_loyalty_initial_date_validity/readme/CONTEXT.rst b/sale_loyalty_initial_date_validity/readme/CONTEXT.rst new file mode 100644 index 00000000..5f550932 --- /dev/null +++ b/sale_loyalty_initial_date_validity/readme/CONTEXT.rst @@ -0,0 +1 @@ +This module is required to complete the loyalty_initial_date_validity functionality. diff --git a/sale_loyalty_initial_date_validity/readme/CONTRIBUTORS.rst b/sale_loyalty_initial_date_validity/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..44075b9f --- /dev/null +++ b/sale_loyalty_initial_date_validity/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * Pilar Vargas diff --git a/sale_loyalty_initial_date_validity/readme/DESCRIPTION.rst b/sale_loyalty_initial_date_validity/readme/DESCRIPTION.rst new file mode 100644 index 00000000..06d6f6a2 --- /dev/null +++ b/sale_loyalty_initial_date_validity/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of loyalty_initial_date_validity to make checks +when applying a promotion based on the start date of the promotion. diff --git a/sale_loyalty_initial_date_validity/readme/ROADMAP.rst b/sale_loyalty_initial_date_validity/readme/ROADMAP.rst new file mode 100644 index 00000000..42aa2c95 --- /dev/null +++ b/sale_loyalty_initial_date_validity/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +This module will not be needed in v17 as this functionality is reinstated. +https://github.com/odoo/odoo/commit/bce4aededc37bac40c89aae44a157f20a873528f diff --git a/sale_loyalty_initial_date_validity/readme/USAGE.rst b/sale_loyalty_initial_date_validity/readme/USAGE.rst new file mode 100644 index 00000000..8ac5a1cb --- /dev/null +++ b/sale_loyalty_initial_date_validity/readme/USAGE.rst @@ -0,0 +1,2 @@ +To use this module, simply go to edit or create a promotion and set a start date in the +"Start date" field and then apply the promotion to a sales order. diff --git a/sale_loyalty_initial_date_validity/static/description/index.html b/sale_loyalty_initial_date_validity/static/description/index.html new file mode 100644 index 00000000..c93500d5 --- /dev/null +++ b/sale_loyalty_initial_date_validity/static/description/index.html @@ -0,0 +1,442 @@ + + + + + + +Sale Loyalty Initial Date Validity + + + +
+

Sale Loyalty Initial Date Validity

+ + +

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

+

This module extends the functionality of loyalty_initial_date_validity to make checks +when applying a promotion based on the start date of the promotion.

+

Table of contents

+ +
+

Use Cases / Context

+

This module is required to complete the loyalty_initial_date_validity functionality.

+
+
+

Usage

+

To use this module, simply go to edit or create a promotion and set a start date in the +“Start date” field and then apply the promotion to a sales order.

+
+
+

Known issues / Roadmap

+

This module will not be needed in v17 as this functionality is reinstated. +https://github.com/odoo/odoo/commit/bce4aededc37bac40c89aae44a157f20a873528f

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/sale_loyalty_initial_date_validity/tests/__init__.py b/sale_loyalty_initial_date_validity/tests/__init__.py new file mode 100644 index 00000000..46f97463 --- /dev/null +++ b/sale_loyalty_initial_date_validity/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_loyalty_initial_date_validity diff --git a/sale_loyalty_initial_date_validity/tests/test_sale_loyalty_initial_date_validity.py b/sale_loyalty_initial_date_validity/tests/test_sale_loyalty_initial_date_validity.py new file mode 100644 index 00000000..7ef1bee4 --- /dev/null +++ b/sale_loyalty_initial_date_validity/tests/test_sale_loyalty_initial_date_validity.py @@ -0,0 +1,119 @@ +# Copyright 2023 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import date, timedelta + +from odoo.exceptions import ValidationError +from odoo.tests import Form, TransactionCase + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestSaleLoyaltyInitialDateValidity(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + loyalty_program = cls.env["loyalty.program"] + # Promotion with start date currently valid + cls.promotion1 = loyalty_program.create( + { + "name": "Test with start date currently valid", + "program_type": "promotion", + "trigger": "auto", + "applies_on": "current", + "date_from": date.today() - timedelta(days=1), + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + }, + ) + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + # Promotion with a future start date + cls.promotion2 = loyalty_program.create( + { + "name": "Test with a future start date", + "program_type": "promotion", + "trigger": "auto", + "applies_on": "current", + "date_from": date.today() + timedelta(days=1), + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + }, + ) + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + cls.partner = cls.env["res.partner"].create({"name": "Mr. Odoo"}) + cls.product = cls.env["product.product"].create( + {"name": "Test Product", "list_price": 100} + ) + + def _action_apply_program(self, sale, program): + sale._update_programs_and_rewards() + wizard = ( + self.env["sale.loyalty.reward.wizard"] + .with_context(active_id=sale) + .create({"selected_reward_id": program.reward_ids.id}) + ) + wizard.action_apply() + + def _create_sale(self): + """Helper method to create sales in the test cases""" + sale_form = Form(self.env["sale.order"]) + sale_form.partner_id = self.partner + with sale_form.order_line.new() as line_form: + line_form.product_id = self.product + line_form.product_uom_qty = 1 + return sale_form.save() + + def test_01_sale_loyalty_initial_date_validity(self): + """It is verified that the promotion is applicable to a sales order that fulfils + the conditions of the promotion. The condition is that the promotion is + applicable from the current date.""" + sale_order = self._create_sale() + self._action_apply_program(sale_order, self.promotion1) + self.assertTrue(bool(sale_order.order_line.filtered("is_reward_line"))) + + def test_02_sale_loyalty_initial_date_validity(self): + """It is checked that the promotion is not applicable to a sell order that + fulfils the conditions of the promotion. The condition is that the promotion is + not applicable until tomorrow.""" + sale_order = self._create_sale() + with self.assertRaises(ValidationError): + self._action_apply_program(sale_order, self.promotion2) + self.assertFalse(bool(sale_order.order_line.filtered("is_reward_line"))) diff --git a/setup/sale_loyalty_initial_date_validity/odoo/addons/sale_loyalty_initial_date_validity b/setup/sale_loyalty_initial_date_validity/odoo/addons/sale_loyalty_initial_date_validity new file mode 120000 index 00000000..70a4195e --- /dev/null +++ b/setup/sale_loyalty_initial_date_validity/odoo/addons/sale_loyalty_initial_date_validity @@ -0,0 +1 @@ +../../../../sale_loyalty_initial_date_validity \ No newline at end of file diff --git a/setup/sale_loyalty_initial_date_validity/setup.py b/setup/sale_loyalty_initial_date_validity/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/sale_loyalty_initial_date_validity/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)