From 66806ff1b067e9f0dee38456f3e33f777ad7f078 Mon Sep 17 00:00:00 2001 From: Poranut Chollavorn Date: Thu, 18 Jun 2020 13:43:15 +0000 Subject: [PATCH 1/3] fix(pricing_rules): rule won't got use across [item_code, item_group, brands] --- erpnext/accounts/doctype/pricing_rule/utils.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 9876246c47b..fa43e70c2d5 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -30,13 +30,19 @@ apply_on_table = { } def get_pricing_rules(args, doc=None): - pricing_rules = [] - values = {} + pricing_rules_all = [] + values = {} for apply_on in ['Item Code', 'Item Group', 'Brand']: - pricing_rules.extend(_get_pricing_rules(apply_on, args, values)) - if pricing_rules and not apply_multiple_pricing_rules(pricing_rules): - break + pricing_rules_all.extend(_get_pricing_rules(apply_on, args, values)) + + # removing duplicate pricing rule + pricing_rules_title = [] + pricing_rules = [] + for p in pricing_rules_all: + if p['title'] not in pricing_rules_title: + pricing_rules_title.append(p['title']) + pricing_rules.append(p) rules = [] From 850c0ff1212adaa416c861ae1f734a6d11115821 Mon Sep 17 00:00:00 2001 From: Poranut Chollavorn Date: Mon, 22 Jun 2020 07:24:33 +0000 Subject: [PATCH 2/3] fix(pricing_rule): key error on apply_internal_priority apply_internal_priority never check if pricing rule have field --- erpnext/accounts/doctype/pricing_rule/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index fa43e70c2d5..238b37db356 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -328,7 +328,10 @@ def apply_internal_priority(pricing_rules, field_set, args): filtered_rules = [] for field in field_set: if args.get(field): - filtered_rules = filter(lambda x: x[field]==args[field], pricing_rules) + for rule in pricing_rules: + if rule.get(field) == args.get(field): + filtered_rules = [rule] + break if filtered_rules: break return filtered_rules or pricing_rules From 303639db764672ba9347475419c347aad6d06e02 Mon Sep 17 00:00:00 2001 From: Poranut Chollavorn Date: Mon, 22 Jun 2020 10:24:40 +0000 Subject: [PATCH 3/3] fix: use name instead of title --- erpnext/accounts/doctype/pricing_rule/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 238b37db356..f30d0bcaa62 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -37,11 +37,11 @@ def get_pricing_rules(args, doc=None): pricing_rules_all.extend(_get_pricing_rules(apply_on, args, values)) # removing duplicate pricing rule - pricing_rules_title = [] + pricing_rules_name = [] pricing_rules = [] for p in pricing_rules_all: - if p['title'] not in pricing_rules_title: - pricing_rules_title.append(p['title']) + if p['name'] not in pricing_rules_name: + pricing_rules_name.append(p['name']) pricing_rules.append(p) rules = []