From 068dc4ec136ec9dc2d9348a626aa35192c7604b1 Mon Sep 17 00:00:00 2001 From: MohamedAliSmk Date: Mon, 20 Jul 2026 15:21:49 +0300 Subject: [PATCH] feat: enhance coupon validation and customer selection in CouponDialog Updated the coupon validation logic to ensure a customer is selected before applying a coupon. Added a default empty string for the customer prop in the CouponDialog component and improved error handling to prompt the user if no customer is chosen. --- POS/src/components/sale/CouponDialog.vue | 8 +++++++- pos_next/api/offers.py | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/POS/src/components/sale/CouponDialog.vue b/POS/src/components/sale/CouponDialog.vue index 65ab34de4..5bd946710 100644 --- a/POS/src/components/sale/CouponDialog.vue +++ b/POS/src/components/sale/CouponDialog.vue @@ -300,7 +300,7 @@ const couponResource = createResource({ makeParams() { return { coupon_code: couponCode.value, - customer: props.customer, + customer: props.customer || "", company: props.company, }; }, @@ -361,6 +361,12 @@ async function applyCoupon() { return; } + if (!props.customer) { + errorMessage.value = __("Please choose a customer"); + showError(errorMessage.value); + return; + } + applying.value = true; errorMessage.value = ""; diff --git a/pos_next/api/offers.py b/pos_next/api/offers.py index 70b48bf27..b219ab230 100644 --- a/pos_next/api/offers.py +++ b/pos_next/api/offers.py @@ -602,8 +602,11 @@ def get_active_coupons(customer: str, company: str) -> list[dict]: @frappe.whitelist() -def validate_coupon(coupon_code: str, customer: str, company: str) -> dict: +def validate_coupon(coupon_code: str, company: str, customer: str | None = None) -> dict: """Validate a coupon code and return its details""" + if not customer: + return {"valid": False, "message": _("Please choose a customer")} + if not frappe.db.table_exists("POS Coupon"): return {"valid": False, "message": _("Coupons are not enabled")}