From dc2d71102ea4d9c11af9c6bc16f8c8334cbe818d Mon Sep 17 00:00:00 2001 From: Luis Ernesto Garcia Medina Date: Sun, 15 Oct 2023 23:51:39 -0600 Subject: [PATCH] [MIG] sale_coupon_incompatibility: Migration to 16.0 and rename to sale_loyalty_incompatibility --- sale_loyalty_incompatibility/README.rst | 22 +++++++------- sale_loyalty_incompatibility/__manifest__.py | 6 ++-- sale_loyalty_incompatibility/i18n/es.po | 16 +++++----- ...y.pot => sale_loyalty_incompatibility.pot} | 16 +++++----- .../models/__init__.py | 3 +- .../models/sale_coupon.py | 30 ------------------- .../models/sale_order.py | 25 ++++++++++++++++ sale_loyalty_incompatibility/readme/USAGE.rst | 4 +-- .../static/description/index.html | 18 +++++------ .../tests/test_sale_coupon_incompatibility.py | 6 ++-- 10 files changed, 70 insertions(+), 76 deletions(-) rename sale_loyalty_incompatibility/i18n/{sale_coupon_incompatibility.pot => sale_loyalty_incompatibility.pot} (55%) delete mode 100644 sale_loyalty_incompatibility/models/sale_coupon.py create mode 100644 sale_loyalty_incompatibility/models/sale_order.py diff --git a/sale_loyalty_incompatibility/README.rst b/sale_loyalty_incompatibility/README.rst index 14b998ae..32593db7 100644 --- a/sale_loyalty_incompatibility/README.rst +++ b/sale_loyalty_incompatibility/README.rst @@ -1,13 +1,13 @@ -======================== -Coupon incompatibilities -======================== +========================= +Loyalty incompatibilities +========================= .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:5f10374003403bbcd364cf5e67d597e54a8528030be49132d4fda54d30f4df16 + !! source digest: sha256:0a08b29a4c259fa45c1a162e2539bc400e9ecfa97b60f4fc878faca7dd3fb701 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png @@ -17,13 +17,13 @@ Coupon incompatibilities :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/15.0/sale_coupon_incompatibility + :target: https://github.com/OCA/sale-promotion/tree/16.0-mig-sale_coupon_incompatibility/sale_loyalty_incompatibility :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-15-0/sale-promotion-15-0-sale_coupon_incompatibility + :target: https://translation.odoo-community.org/projects/sale-promotion-16-0-mig-sale_coupon_incompatibility/sale-promotion-16-0-mig-sale_coupon_incompatibility-sale_loyalty_incompatibility :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=15.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=16.0-mig-sale_coupon_incompatibility :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -42,8 +42,8 @@ Usage Once you've configured your incompatibilities, go to a quotations that fulfills your incompatible promotions and try to set them altogether. -- A coupon program with no code, won't be applied. -- A coupon or program code, will raise an error. +- A loyalty program with no code, won't be applied. +- A loyalty or program code, will raise an error. Bug Tracker =========== @@ -51,7 +51,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -93,6 +93,6 @@ Current `maintainer `__: |maintainer-chienandalu| -This module is part of the `OCA/sale-promotion `_ project on GitHub. +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_incompatibility/__manifest__.py b/sale_loyalty_incompatibility/__manifest__.py index bba8228c..026ddae7 100644 --- a/sale_loyalty_incompatibility/__manifest__.py +++ b/sale_loyalty_incompatibility/__manifest__.py @@ -1,14 +1,14 @@ # Copyright 2021 Tecnativa - David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - "name": "Coupon incompatibilities", + "name": "Loyalty incompatibilities", "summary": "Allows to set incompatibility rules between promotions", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "development_status": "Production/Stable", "category": "Sale", "website": "https://github.com/OCA/sale-promotion", "author": "Tecnativa, Odoo Community Association (OCA)", "maintainers": ["chienandalu"], "license": "AGPL-3", - "depends": ["sale_coupon", "coupon_incompatibility"], + "depends": ["loyalty_incompatibility"], } diff --git a/sale_loyalty_incompatibility/i18n/es.po b/sale_loyalty_incompatibility/i18n/es.po index 6faa3f4a..48720772 100644 --- a/sale_loyalty_incompatibility/i18n/es.po +++ b/sale_loyalty_incompatibility/i18n/es.po @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * sale_coupon_incompatibility +# * sale_loyalty_incompatibility # msgid "" msgstr "" @@ -17,19 +17,19 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 3.2.2\n" -#. module: sale_coupon_incompatibility -#: model:ir.model,name:sale_coupon_incompatibility.model_coupon_coupon +#. module: sale_loyalty_incompatibility +#: model:ir.model,name:sale_loyalty_incompatibility.model_coupon_coupon msgid "Coupon" msgstr "Cupón" -#. module: sale_coupon_incompatibility -#: model:ir.model,name:sale_coupon_incompatibility.model_coupon_program +#. module: sale_loyalty_incompatibility +#: model:ir.model,name:sale_loyalty_incompatibility.model_coupon_program msgid "Coupon display on a website" msgstr "" -#. module: sale_coupon_incompatibility -#: code:addons/sale_coupon_incompatibility/models/coupon_program.py:0 -#: code:addons/sale_coupon_incompatibility/models/sale_coupon.py:0 +#. module: sale_loyalty_incompatibility +#: code:addons/sale_loyalty_incompatibility/models/coupon_program.py:0 +#: code:addons/sale_loyalty_incompatibility/models/sale_coupon.py:0 #, python-format msgid "" "This promotion is incompatible with other set already in the order so it " diff --git a/sale_loyalty_incompatibility/i18n/sale_coupon_incompatibility.pot b/sale_loyalty_incompatibility/i18n/sale_loyalty_incompatibility.pot similarity index 55% rename from sale_loyalty_incompatibility/i18n/sale_coupon_incompatibility.pot rename to sale_loyalty_incompatibility/i18n/sale_loyalty_incompatibility.pot index 38d7595c..5a310ce0 100644 --- a/sale_loyalty_incompatibility/i18n/sale_coupon_incompatibility.pot +++ b/sale_loyalty_incompatibility/i18n/sale_loyalty_incompatibility.pot @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * sale_coupon_incompatibility +# * sale_loyalty_incompatibility # msgid "" msgstr "" @@ -13,19 +13,19 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" -#. module: sale_coupon_incompatibility -#: model:ir.model,name:sale_coupon_incompatibility.model_coupon_coupon +#. module: sale_loyalty_incompatibility +#: model:ir.model,name:sale_loyalty_incompatibility.model_coupon_coupon msgid "Coupon" msgstr "" -#. module: sale_coupon_incompatibility -#: model:ir.model,name:sale_coupon_incompatibility.model_coupon_program +#. module: sale_loyalty_incompatibility +#: model:ir.model,name:sale_loyalty_incompatibility.model_coupon_program msgid "Coupon display on a website" msgstr "" -#. module: sale_coupon_incompatibility -#: code:addons/sale_coupon_incompatibility/models/coupon_program.py:0 -#: code:addons/sale_coupon_incompatibility/models/sale_coupon.py:0 +#. module: sale_loyalty_incompatibility +#: code:addons/sale_loyalty_incompatibility/models/coupon_program.py:0 +#: code:addons/sale_loyalty_incompatibility/models/sale_coupon.py:0 #, python-format msgid "" "This promotion is incompatible with other set already in the order so it " diff --git a/sale_loyalty_incompatibility/models/__init__.py b/sale_loyalty_incompatibility/models/__init__.py index 5743c52c..6aacb753 100644 --- a/sale_loyalty_incompatibility/models/__init__.py +++ b/sale_loyalty_incompatibility/models/__init__.py @@ -1,2 +1 @@ -from . import coupon_program -from . import sale_coupon +from . import sale_order diff --git a/sale_loyalty_incompatibility/models/sale_coupon.py b/sale_loyalty_incompatibility/models/sale_coupon.py deleted file mode 100644 index f2d43da5..00000000 --- a/sale_loyalty_incompatibility/models/sale_coupon.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2021 Tecnativa - David Vidal -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import _, models - - -class Coupon(models.Model): - _inherit = "coupon.coupon" - - def _check_coupon_code(self, order_date, partner_id, **kwargs): - """Coupon incompatibility rules. Check the error strings for a detailed case - detail.""" - message = super()._check_coupon_code(order_date, partner_id, **kwargs) - order = kwargs.get("order", False) - # Other errors may precede - if message: - return message - order_programs = order.no_code_promo_program_ids + order.code_promo_program_id - order_programs |= ( - order.applied_coupon_ids + order.generated_coupon_ids - ).mapped("program_id") - if any( - {x in order_programs for x in self.program_id.incompatible_promotion_ids} - ): - message = { - "error": _( - "This promotion is incompatible with other set already in the " - "order so it can't be applied." - ) - } - return message diff --git a/sale_loyalty_incompatibility/models/sale_order.py b/sale_loyalty_incompatibility/models/sale_order.py new file mode 100644 index 00000000..010018df --- /dev/null +++ b/sale_loyalty_incompatibility/models/sale_order.py @@ -0,0 +1,25 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import _, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _program_check_compute_points(self, programs): + """Coupon incompatibility rules. Check the error strings for a detailed case + detail.""" + self.ensure_one() + result = super()._program_check_compute_points(programs) + order_programs = self.order_line.reward_id.program_id + for program in programs: + if any( + {x in order_programs for x in program.incompatible_promotion_ids} + ): + result[program] = { + "error": _( + "This promotion is incompatible with other set already in the " + "order so it can't be applied." + ) + } + return result diff --git a/sale_loyalty_incompatibility/readme/USAGE.rst b/sale_loyalty_incompatibility/readme/USAGE.rst index 0137dbab..8a561407 100644 --- a/sale_loyalty_incompatibility/readme/USAGE.rst +++ b/sale_loyalty_incompatibility/readme/USAGE.rst @@ -1,5 +1,5 @@ Once you've configured your incompatibilities, go to a quotations that fulfills your incompatible promotions and try to set them altogether. -- A coupon program with no code, won't be applied. -- A coupon or program code, will raise an error. +- A loyalty program with no code, won't be applied. +- A loyalty or program code, will raise an error. diff --git a/sale_loyalty_incompatibility/static/description/index.html b/sale_loyalty_incompatibility/static/description/index.html index c58f9957..bc903657 100644 --- a/sale_loyalty_incompatibility/static/description/index.html +++ b/sale_loyalty_incompatibility/static/description/index.html @@ -4,7 +4,7 @@ -Coupon incompatibilities +Loyalty incompatibilities -
-

