diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 53f900fbf2..e915618f4c 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -32,6 +32,7 @@ class PricingRule(Document): self.validate_max_discount() self.validate_price_list_with_currency() self.validate_dates() + validate_condition(self) if not self.margin_type: self.margin_rate_or_amount = 0.0 @@ -144,13 +145,13 @@ class PricingRule(Document): def validate_condition(pricing_rule, doc=None): if pricing_rule.condition and ("=" in pricing_rule.condition) and re.match("""[\w\.:_]+\s*={1}\s*[\w\.@'"]+""", pricing_rule.condition): - frappe.throw(_("Invalid condition in Pricing Rule: {0}").format(pricing_rule.name), frappe.ValidationError) - elif pricing_rule.condition: + frappe.throw(_("Invalid condition in Pricing Rule - {0}").format(pricing_rule.name), frappe.ValidationError) + elif doc: try: - doc = doc.as_dict() - return frappe.safe_eval(pricing_rule.condition, None, doc) + return frappe.safe_eval(pricing_rule.condition, None, doc.as_dict()) except Exception as e: - frappe.throw(" Pricing Rule - " + pricing_rule.name + " - 'Condition' field error:
" + str(e).capitalize() ) + frappe.msgprint(_("Pricing Rule - " + pricing_rule.name + " - condition field error:
" + \ + str(e).capitalize() + "

Ignoring Pricing Rule"), indicator="orange", title=_("Warning")) return False return True #--------------------------------------------------------------------------------