mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
Merge pull request #40504 from khushi8112/selling-coupon-code
feat: Coupon code in sales invoice
This commit is contained in:
@@ -736,7 +736,6 @@ def get_pricing_rule_items(pr_doc, other_items=False) -> list:
|
|||||||
|
|
||||||
def validate_coupon_code(coupon_name):
|
def validate_coupon_code(coupon_name):
|
||||||
coupon = frappe.get_doc("Coupon Code", coupon_name)
|
coupon = frappe.get_doc("Coupon Code", coupon_name)
|
||||||
|
|
||||||
if coupon.valid_from:
|
if coupon.valid_from:
|
||||||
if coupon.valid_from > getdate(today()):
|
if coupon.valid_from > getdate(today()):
|
||||||
frappe.throw(_("Sorry, this coupon code's validity has not started"))
|
frappe.throw(_("Sorry, this coupon code's validity has not started"))
|
||||||
|
|||||||
@@ -90,6 +90,7 @@
|
|||||||
"section_break_49",
|
"section_break_49",
|
||||||
"apply_discount_on",
|
"apply_discount_on",
|
||||||
"base_discount_amount",
|
"base_discount_amount",
|
||||||
|
"coupon_code",
|
||||||
"is_cash_or_non_trade_discount",
|
"is_cash_or_non_trade_discount",
|
||||||
"additional_discount_account",
|
"additional_discount_account",
|
||||||
"column_break_51",
|
"column_break_51",
|
||||||
@@ -2173,6 +2174,12 @@
|
|||||||
"label": "Don't Create Loyalty Points",
|
"label": "Don't Create Loyalty Points",
|
||||||
"no_copy": 1
|
"no_copy": 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "coupon_code",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Coupon Code",
|
||||||
|
"options": "Coupon Code"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"default": "1",
|
"default": "1",
|
||||||
"depends_on": "eval: doc.is_return && doc.return_against",
|
"depends_on": "eval: doc.is_return && doc.return_against",
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
|
|||||||
get_loyalty_program_details_with_points,
|
get_loyalty_program_details_with_points,
|
||||||
validate_loyalty_points,
|
validate_loyalty_points,
|
||||||
)
|
)
|
||||||
|
from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||||
|
update_coupon_code_count,
|
||||||
|
validate_coupon_code,
|
||||||
|
)
|
||||||
from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger import (
|
from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger import (
|
||||||
validate_docs_for_deferred_accounting,
|
validate_docs_for_deferred_accounting,
|
||||||
validate_docs_for_voucher_types,
|
validate_docs_for_voucher_types,
|
||||||
@@ -106,6 +110,7 @@ class SalesInvoice(SellingController):
|
|||||||
contact_person: DF.Link | None
|
contact_person: DF.Link | None
|
||||||
conversion_rate: DF.Float
|
conversion_rate: DF.Float
|
||||||
cost_center: DF.Link | None
|
cost_center: DF.Link | None
|
||||||
|
coupon_code: DF.Link | None
|
||||||
currency: DF.Link
|
currency: DF.Link
|
||||||
customer: DF.Link | None
|
customer: DF.Link | None
|
||||||
customer_address: DF.Link | None
|
customer_address: DF.Link | None
|
||||||
@@ -294,6 +299,10 @@ class SalesInvoice(SellingController):
|
|||||||
self.doctype, self.customer, self.company, self.inter_company_invoice_reference
|
self.doctype, self.customer, self.company, self.inter_company_invoice_reference
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Validating coupon code
|
||||||
|
if self.coupon_code:
|
||||||
|
validate_coupon_code(self.coupon_code)
|
||||||
|
|
||||||
if cint(self.is_pos):
|
if cint(self.is_pos):
|
||||||
self.validate_pos()
|
self.validate_pos()
|
||||||
|
|
||||||
@@ -473,6 +482,9 @@ class SalesInvoice(SellingController):
|
|||||||
self.update_project()
|
self.update_project()
|
||||||
update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference)
|
update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference)
|
||||||
|
|
||||||
|
if self.coupon_code:
|
||||||
|
update_coupon_code_count(self.coupon_code, "used")
|
||||||
|
|
||||||
# create the loyalty point ledger entry if the customer is enrolled in any loyalty program
|
# create the loyalty point ledger entry if the customer is enrolled in any loyalty program
|
||||||
if (
|
if (
|
||||||
not self.is_return
|
not self.is_return
|
||||||
@@ -563,6 +575,9 @@ class SalesInvoice(SellingController):
|
|||||||
self.db_set("status", "Cancelled")
|
self.db_set("status", "Cancelled")
|
||||||
self.db_set("repost_required", 0)
|
self.db_set("repost_required", 0)
|
||||||
|
|
||||||
|
if self.coupon_code:
|
||||||
|
update_coupon_code_count(self.coupon_code, "cancelled")
|
||||||
|
|
||||||
if (
|
if (
|
||||||
frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction"
|
frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction"
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user