-
-
Notifications
You must be signed in to change notification settings - Fork 64
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_criteria_multi_product: Migration to 16.0 and renam…
…e to sale_loyalty_criteria_multi_product
- Loading branch information
1 parent
c71d3cc
commit b5ee08e
Showing
15 changed files
with
115 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# Copyright 2021 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Coupons multi product criteria in sale", | ||
"name": "Loyalty multi product criteria in sale", | ||
"summary": "Allows to set as promotion criteria multi-product conditions", | ||
"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_criteria_multi_product", "sale_coupon"], | ||
"depends": ["loyalty_criteria_multi_product", "sale_loyalty"], | ||
} |
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 +1,2 @@ | ||
from . import coupon_program | ||
from . import loyalty_program | ||
from . import sale_order |
60 changes: 0 additions & 60 deletions
60
sale_loyalty_criteria_multi_product/models/coupon_program.py
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
sale_loyalty_criteria_multi_product/models/loyalty_program.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,16 @@ | ||
# 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 _get_valid_products_multi_product(self, products, rule): | ||
"""Return valid products depending on the rule repeat product setting. Then | ||
the main method will check if the minimum quantities are acomplished.""" | ||
if rule.repeat_product: | ||
return products.browse([x.id for x in rule.product_ids if x in products]) | ||
if not all([x in products for x in rule.product_ids]): | ||
return self.env["product.product"] | ||
return rule.product_ids |
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,61 @@ | ||
# Copyright 2021 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
def _program_check_compute_points(self, programs): | ||
""" | ||
Updates applied programs's given points with the current state of the order. | ||
Checks automatic programs for applicability. | ||
Updates applied rewards using the new points and the current state of the order | ||
(for example with % discounts). | ||
""" | ||
self.ensure_one() | ||
domain_programs = programs.filtered(lambda x: x.loyalty_criteria == "domain") | ||
multi_product_programs = (programs - domain_programs).filtered( | ||
"loyalty_criteria_ids" | ||
) | ||
# We'll return them altogether | ||
valid_domain_criteria_programs = super()._program_check_compute_points( | ||
domain_programs | ||
) | ||
order_lines = self.order_line.filtered( | ||
lambda line: line.product_id | ||
) - self.order_line.filtered("is_reward_line") | ||
products = order_lines.mapped("product_id") | ||
products_qties = dict.fromkeys(products, 0) | ||
for line in order_lines: | ||
products_qties[line.product_id] += line.product_uom_qty | ||
valid_multi_product_criteria_programs = dict.fromkeys( | ||
multi_product_programs, dict() | ||
) | ||
|
||
for program in multi_product_programs: | ||
criterias_are_valid = True | ||
for criteria in program.loyalty_criteria_ids: | ||
valid_products = program._get_valid_products_multi_product( | ||
products, criteria | ||
) | ||
if not valid_products: | ||
criterias_are_valid = False | ||
ordered_rule_products_qty = sum( | ||
products_qties[p] for p in valid_products | ||
) | ||
if ordered_rule_products_qty < criteria.criterian_min_quantity: | ||
criterias_are_valid = False | ||
if not criterias_are_valid: | ||
valid_multi_product_criteria_programs[program] = { | ||
"error": "You don't have the required " | ||
"product quantities on your sales order." | ||
} | ||
else: | ||
# bypass: forced the points of program | ||
# because the original function takes this from rules | ||
valid_multi_product_criteria_programs[program] = {"points": [1]} | ||
return { | ||
**valid_domain_criteria_programs, | ||
**valid_multi_product_criteria_programs, | ||
} |
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,2 +1,2 @@ | ||
Module that extends from *coupon_criteria_multi_product* and allows to | ||
Module that extends from *loyalty_criteria_multi_product* and allows to | ||
use it's configuration in sale orders. |
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 +1 @@ | ||
from . import test_sale_coupon_criteria_multi_product | ||
from . import test_sale_loyalty_criteria_multi_product |
Oops, something went wrong.