refactor: validation to prevent recursion with mixed conditions
This commit is contained in:
@@ -139,6 +139,7 @@ class PricingRule(Document):
|
|||||||
self.validate_price_list_with_currency()
|
self.validate_price_list_with_currency()
|
||||||
self.validate_dates()
|
self.validate_dates()
|
||||||
self.validate_condition()
|
self.validate_condition()
|
||||||
|
self.validate_mixed_with_recursion()
|
||||||
|
|
||||||
if not self.margin_type:
|
if not self.margin_type:
|
||||||
self.margin_rate_or_amount = 0.0
|
self.margin_rate_or_amount = 0.0
|
||||||
@@ -308,6 +309,10 @@ class PricingRule(Document):
|
|||||||
):
|
):
|
||||||
frappe.throw(_("Invalid condition expression"))
|
frappe.throw(_("Invalid condition expression"))
|
||||||
|
|
||||||
|
def validate_mixed_with_recursion(self):
|
||||||
|
if self.mixed_conditions and self.is_recursive:
|
||||||
|
frappe.throw(_("Recursive Discounts with Mixed condition is not supported by the system"))
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ class PromotionalScheme(Document):
|
|||||||
|
|
||||||
self.validate_applicable_for()
|
self.validate_applicable_for()
|
||||||
self.validate_pricing_rules()
|
self.validate_pricing_rules()
|
||||||
|
self.validate_mixed_with_recursion()
|
||||||
|
|
||||||
def validate_applicable_for(self):
|
def validate_applicable_for(self):
|
||||||
if self.applicable_for:
|
if self.applicable_for:
|
||||||
@@ -177,6 +178,7 @@ class PromotionalScheme(Document):
|
|||||||
frappe.delete_doc("Pricing Rule", docname.name)
|
frappe.delete_doc("Pricing Rule", docname.name)
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
|
self.validate()
|
||||||
pricing_rules = (
|
pricing_rules = (
|
||||||
frappe.get_all(
|
frappe.get_all(
|
||||||
"Pricing Rule",
|
"Pricing Rule",
|
||||||
@@ -188,6 +190,15 @@ class PromotionalScheme(Document):
|
|||||||
)
|
)
|
||||||
self.update_pricing_rules(pricing_rules)
|
self.update_pricing_rules(pricing_rules)
|
||||||
|
|
||||||
|
def validate_mixed_with_recursion(self):
|
||||||
|
if self.mixed_conditions:
|
||||||
|
if self.product_discount_slabs:
|
||||||
|
for slab in self.product_discount_slabs:
|
||||||
|
if slab.is_recursive:
|
||||||
|
frappe.throw(
|
||||||
|
_("Recursive Discounts with Mixed condition is not supported by the system")
|
||||||
|
)
|
||||||
|
|
||||||
def update_pricing_rules(self, pricing_rules):
|
def update_pricing_rules(self, pricing_rules):
|
||||||
rules = {}
|
rules = {}
|
||||||
count = 0
|
count = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user