Coupon incompatibilities

+
+

Loyalty incompatibilities

-

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

+

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

This module allows to set incompatibilities between promotions, so when a promotion A is not compatible with promotion B, they can’t be applied together in a sales order.

Table of contents

@@ -390,8 +390,8 @@

Usage

Once you’ve configured your incompatibilities, go to a quotations that fulfills your incompatible promotions and try to set them altogether.

    -
  • A coupon program with no code, won’t be applied.
  • -
  • A coupon or program code, will raise an error.
  • +
  • A loyalty program with no code, won’t be applied.
  • +
  • A loyalty or program code, will raise an error.
@@ -399,7 +399,7 @@

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.

+feedback.

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

@@ -430,7 +430,7 @@

Maintainers

promote its widespread use.

Current maintainer:

chienandalu

-

This module is part of the OCA/sale-promotion project on GitHub.

+

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_incompatibility/tests/test_sale_coupon_incompatibility.py b/sale_loyalty_incompatibility/tests/test_sale_coupon_incompatibility.py index bbdfb5ea..06f15f1a 100644 --- a/sale_loyalty_incompatibility/tests/test_sale_coupon_incompatibility.py +++ b/sale_loyalty_incompatibility/tests/test_sale_coupon_incompatibility.py @@ -3,12 +3,12 @@ from odoo.exceptions import UserError from odoo.tests import Form -from odoo.addons.coupon_incompatibility.tests.test_coupon_incompatibility import ( - CouponIncompatibilityCase, +from odoo.addons.loyalty_incompatibility.tests.test_loyalty_incompatibility import ( + LoyaltyIncompatibilityCase, ) -class TestCouponIncompatibility(CouponIncompatibilityCase): +class TestLoyaltyIncompatibility(LoyaltyIncompatibilityCase): def _create_coupon_program(self, product=False, code=False, apply_on_order=True): """Helper method to create coupon programs in the tests cases""" coupon_program_form = Form(