From 9831c5beca7b0c2a4000210a582136157f1dbb41 Mon Sep 17 00:00:00 2001 From: Poranut Chollavorn Date: Tue, 9 Jun 2020 15:06:44 +0000 Subject: [PATCH 1/2] fix(loyalty): loyalty point entry use wrong tier --- .../doctype/loyalty_program/loyalty_program.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/loyalty_program/loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/loyalty_program.py index 563165b2cc8..6a82572a8d8 100644 --- a/erpnext/accounts/doctype/loyalty_program/loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/loyalty_program.py @@ -41,10 +41,16 @@ def get_loyalty_program_details_with_points(customer, loyalty_program=None, expi loyalty_program = frappe.get_doc("Loyalty Program", loyalty_program) lp_details.update(get_loyalty_details(customer, loyalty_program.name, expiry_date, company, include_expired_entry)) - tier_spent_level = sorted([d.as_dict() for d in loyalty_program.collection_rules], - key=lambda rule:rule.min_spent, reverse=True) + # sort collection rule, first item on list will be lowest min_spent + tier_spent_level = sorted( + [d.as_dict() for d in loyalty_program.collection_rules], + key=lambda rule: rule.min_spent, reverse=False, + ) + + # looping and apply tier from highest min_spent for i, d in enumerate(tier_spent_level): - if i==0 or (lp_details.total_spent+current_transaction_amount) <= d.min_spent: + # if cumulative spend more than min_spent then continue to next tier + if (lp_details.total_spent + current_transaction_amount) >= d.min_spent: lp_details.tier_name = d.tier_name lp_details.collection_factor = d.collection_factor else: From 5a5361815fc7c7152da81f47a038fda9aa7334a6 Mon Sep 17 00:00:00 2001 From: Poranut Chollavorn Date: Tue, 9 Jun 2020 15:16:28 +0000 Subject: [PATCH 2/2] docs(loyalty): fix wrong comment --- erpnext/accounts/doctype/loyalty_program/loyalty_program.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/loyalty_program/loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/loyalty_program.py index 6a82572a8d8..d2d852229e2 100644 --- a/erpnext/accounts/doctype/loyalty_program/loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/loyalty_program.py @@ -47,7 +47,7 @@ def get_loyalty_program_details_with_points(customer, loyalty_program=None, expi key=lambda rule: rule.min_spent, reverse=False, ) - # looping and apply tier from highest min_spent + # looping and apply tier from lowest min_spent for i, d in enumerate(tier_spent_level): # if cumulative spend more than min_spent then continue to next tier if (lp_details.total_spent + current_transaction_amount) >= d.min_spent: