-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] sale_coupon_limit: Renamed to sale_loyalty_limit + Migration to…
… 16.0 TT44347
- Loading branch information
1 parent
d174851
commit 2f1901d
Showing
17 changed files
with
297 additions
and
341 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
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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from . import coupon_coupon | ||
from . import coupon_program | ||
from . import coupon_rule | ||
from . import loyalty_program | ||
from . import sale_order |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 |
Oops, something went wrong.