mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-24 17:25:39 +00:00
fix: only highest eligible coupon applied (#38416)
fix: only highest eligible coupon applied (#38416)
* fix: application of pricing rule when coupon is used
(cherry picked from commit d34787cf6d)
Co-authored-by: sandratridz <102575830+sandratridz@users.noreply.github.com>
This commit is contained in:
@@ -581,6 +581,8 @@ def apply_pricing_rule_on_transaction(doc):
|
|||||||
if d.price_or_product_discount == "Price":
|
if d.price_or_product_discount == "Price":
|
||||||
if d.apply_discount_on:
|
if d.apply_discount_on:
|
||||||
doc.set("apply_discount_on", d.apply_discount_on)
|
doc.set("apply_discount_on", d.apply_discount_on)
|
||||||
|
# Variable to track whether the condition has been met
|
||||||
|
condition_met = False
|
||||||
|
|
||||||
for field in ["additional_discount_percentage", "discount_amount"]:
|
for field in ["additional_discount_percentage", "discount_amount"]:
|
||||||
pr_field = "discount_percentage" if field == "additional_discount_percentage" else field
|
pr_field = "discount_percentage" if field == "additional_discount_percentage" else field
|
||||||
@@ -603,6 +605,11 @@ def apply_pricing_rule_on_transaction(doc):
|
|||||||
if coupon_code_pricing_rule == d.name:
|
if coupon_code_pricing_rule == d.name:
|
||||||
# if selected coupon code is linked with pricing rule
|
# if selected coupon code is linked with pricing rule
|
||||||
doc.set(field, d.get(pr_field))
|
doc.set(field, d.get(pr_field))
|
||||||
|
|
||||||
|
# Set the condition_met variable to True and break out of the loop
|
||||||
|
condition_met = True
|
||||||
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# reset discount if not linked
|
# reset discount if not linked
|
||||||
doc.set(field, 0)
|
doc.set(field, 0)
|
||||||
@@ -611,6 +618,10 @@ def apply_pricing_rule_on_transaction(doc):
|
|||||||
doc.set(field, 0)
|
doc.set(field, 0)
|
||||||
|
|
||||||
doc.calculate_taxes_and_totals()
|
doc.calculate_taxes_and_totals()
|
||||||
|
|
||||||
|
# Break out of the main loop if the condition is met
|
||||||
|
if condition_met:
|
||||||
|
break
|
||||||
elif d.price_or_product_discount == "Product":
|
elif d.price_or_product_discount == "Product":
|
||||||
item_details = frappe._dict({"parenttype": doc.doctype, "free_item_data": []})
|
item_details = frappe._dict({"parenttype": doc.doctype, "free_item_data": []})
|
||||||
get_product_discount_rule(d, item_details, doc=doc)
|
get_product_discount_rule(d, item_details, doc=doc)
|
||||||
|
|||||||
Reference in New Issue
Block a user