From a0247d11bda083dc25ec64ab35cc27b6bfefd4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CKhushi?= <“khushirawat.sophia@gamil.com”> Date: Thu, 14 Mar 2024 12:04:09 +0530 Subject: [PATCH] feat: added coupon code functionality onsales invoice --- erpnext/accounts/doctype/pricing_rule/utils.py | 4 ++-- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index d4f634a99d1..8ae2eb704c6 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -740,10 +740,10 @@ def validate_coupon_code(coupon_name): if coupon.valid_from: if coupon.valid_from > getdate(today()): frappe.throw(_("Sorry, this coupon code's validity has not started")) - if coupon.valid_upto: + elif coupon.valid_upto: if coupon.valid_upto < getdate(today()): frappe.throw(_("Sorry, this coupon code's validity has expired")) - if coupon.used >= coupon.maximum_use: + elif coupon.used >= coupon.maximum_use: frappe.throw(_("Sorry, this coupon code is no longer valid")) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 6990310b59b..872327f12bb 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -271,6 +271,8 @@ class SalesInvoice(SellingController): validate_inter_company_party( self.doctype, self.customer, self.company, self.inter_company_invoice_reference ) + + # Validating coupon code if self.coupon_code: validate_coupon_code(self.coupon_code)