-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sale_loyalty_partner_applicability: New module
TT45413
- Loading branch information
1 parent
f080b8c
commit 2eab37d
Showing
16 changed files
with
943 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
================================== | ||
Sale Loyalty Partner Applicability | ||
================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:bd99f5149f7b31775a82ebf75fa2031b9afc04d0bfde9e4a566329bf4054cd0b | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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_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-16-0/sale-promotion-16-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=16.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:%2016.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/16.0/sale_loyalty_partner_applicability>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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": "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_partner_applicability"], | ||
"data": [ | ||
"views/res_config_settings.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import sale_order | ||
from . import res_config_settings |
13 changes: 13 additions & 0 deletions
13
sale_loyalty_partner_applicability/models/res_config_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2023 Tecnativa - Pilar Vargas Moreno | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
|
||
_inherit = "res.config.settings" | ||
|
||
allow_coupon_sharing = fields.Boolean( | ||
string="Allow coupon sharing", config_parameter="allow_coupon_sharing" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 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 != "[]": | ||
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 partner_domain: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Pilar Vargas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
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. |
Oops, something went wrong.