From 50985447d1db6568f25806eb5deb3d44c2415017 Mon Sep 17 00:00:00 2001 From: Sanket322 <113279972+Sanket322@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:16:44 +0530 Subject: [PATCH] fix: filter for invalid invoice number in document issue summary (#2641) closes: #2608 Huly®: IC-2765 --- .../gst_india/doctype/gstr_1_beta/gstr_1_export.py | 8 +++++++- india_compliance/gst_india/report/gstr_1/gstr_1.py | 9 ++++++++- india_compliance/gst_india/utils/__init__.py | 12 +++++++++--- .../gst_india/utils/gstr_1/gstr_1_json_map.py | 5 +++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_export.py b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_export.py index dfb245fbe..85136e4bc 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_export.py +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_export.py @@ -202,7 +202,13 @@ def process_doc_issue_data(self, data): """ Add draft count to cancelled count for DOC_ISSUE category """ - for doc in data: + for doc in data.copy(): + if doc.get(GSTR1_DataField.DOC_TYPE.value).startswith( + "Excluded from Report" + ): + data.remove(doc) + continue + doc[GSTR1_DataField.CANCELLED_COUNT.value] += doc.get( GSTR1_DataField.DRAFT_COUNT.value, 0 ) diff --git a/india_compliance/gst_india/report/gstr_1/gstr_1.py b/india_compliance/gst_india/report/gstr_1/gstr_1.py index 769a8df8f..666273a45 100644 --- a/india_compliance/gst_india/report/gstr_1/gstr_1.py +++ b/india_compliance/gst_india/report/gstr_1/gstr_1.py @@ -27,6 +27,7 @@ get_gst_accounts_by_type, get_gstin_list, ) +from india_compliance.gst_india.utils.__init__ import validate_invoice_number from india_compliance.gst_india.utils.exporter import ExcelExporter from india_compliance.gst_india.utils.gstr_1 import SUPECOM @@ -1590,6 +1591,7 @@ def is_same_naming_series(self, name_1, name_2): def seperate_data_by_nature_of_document(self, data, doctype): nature_of_document = { + "Excluded from Report (Invalid Invoice Number)": [], "Excluded from Report (Same GSTIN Billing)": [], "Excluded from Report (Is Opening Entry)": [], "Invoices for outward supply": [], @@ -1600,7 +1602,12 @@ def seperate_data_by_nature_of_document(self, data, doctype): } for doc in data: - if doc.is_opening == "Yes": + if not validate_invoice_number(doc, throw=False): + nature_of_document[ + "Excluded from Report (Invalid Invoice Number)" + ].append(doc) + + elif doc.is_opening == "Yes": nature_of_document["Excluded from Report (Is Opening Entry)"].append( doc ) diff --git a/india_compliance/gst_india/utils/__init__.py b/india_compliance/gst_india/utils/__init__.py index f19d32533..f587b07de 100644 --- a/india_compliance/gst_india/utils/__init__.py +++ b/india_compliance/gst_india/utils/__init__.py @@ -914,16 +914,22 @@ def disable_new_gst_category_notification(): frappe.defaults.clear_user_default("needs_new_gst_category_notification") -def validate_invoice_number(doc): +def validate_invoice_number(doc, throw=True): """Validate GST invoice number requirements.""" - if len(doc.name) > 16: + is_valid_length = len(doc.name) <= 16 + is_valid_format = GST_INVOICE_NUMBER_FORMAT.match(doc.name) + + if not throw: + return is_valid_length and is_valid_format + + if not is_valid_length: frappe.throw( _("GST Invoice Number cannot exceed 16 characters"), title=_("Invalid GST Invoice Number"), ) - if not GST_INVOICE_NUMBER_FORMAT.match(doc.name): + if not is_valid_format: frappe.throw( _( "GST Invoice Number should start with an alphanumeric character and can" diff --git a/india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py b/india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py index 7d1b0f147..0008a7956 100644 --- a/india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py +++ b/india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py @@ -1567,6 +1567,11 @@ def convert_to_gov_data_format(self, input_data, **kwargs): doc_nature_wise_data = {} for invoice in input_data: + if invoice[GSTR1_DataField.DOC_TYPE.value].startswith( + "Excluded from Report" + ): + continue + doc_nature_wise_data.setdefault( invoice[GSTR1_DataField.DOC_TYPE.value], [] ).append(invoice)