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 4ce0ba650..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 @@ -203,11 +203,9 @@ def process_doc_issue_data(self, data): Add draft count to cancelled count for DOC_ISSUE category """ for doc in data.copy(): - if doc.get(GSTR1_DataField.DOC_TYPE.value) in [ - "Invalid Invoice Number (length greater than 16)", - "Excluded from Report (Same GSTIN Billing)", - "Excluded from Report (Is Opening Entry)", - ]: + if doc.get(GSTR1_DataField.DOC_TYPE.value).startswith( + "Excluded from Report" + ): data.remove(doc) continue 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 665005630..666273a45 100644 --- a/india_compliance/gst_india/report/gstr_1/gstr_1.py +++ b/india_compliance/gst_india/report/gstr_1/gstr_1.py @@ -11,10 +11,7 @@ from frappe.query_builder.functions import Date, IfNull, Sum from frappe.utils import cint, flt, formatdate, getdate -from india_compliance.gst_india.constants.__init__ import ( - GST_INVOICE_NUMBER_FORMAT, - GST_TAX_TYPES, -) +from india_compliance.gst_india.constants.__init__ import GST_TAX_TYPES from india_compliance.gst_india.report.hsn_wise_summary_of_outward_supplies.hsn_wise_summary_of_outward_supplies import ( get_columns as get_hsn_columns, ) @@ -30,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 @@ -1593,7 +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 = { - "Invalid Invoice Number (length greater than 16)": [], + "Excluded from Report (Invalid Invoice Number)": [], "Excluded from Report (Same GSTIN Billing)": [], "Excluded from Report (Is Opening Entry)": [], "Invoices for outward supply": [], @@ -1604,10 +1602,11 @@ def seperate_data_by_nature_of_document(self, data, doctype): } for doc in data: - if len(doc.name) > 16 or not GST_INVOICE_NUMBER_FORMAT.match(doc.name): + if not validate_invoice_number(doc, throw=False): nature_of_document[ - "Invalid Invoice Number (length greater than 16)" + "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 554485ff1..fd8559be4 100644 --- a/india_compliance/gst_india/utils/__init__.py +++ b/india_compliance/gst_india/utils/__init__.py @@ -906,16 +906,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"