From 2976e56d2335acf3ceb5d76980e8658fa65dace1 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 12 Dec 2016 18:34:56 +0530 Subject: [PATCH] [Fix] Ignore pricing rule not removed the discount percentage --- .../accounts/doctype/pricing_rule/pricing_rule.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index f298bc88f91..b36898a8078 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -126,6 +126,8 @@ def get_pricing_rule_for_item(args): }) if args.ignore_pricing_rule or not args.item_code: + if args.name and args.get("pricing_rule"): + item_details = remove_pricing_rule(args, item_details) return item_details if not (args.item_group and args.brand): @@ -166,9 +168,16 @@ def get_pricing_rule_for_item(args): else: item_details.discount_percentage = pricing_rule.discount_percentage elif args.get('pricing_rule'): - if frappe.db.get_value('Pricing Rule', args.get('pricing_rule'), 'price_or_discount') == 'Discount Percentage': - item_details.discount_percentage = 0.0 + item_details = remove_pricing_rule(args, item_details) + return item_details + +def remove_pricing_rule(args, item_details): + pricing_rule = frappe.db.get_value('Pricing Rule', args.get('pricing_rule'), ['price_or_discount', 'margin_type'], as_dict=1) + if pricing_rule and pricing_rule.price_or_discount == 'Discount Percentage': + item_details.discount_percentage = 0.0 + + if pricing_rule and pricing_rule.margin_type in ['Percentage', 'Amount']: item_details.margin_rate_or_amount = 0.0 item_details.margin_type = None