From 68b052bdbb53a9319388cb7a2d2098f47c4d07ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CKhushi?= <“khushirawat.sophia@gamil.com”> Date: Wed, 13 Mar 2024 17:47:40 +0530 Subject: [PATCH 1/3] feat: Coupon code in sales invoice --- .../doctype/sales_invoice/sales_invoice.json | 19 ++++++++++++++++++- .../doctype/sales_invoice/sales_invoice.py | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index e55462c8b3..0eee55f135 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -96,6 +96,7 @@ "section_break_49", "apply_discount_on", "base_discount_amount", + "coupon_code", "is_cash_or_non_trade_discount", "additional_discount_account", "column_break_51", @@ -1899,6 +1900,22 @@ "label": "Don't Create Loyalty Points", "no_copy": 1 }, + { + "fieldname": "coupon_code", + "fieldtype": "Link", + "label": "Coupon Code", + "options": "Coupon Code" + }, + { + "default": "1", + "depends_on": "eval: doc.is_return && doc.return_against", + "description": "Credit Note will update it's own outstanding amount, even if \"Return Against\" is specified.", + "fieldname": "update_outstanding_for_self", + "fieldtype": "Check", + "label": "Update Outstanding for Self", + "no_copy": 1, + "print_hide": 1 + }, { "fieldname": "accounting_journal", "fieldtype": "Link", @@ -1927,7 +1944,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2024-05-08 18:02:28.549041", + "modified": "2024-04-16 16:27:05.980674", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index eb5904d233..32688e9c89 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -15,6 +15,10 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_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 ( validate_docs_for_deferred_accounting, validate_docs_for_voucher_types, @@ -111,6 +115,7 @@ class SalesInvoice(SellingController): contact_person: DF.Link | None conversion_rate: DF.Float cost_center: DF.Link | None + coupon_code: DF.Link | None currency: DF.Link customer: DF.Link | None customer_address: DF.Link | None @@ -304,6 +309,10 @@ class SalesInvoice(SellingController): 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): self.validate_pos() @@ -494,6 +503,9 @@ class SalesInvoice(SellingController): self.update_project() 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 if ( not self.is_return @@ -583,6 +595,9 @@ class SalesInvoice(SellingController): self.db_set("status", "Cancelled") self.db_set("repost_required", 0) + if self.coupon_code: + update_coupon_code_count(self.coupon_code, "cancelled") + if ( frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction" ): -- GitLab From 8682813e90ae2fe0a4a2154b0315cd5874e53255 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Thu, 30 May 2024 09:56:30 +0000 Subject: [PATCH 2/3] fix: merge conflict --- .../doctype/sales_invoice/sales_invoice.json | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 0eee55f135..ed42d97035 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -1900,22 +1900,6 @@ "label": "Don't Create Loyalty Points", "no_copy": 1 }, - { - "fieldname": "coupon_code", - "fieldtype": "Link", - "label": "Coupon Code", - "options": "Coupon Code" - }, - { - "default": "1", - "depends_on": "eval: doc.is_return && doc.return_against", - "description": "Credit Note will update it's own outstanding amount, even if \"Return Against\" is specified.", - "fieldname": "update_outstanding_for_self", - "fieldtype": "Check", - "label": "Update Outstanding for Self", - "no_copy": 1, - "print_hide": 1 - }, { "fieldname": "accounting_journal", "fieldtype": "Link", -- GitLab From ac2bc0466e21f9fe6e1f208912e0dfe94448df36 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Thu, 30 May 2024 09:57:02 +0000 Subject: [PATCH 3/3] fix: merge conflict --- erpnext/accounts/doctype/sales_invoice/sales_invoice.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index ed42d97035..3b91f09b21 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -1900,6 +1900,12 @@ "label": "Don't Create Loyalty Points", "no_copy": 1 }, + { + "fieldname": "coupon_code", + "fieldtype": "Link", + "label": "Coupon Code", + "options": "Coupon Code" + }, { "fieldname": "accounting_journal", "fieldtype": "Link", -- GitLab