diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 72ad0d096bc0..73cb24838118 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -451,6 +451,16 @@ def get_pricing_rule_for_item(args, doc=None, for_validate=False): get_pricing_rule_items(pricing_rule, other_items=fetch_other_item) or [] ) + if pricing_rule.coupon_code_based == 1: + if not args.coupon_code: + return item_details + + coupon_code = frappe.db.get_value( + doctype="Coupon Code", filters={"pricing_rule": pricing_rule.name}, fieldname="name" + ) + if args.coupon_code != coupon_code: + continue + if pricing_rule.get("suggestion"): continue @@ -476,9 +486,6 @@ def get_pricing_rule_for_item(args, doc=None, for_validate=False): pricing_rule.apply_rule_on_other_items ) - if pricing_rule.coupon_code_based == 1 and args.coupon_code is None: - return item_details - if not pricing_rule.validate_applied_rule: if pricing_rule.price_or_product_discount == "Price": apply_price_discount_rule(pricing_rule, item_details, args)