Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] sale_loyalty_partner_applicability #232

Open
wants to merge 12 commits into
base: 18.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions sale_loyalty_partner_applicability/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
==================================
Sale Loyalty Partner Applicability
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7f46e04a34e7594dd33b7bbf5c9443bef6fbfe164f511d54237341d908cd53f5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/18.0/sale_loyalty_partner_applicability
: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-18-0/sale-promotion-18-0-sale_loyalty_partner_applicability
: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=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the loyalty_partner_applicability functionality.
When this filter is defined, the promotion rule will only be applied to
customers who meet the specified conditions in the filter. The coupons
generated in a sales order for a specific member promotion can be shared
between members of the same trading entity.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure the partner based promotion filter:

Go to *Sales > Products > Discount & Loyalty* and select or create a new
one. In conditional rules set the condition based on customers.

In promotions that generate coupons for the next sale, we can allow
coupon sharing between members of the same commercial entity. To allow
this, go to *Settings > Sales > Pricing* and check the option "Allow
coupon sharing".

Usage
=====

Go to a sales order and apply the promotion accordingly. If the sales
order meets the requirements set in the partner based filter the
promotion will be applied to that order.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-promotion/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 <https://github.com/OCA/sale-promotion/issues/new?body=module:%20sale_loyalty_partner_applicability%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- 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 <https://github.com/OCA/sale-promotion/tree/18.0/sale_loyalty_partner_applicability>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_loyalty_partner_applicability/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions sale_loyalty_partner_applicability/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Loyalty Partner Applicability",
"summary": "Enables the definition of a customer filter for promotion rules "
"that will only be applied to customers who meet the specified conditions in the "
"filter.",
"version": "18.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_partner_applicability"],
"data": [
"views/res_config_settings.xml",
],
}
45 changes: 45 additions & 0 deletions sale_loyalty_partner_applicability/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_loyalty_partner_applicability
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-12-06 17:33+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: sale_loyalty_partner_applicability
#: model_terms:ir.ui.view,arch_db:sale_loyalty_partner_applicability.res_config_settings_view_form
msgid ""
"Allows a coupon generated for one partner to be used by any other member of "
"your commercial entity."
msgstr ""
"Consente di utilizzare un coupon creato per un partner da parte di un altro "
"componente della vostra entità commerciale."

#. module: sale_loyalty_partner_applicability
#: model_terms:ir.ui.view,arch_db:sale_loyalty_partner_applicability.res_config_settings_view_form
msgid "Coupon sharing between partners within the commercial entity."
msgstr ""
"Condivisione coupon tra partner all'interno della stessa entità commerciale."

#. module: sale_loyalty_partner_applicability
#: model:ir.model,name:sale_loyalty_partner_applicability.model_sale_order
msgid "Sales Order"
msgstr "Ordine di vendita"

#. module: sale_loyalty_partner_applicability
#. odoo-python
#: code:addons/sale_loyalty_partner_applicability/models/sale_order.py:0
#: code:addons/sale_loyalty_partner_applicability/models/sale_order.py:0
#, python-format
msgid "The customer doesn't have access to this reward."
msgstr "Il cliente non a accesso a questo premio."
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_loyalty_partner_applicability
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \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_partner_applicability
#: model_terms:ir.ui.view,arch_db:sale_loyalty_partner_applicability.res_config_settings_view_form
msgid ""
"Allows a coupon generated for one partner to be used by any other member of "
"your commercial entity."
msgstr ""

#. module: sale_loyalty_partner_applicability
#: model_terms:ir.ui.view,arch_db:sale_loyalty_partner_applicability.res_config_settings_view_form
msgid "Coupon sharing between partners within the commercial entity."
msgstr ""

