From b4a93da9f3d69c2f45525ba8b41e7def08c74944 Mon Sep 17 00:00:00 2001 From: Jingxuan He Date: Thu, 16 Jun 2022 08:46:59 +0200 Subject: [PATCH] chore: Fix a potential variable misuse bug (#31372) * Fix a potential variable misuse bug * chore: Separate check (separate line) for empty table in Pricing Rule * chore: Code readability & check for field in row (now row itself) Co-authored-by: marination --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 2438f4b1ab..98e0a9b215 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -36,8 +36,12 @@ class PricingRule(Document): def validate_duplicate_apply_on(self): if self.apply_on != "Transaction": - field = apply_on_dict.get(self.apply_on) - values = [d.get(frappe.scrub(self.apply_on)) for d in self.get(field) if field] + apply_on_table = apply_on_dict.get(self.apply_on) + if not apply_on_table: + return + + apply_on_field = frappe.scrub(self.apply_on) + values = [d.get(apply_on_field) for d in self.get(apply_on_table) if d.get(apply_on_field)] if len(values) != len(set(values)): frappe.throw(_("Duplicate {0} found in the table").format(self.apply_on))