From 10604664d403ae272542e7a85f14eeb88bea36c0 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 19 Jul 2020 21:20:28 +0530 Subject: [PATCH 1/3] fix: Error due to commma in Pricing rule name --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 6 ++++-- erpnext/accounts/doctype/pricing_rule/utils.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index b7c6d4a9728..fcc467536d2 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -247,7 +247,9 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa if pricing_rules: rules = [] + print(pricing_rules, "$$$$$$") for pricing_rule in pricing_rules: + print(pricing_rule) if not pricing_rule: continue if isinstance(pricing_rule, string_types): @@ -280,7 +282,7 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa item_details.has_pricing_rule = 1 - item_details.pricing_rules = ','.join([d.pricing_rule for d in rules]) + item_details.pricing_rules = frappe.as_json([d.pricing_rule for d in rules]) if not doc: return item_details @@ -370,7 +372,7 @@ def set_discount_amount(rate, item_details): def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None): from erpnext.accounts.doctype.pricing_rule.utils import get_pricing_rule_items - for d in pricing_rules.split(','): + for d in json.loads(pricing_rules): if not d or not frappe.db.exists("Pricing Rule", d): continue pricing_rule = frappe.get_cached_doc('Pricing Rule', d) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index dc27cfb3342..7d20208fc79 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -471,7 +471,7 @@ def apply_pricing_rule_on_transaction(doc): doc.set_missing_values() def get_applied_pricing_rules(item_row): - return (item_row.get("pricing_rules").split(',') + return (json.loads(item_row.get("pricing_rules")) if item_row.get("pricing_rules") else []) def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): From 579167d1ded5ed788428e94654a388744701bd10 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 19 Jul 2020 21:40:33 +0530 Subject: [PATCH 2/3] fix: Remove print statement --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index fcc467536d2..bb4f5bc602c 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -247,9 +247,7 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa if pricing_rules: rules = [] - print(pricing_rules, "$$$$$$") for pricing_rule in pricing_rules: - print(pricing_rule) if not pricing_rule: continue if isinstance(pricing_rule, string_types): From b3cdd91d65cd731c0d458d5225320826cd45d655 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 20 Jul 2020 10:12:17 +0530 Subject: [PATCH 3/3] fix: Tests --- erpnext/controllers/taxes_and_totals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 82f820c4252..7534bf43a69 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -593,7 +593,7 @@ class calculate_taxes_and_totals(object): base_rate_with_margin = 0.0 if item.price_list_rate: if item.pricing_rules and not self.doc.ignore_pricing_rule: - for d in item.pricing_rules.split(','): + for d in json.loads(item.pricing_rules): pricing_rule = frappe.get_cached_doc('Pricing Rule', d) if (pricing_rule.margin_type == 'Amount' and pricing_rule.currency == self.doc.currency)\