diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 09feb7d97bc..27541670a89 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -31,13 +31,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_name = [] + pricing_rules = [] + for p in pricing_rules_all: + if p['name'] not in pricing_rules_name: + pricing_rules_name.append(p['name']) + pricing_rules.append(p) rules = [] @@ -323,9 +329,10 @@ def apply_internal_priority(pricing_rules, field_set, args): filtered_rules = [] for field in field_set: if args.get(field): - # filter function always returns a filter object even if empty - # list conversion is necessary to check for an empty result - filtered_rules = list(filter(lambda x: x.get(field)==args.get(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