Skip to content

Commit 48dd1b4

Browse files
chienandalupilarvargas-tecnativa
authored andcommitted
[ADD] sale_coupon_incompatibility: New module
TT30846
1 parent 0e7c21a commit 48dd1b4

17 files changed

+1000
-0
lines changed
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
========================
2+
Coupon incompatibilities
3+
========================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Production/Stable
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github
17+
:target: https://github.com/OCA/sale-promotion/tree/13.0/sale_coupon_incompatibility
18+
:alt: OCA/sale-promotion
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/sale-promotion-13-0/sale-promotion-13-0-sale_coupon_incompatibility
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/296/13.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module allows to set incompatibilities between promotions, so when a promotion A
29+
is not compatible with promotion B, they can't be applied together in a sales order.
30+
31+
**Table of contents**
32+
33+
.. contents::
34+
:local:
35+
36+
Configuration
37+
=============
38+
39+
To configure promotion incompatibilities (either coupons or promotion programs):
40+
41+
#. Go to *Sales > Catalog > Coupon Programs* and select or create a new one.
42+
#. In the *Incompatible Promotions* set the promotions that aren't compatible with the
43+
one you're configuring.
44+
#. Once set, the those promotions will have your configured promotion as incompatible
45+
as well, so they can't be used altogether in the same sale order.
46+
47+
Usage
48+
=====
49+
50+
Once you've configured your incompatibilities, go to a quotations that fulfills your
51+
incompatible promotions and try to set them altogether.
52+
53+
- A coupon program with no code, won't be applied.
54+
- A coupon or program code, will raise an error.
55+
56+
Bug Tracker
57+
===========
58+
59+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-promotion/issues>`_.
60+
In case of trouble, please check there if your issue has already been reported.
61+
If you spotted it first, help us smashing it by providing a detailed and welcomed
62+
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20sale_coupon_incompatibility%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
63+
64+
Do not contact contributors directly about support or help with technical issues.
65+
66+
Credits
67+
=======
68+
69+
Authors
70+
~~~~~~~
71+
72+
* Tecnativa
73+
74+
Contributors
75+
~~~~~~~~~~~~
76+
77+
* `Tecnativa <https://www.tecnativa.com>`_:
78+
79+
* Pedro M. Baeza
80+
* David Vidal
81+
82+
Maintainers
83+
~~~~~~~~~~~
84+
85+
This module is maintained by the OCA.
86+
87+
.. image:: https://odoo-community.org/logo.png
88+
:alt: Odoo Community Association
89+
:target: https://odoo-community.org
90+
91+
OCA, or the Odoo Community Association, is a nonprofit organization whose
92+
mission is to support the collaborative development of Odoo features and
93+
promote its widespread use.
94+
95+
.. |maintainer-chienandalu| image:: https://github.com/chienandalu.png?size=40px
96+
:target: https://github.com/chienandalu
97+
:alt: chienandalu
98+
99+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
100+
101+
|maintainer-chienandalu|
102+
103+
This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/13.0/sale_coupon_incompatibility>`_ project on GitHub.
104+
105+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2021 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Coupon incompatibilities",
5+
"summary": "Allows to set incompatibility rules between promotions",
6+
"version": "13.0.1.0.0",
7+
"development_status": "Production/Stable",
8+
"category": "Sale",
9+
"website": "https://github.com/OCA/sale-promotion",
10+
"author": "Tecnativa, Odoo Community Association (OCA)",
11+
"maintainers": ["chienandalu"],
12+
"license": "AGPL-3",
13+
"depends": ["sale_coupon"],
14+
"data": ["views/sale_coupon_program_views.xml"],
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * sale_coupon_incompatibility
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 13.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: sale_coupon_incompatibility
17+
#: model:ir.model.fields,field_description:sale_coupon_incompatibility.field_sale_coupon_program__incompatible_promotion_ids
18+
msgid "Incompatible Promotions"
19+
msgstr ""
20+
21+
#. module: sale_coupon_incompatibility
22+
#: model:ir.model,name:sale_coupon_incompatibility.model_sale_coupon
23+
msgid "Sales Coupon"
24+
msgstr ""
25+
26+
#. module: sale_coupon_incompatibility
27+
#: model:ir.model,name:sale_coupon_incompatibility.model_sale_coupon_program
28+
msgid "Sales Coupon Program"
29+
msgstr ""
30+
31+
#. module: sale_coupon_incompatibility
32+
#: code:addons/sale_coupon_incompatibility/models/sale_coupon.py:0
33+
#: code:addons/sale_coupon_incompatibility/models/sale_coupon_program.py:0
34+
#, python-format
35+
msgid ""
36+
"This promotion is incompatible with other set already in the order so it "
37+
"can't be applied."
38+
msgstr ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import sale_coupon_program
2+
from . import sale_coupon
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2021 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import _, models
4+
5+
6+
class SaleCoupon(models.Model):
7+
_inherit = "sale.coupon"
8+
9+
def _check_coupon_code(self, order):
10+
"""Coupon incompatibility rules. Check the error strings for a detailed case
11+
detail."""
12+
message = super()._check_coupon_code(order)
13+
# Other errors may precede
14+
if message:
15+
return message
16+
order_programs = order.no_code_promo_program_ids + order.code_promo_program_id
17+
order_programs |= (
18+
order.applied_coupon_ids + order.generated_coupon_ids
19+
).mapped("program_id")
20+
if any(
21+
{x in order_programs for x in self.program_id.incompatible_promotion_ids}
22+
):
23+
message = {
24+
"error": _(
25+
"This promotion is incompatible with other set already in the "
26+
"order so it can't be applied."
27+
)
28+
}
29+
return message
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2021 Tecnativa - David Vidal
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import _, fields, models
4+
5+
6+
class SaleCouponProgram(models.Model):
7+
_inherit = "sale.coupon.program"
8+
9+
incompatible_promotion_ids = fields.Many2many(
10+
comodel_name="sale.coupon.program",
11+
relation="sale_coupon_program_incompatibility_rel",
12+
column1="program_id",
13+
column2="incompatible_program_id",
14+
inverse="_inverse_incompatible_promotion_ids",
15+
string="Incompatible Promotions",
16+
)
17+
18+
def _inverse_incompatible_promotion_ids(self):
19+
"""We'll be ensuring that any program that could have been removed from the
20+
field will be compatible again and that any new program in the field will
21+
be incompatible with this one. So we will ensure that A ⊥ B as B ⊥ A"""
22+
for program in self:
23+
incompatible_programs = self.search(
24+
[
25+
("incompatible_promotion_ids", "in", program.ids),
26+
("id", "!=", program.id),
27+
]
28+
)
29+
to_remove_programs = (
30+
incompatible_programs - program.incompatible_promotion_ids
31+
)
32+
program.incompatible_promotion_ids.incompatible_promotion_ids |= program
33+
to_remove_programs.incompatible_promotion_ids -= program
34+
35+
def _check_promo_code(self, order, coupon_code):
36+
"""Promotion incompatibility rules. Check the error strings for a detailed case
37+
detail."""
38+
message = super()._check_promo_code(order, coupon_code)
39+
# Other errors may precede
40+
if message:
41+
return message
42+
order_programs = order.no_code_promo_program_ids + order.code_promo_program_id
43+
order_programs |= (
44+
order.applied_coupon_ids + order.generated_coupon_ids
45+
).mapped("program_id")
46+
if any({x in order_programs for x in self.incompatible_promotion_ids}):
47+
message = {
48+
"error": _(
49+
"This promotion is incompatible with other set already in the "
50+
"order so it can't be applied."
51+
)
52+
}
53+
return message
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
To configure promotion incompatibilities (either coupons or promotion programs):
2+
3+
#. Go to *Sales > Catalog > Coupon Programs* and select or create a new one.
4+
#. In the *Incompatible Promotions* set the promotions that aren't compatible with the
5+
one you're configuring.
6+
#. Once set, the those promotions will have your configured promotion as incompatible
7+
as well, so they can't be used altogether in the same sale order.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* `Tecnativa <https://www.tecnativa.com>`_:
2+
3+
* Pedro M. Baeza
4+
* David Vidal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module allows to set incompatibilities between promotions, so when a promotion A
2+
is not compatible with promotion B, they can't be applied together in a sales order.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Once you've configured your incompatibilities, go to a quotations that fulfills your
2+
incompatible promotions and try to set them altogether.
3+
4+
- A coupon program with no code, won't be applied.
5+
- A coupon or program code, will raise an error.
Loading

0 commit comments

Comments
 (0)