#. module: sale_loyalty_partner_applicability
#: model:ir.model,name:sale_loyalty_partner_applicability.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_loyalty_partner_applicability
#. odoo-python
#: code:addons/sale_loyalty_partner_applicability/models/sale_order.py:0
#: code:addons/sale_loyalty_partner_applicability/models/sale_order.py:0
#, python-format
msgid "The customer doesn't have access to this reward."
msgstr ""
1 change: 1 addition & 0 deletions sale_loyalty_partner_applicability/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
77 changes: 77 additions & 0 deletions sale_loyalty_partner_applicability/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2023 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import ast

from odoo import _, models
from odoo.osv import expression


class SaleOrder(models.Model):
_inherit = "sale.order"

def _get_partner_domain(self, rule, partner_id):
domain = []
if rule.rule_partners_domain and rule.rule_partners_domain != "[]":
allow_sharing = (
self.env["ir.config_parameter"].sudo().get_param("allow_coupon_sharing")
)
if allow_sharing:
domain = [
("commercial_partner_id", "=", partner_id.commercial_partner_id.id)
]
else:
domain = [("id", "=", partner_id.id)]
domain = expression.AND(
[ast.literal_eval(rule.rule_partners_domain), domain]
)
return domain

def _is_valid_partner(self, program):
"""
Check if the partner is eligible for a loyalty program based on partner domains.
This method iterates through the loyalty program's rules and their partner
domains. It verifies if the partner meets the eligibility criteria specified
in the partner domain of each rule. When the partner is found eligible for a
rule, the program is considered valid.
Args:
program (recordset): The loyalty program for which partner eligibility is checked.
Returns:
bool: True if the partner is eligible for the program, False otherwise.
"""
for rule in program.rule_ids:
partner_domain = self._get_partner_domain(rule, self.partner_id)
if self.env["res.partner"].search_count(partner_domain):
return True
return False

def _program_check_compute_points(self, programs):
"""
Check and ensure partner eligibility for loyalty programs.
This method extends the behavior of checking and computing loyalty program
points. It checks if the customer meets the partner eligibility criteria
for each program. If a customer does not meet the criteria, an error is
added to the results for that program.
"""
res = super()._program_check_compute_points(programs)
for program, result in res.items():
if result.get("error", False):
continue
if not self._is_valid_partner(program):
res[program] = {
"error": _("The customer doesn't have access to this reward.")
}
return res

def _try_apply_code(self, code):
res = super()._try_apply_code(code)
base_domain = self._get_trigger_domain()
domain = expression.AND(
[base_domain, [("mode", "=", "with_code"), ("code", "=", code)]]
)
program = self.env["loyalty.rule"].search(domain).program_id
if not program:
program = self.env["loyalty.card"].search([("code", "=", code)]).program_id
# Check that the partner is valid when applying the coupon code.
if not self._is_valid_partner(program):
return {"error": _("The customer doesn't have access to this reward.")}
return res
3 changes: 3 additions & 0 deletions sale_loyalty_partner_applicability/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
9 changes: 9 additions & 0 deletions sale_loyalty_partner_applicability/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
To configure the partner based promotion filter:

Go to *Sales \> Products \> Discount & Loyalty* and select or create a
new one. In conditional rules set the condition based on customers.

In promotions that generate coupons for the next sale, we can allow
coupon sharing between members of the same commercial entity. To allow
this, go to *Settings \> Sales \> Pricing* and check the option "Allow
coupon sharing".
2 changes: 2 additions & 0 deletions sale_loyalty_partner_applicability/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Tecnativa](https://www.tecnativa.com):
- Pilar Vargas
5 changes: 5 additions & 0 deletions sale_loyalty_partner_applicability/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module extends the loyalty_partner_applicability functionality.
When this filter is defined, the promotion rule will only be applied to
customers who meet the specified conditions in the filter. The coupons
generated in a sales order for a specific member promotion can be shared
between members of the same trading entity.
3 changes: 3 additions & 0 deletions sale_loyalty_partner_applicability/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Go to a sales order and apply the promotion accordingly. If the sales
order meets the requirements set in the partner based filter the
promotion will be applied to that order.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading