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

[16.0][MIG] sale_coupon_limit > sale_loyalty_limit: Migration to version 16.0 #156

Merged
merged 13 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
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
126 changes: 126 additions & 0 deletions sale_loyalty_limit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
============
Coupon Limit
============

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |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_limit
: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_limit
: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 allows to configure a limit on the times a promotion can be applied. Two
limits can be configured: customer and salesman. Those limits apply to either programs
or coupons.

**Table of contents**

.. contents::
:local:

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

To configure customer limits:

#. Go to *Sales > Products > Discount & Loyalty* and select or create a new one.
#. Set the *Maximum Customer Applications* to the number of times a program can be used
by a customer.

NOTE: The customer limit is applied at commercial entity level, not for each contact
inside the entity.

To configure salesmen limits:

#. Go to *Sales > Products > Discount & Loyalty* and select or create a new one.
#. Add salesmen to the *Salesmen Limits* list and their maximum number of applications.
#. You can add different limits to different salesmen groups.
#. If you want to constrain the use of the promotion to the salesmen list, set the
option *Strict limit* on, so any other salesman won't be able to apply the promotion.

Usage
=====

Once the program limits are configured, apply the programs as usual in your sale orders.

Once the limit for a customer or a salesman is reached, if we try to apply a promotion:

- A code promotion will raise an error.
- A program with no code won't be applied.
- A coupon belonging to a limited program will raise an error.
- A promotion applied on the next order won't generate the coupon.

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_limit%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>`_:

* Pedro M. Baeza
* David Vidal
* Pilar Vargas

* `Akretion <https://www.akretion.com>`_:

* Florian Mounier

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.

.. |maintainer-chienandalu| image:: https://github.com/chienandalu.png?size=40px
:target: https://github.com/chienandalu
:alt: chienandalu

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-chienandalu|

This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/16.0/sale_loyalty_limit>`_ 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_limit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions sale_loyalty_limit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Coupon Limit",
"summary": "Restrict number of promotions per customer or salesman",
"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": [
"loyalty_limit",
"sale_commercial_partner",
"sale_loyalty_order_line_link",
],
"data": ["security/ir.model.access.csv"],
}
85 changes: 85 additions & 0 deletions sale_loyalty_limit/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_coupon_limit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-07-10 10:09+0000\n"
"Last-Translator: Francesco Foresti <[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_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_coupon
msgid "Coupon"
msgstr "Buono sconto"

#. module: sale_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_rule
msgid "Coupon Rule"
msgstr "Regola buono sconto"

#. module: sale_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_rule_salesmen_limit
msgid "Coupon Rule Salesmen limits"
msgstr "Limiti regola buono sconto addetto alle vendite"

#. module: sale_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_program
msgid "Coupon display on a website"
msgstr "Mostra buono sconto su sito web"

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid ""
"This promo code was already applied %(count)s times for this customer and "
"there's an stablished limit of %(max)s for this promotion."
msgstr ""
"Questo buono sconto è già stato applicato %(count)s volte per questo cliente "
"e il limite massimo è di %(max)s per questa promozione."

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid ""
"This promo code was already applied %(times)s times for this salesman and "
"there's an stablished limit of %(max)s for this promotion."
msgstr ""
"Questo buono sconto è già stato applicato %(times)s volte per questo addetto "
"alle vendite e il limite massimo è di %(max)s per questa promozione."

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_coupon.py:0
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid "This promotion is restricted to the listed salesmen."
msgstr "Questa promozione è riservata all'addetto alle vendite indicato."

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_coupon.py:0
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid ""
"This promotion was already applied %(count)s times for this customer and "
"there's an stablished limit of %(max)s."
msgstr ""
"Questa promozione è già stata applicata %(count)s volte per questo cliente e "
"il limite massimo è di %(max)s."

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_coupon.py:0
#, python-format
msgid ""
"This promotion was already applied %(times)s times for this salesman and "
"there's an stablished limit of %(max)s."
msgstr ""
"Questa promozione è già stata applicata %(times)s volte per questo addetto "
"alle vendite e il limite massimo è di %(max)s."
74 changes: 74 additions & 0 deletions sale_loyalty_limit/i18n/sale_coupon_limit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_coupon_limit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.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_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_coupon
msgid "Coupon"
msgstr ""

#. module: sale_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_rule
msgid "Coupon Rule"
msgstr ""

#. module: sale_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_rule_salesmen_limit
msgid "Coupon Rule Salesmen limits"
msgstr ""

#. module: sale_coupon_limit
#: model:ir.model,name:sale_coupon_limit.model_coupon_program
msgid "Coupon display on a website"
msgstr ""

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid ""
"This promo code was already applied %(count)s times for this customer and "
"there's an stablished limit of %(max)s for this promotion."
msgstr ""

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid ""
"This promo code was already applied %(times)s times for this salesman and "
"there's an stablished limit of %(max)s for this promotion."
msgstr ""

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_coupon.py:0
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid "This promotion is restricted to the listed salesmen."
msgstr ""

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_coupon.py:0
#: code:addons/sale_coupon_limit/models/coupon_program.py:0
#, python-format
msgid ""
"This promotion was already applied %(count)s times for this customer and "
"there's an stablished limit of %(max)s."
msgstr ""

#. module: sale_coupon_limit
#: code:addons/sale_coupon_limit/models/coupon_coupon.py:0
#, python-format
msgid ""
"This promotion was already applied %(times)s times for this salesman and "
"there's an stablished limit of %(max)s."
msgstr ""
2 changes: 2 additions & 0 deletions sale_loyalty_limit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import loyalty_program
from . import sale_order
51 changes: 51 additions & 0 deletions sale_loyalty_limit/models/loyalty_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


class LoyaltyProgram(models.Model):
_inherit = "loyalty.program"

def _compute_salesmen_limit_count(self):
"""This count is merely informative"""
res = super()._compute_salesmen_limit_count()

Check warning on line 11 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L11

Added line #L11 was not covered by tests
for program in self:
program.salesmen_limit_count = sum(

Check warning on line 13 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L13

Added line #L13 was not covered by tests
program.salesmen_limit_ids.mapped("max_salesman_application")
)
program.salesmen_limit_used_count = sum(

Check warning on line 16 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L16

Added line #L16 was not covered by tests
program.salesmen_limit_ids.mapped("times_used")
)
return res

Check warning on line 19 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L19

Added line #L19 was not covered by tests


class LoyaltySalesmenLimit(models.Model):
_inherit = "loyalty.salesmen.limit"

def _compute_times_used(self):
res = super()._compute_times_used()
programs = self.env["loyalty.program"].search_read(

Check warning on line 27 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L26-L27

Added lines #L26 - L27 were not covered by tests
[("id", "in", self.mapped("program_id").ids)],
["id", "program_type", "coupon_ids", "salesmen_limit_ids"],
)
for program in programs:
salesmen_limits = self.filtered(
lambda x: x._origin in program["salesmen_limit_ids"]
)
for salesman_limit in salesmen_limits:
salesman_limit.times_used = len(

Check warning on line 36 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L36

Added line #L36 was not covered by tests
self.env["sale.order.line"].read_group(
[
("loyalty_program_id", "=", program["id"]),
(
"order_id.user_id",
"=",
salesman_limit.user_id.id,
),
("order_id.state", "!=", "cancel"),
],
["order_id"],
["order_id"],
)
)
return res

Check warning on line 51 in sale_loyalty_limit/models/loyalty_program.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_limit/models/loyalty_program.py#L51

Added line #L51 was not covered by tests
Loading
Loading