fix: Error due to comma in Pricing rule name (#22741)
* fix: Error due to commma in Pricing rule name
* fix: Remove print statement
* fix: Tests
Co-authored-by: Marica <maricadsouza221197@gmail.com>
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index d4d83af..d90ae28 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -276,7 +276,7 @@
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
@@ -366,7 +366,7 @@
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 ad98383..3fd316f 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -448,7 +448,7 @@
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):
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index a9eb996..6449c71 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -597,7 +597,7 @@
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)\