Skip to content

Commit

Permalink
[MIG] sale_coupon_limit: Renamed to sale_loyalty_limit + Migration to…
Browse files Browse the repository at this point in the history
… 16.0

TT44347
  • Loading branch information
pilarvargas-tecnativa committed Nov 20, 2023
1 parent d174851 commit 2f1901d
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 341 deletions.
19 changes: 10 additions & 9 deletions sale_loyalty_limit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Coupon Limit
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:527843ce58639698397e9681ecf8ad8a61f1fdb38acfa103dae0c7efc4043f5d
!! source digest: sha256:7ee02c35cf9a86ded5ad53c98fdab3dc5f7b78725d4177bfc9918188e8c7351f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand All @@ -17,13 +17,13 @@ Coupon Limit
: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_limit
: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-15-0/sale-promotion-15-0-sale_coupon_limit
: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=15.0
: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|
Expand All @@ -42,16 +42,16 @@ Configuration

To configure customer limits:

#. Go to *Sales > Catalog > Coupon Programs* and select or create a new one.
#. Set the *Maximum Customer Applications* to the number of times a coupon can be used
#. 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 > Catalog > Coupon Programs* and select or create a new one.
#. 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
Expand All @@ -75,7 +75,7 @@ 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_coupon_limit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`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.

Expand All @@ -94,6 +94,7 @@ Contributors

* Pedro M. Baeza
* David Vidal
* Pilar Vargas

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

Expand All @@ -120,6 +121,6 @@ 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/15.0/sale_coupon_limit>`_ project on GitHub.
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.
6 changes: 3 additions & 3 deletions sale_loyalty_limit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
{
"name": "Coupon Limit",
"summary": "Restrict number of promotions per customer or salesman",
"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": [
"coupon_limit",
"loyalty_limit",
"sale_commercial_partner",
"sale_coupon_order_line_link",
"sale_loyalty_order_line_link",
],
"data": ["security/ir.model.access.csv"],
}
5 changes: 2 additions & 3 deletions sale_loyalty_limit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import coupon_coupon
from . import coupon_program
from . import coupon_rule
from . import loyalty_program
from . import sale_order
63 changes: 0 additions & 63 deletions sale_loyalty_limit/models/coupon_coupon.py

This file was deleted.

70 changes: 0 additions & 70 deletions sale_loyalty_limit/models/coupon_program.py

This file was deleted.

78 changes: 0 additions & 78 deletions sale_loyalty_limit/models/coupon_rule.py

This file was deleted.

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()
for program in self:
program.salesmen_limit_count = sum(
program.salesmen_limit_ids.mapped("max_salesman_application")
)
program.salesmen_limit_used_count = sum(
program.salesmen_limit_ids.mapped("times_used")
)
return res


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(
[("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(
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
Loading

0 comments on commit 2f1901d

Please sign in to comment.