diff --git a/india_compliance/gst_india/api_classes/taxpayer_returns.py b/india_compliance/gst_india/api_classes/taxpayer_returns.py index fb0df061b..26807a075 100644 --- a/india_compliance/gst_india/api_classes/taxpayer_returns.py +++ b/india_compliance/gst_india/api_classes/taxpayer_returns.py @@ -37,17 +37,19 @@ def get_return_status(self, return_period, reference_id, otp=None): otp=otp, ) - def proceed_to_file(self, return_type, return_period, otp=None): + def proceed_to_file(self, return_type, return_period, is_nil_return, otp=None): + data = { + "gstin": self.company_gstin, + "ret_period": return_period, + } + + if is_nil_return: + data["isnil"] = "Y" + return self.post( return_type=return_type, return_period=return_period, - json={ - "action": "RETNEWPTF", - "data": { - "gstin": self.company_gstin, - "ret_period": return_period, - }, # "isnil": "N" / "Y" - }, + json={"action": "RETNEWPTF", "data": data}, endpoint="returns/gstrptf", otp=otp, ) diff --git a/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py b/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py index 86f5667aa..245d8320f 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py +++ b/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py @@ -4,7 +4,7 @@ import frappe from frappe import _, unscrub -from frappe.utils import flt +from frappe.utils import flt, sbool from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.utils.gstr_1 import GovJsonKey, GSTR1_SubCategory @@ -832,14 +832,23 @@ def process_upload_gstr1(self): return response - def proceed_to_file_gstr1(self, force): + def proceed_to_file_gstr1(self, is_nil_return, force): verify_request_in_progress(self, force) + is_nil_return = sbool(is_nil_return) + api = GSTR1API(self) - response = api.proceed_to_file("GSTR1", self.return_period) + response = api.proceed_to_file("GSTR1", self.return_period, is_nil_return) # Return Form already ready to be filed - if response.error and response.error.error_cd == "RET00003": + if response.error and response.error.error_cd == "RET00003" or is_nil_return: + set_gstr1_actions( + self, + "proceed_to_file", + response.get("reference_id"), + api.request_id, + status="Processed", + ) return self.fetch_and_compare_summary(api) set_gstr1_actions( @@ -872,13 +881,15 @@ def fetch_and_compare_summary(self, api, response=None): response = {} summary = api.get_gstr_1_data("RETSUM", self.return_period) + self.db_set("is_nil", summary.isnil == "Y") + if summary.error: return self.update_json_for("authenticated_summary", summary) mapped_summary = self.get_json_for("books_summary") - gov_summary = convert_to_internal_data_format(summary).get("summary") + gov_summary = convert_to_internal_data_format(summary).get("summary", {}) gov_summary = summarize_retsum_data(gov_summary.values()) differing_categories = get_differing_categories(mapped_summary, gov_summary) @@ -940,7 +951,7 @@ def file_gstr1(self, pan, otp, force): def get_amendment_data(self): authenticated_summary = convert_to_internal_data_format( self.get_json_for("authenticated_summary") - ).get("summary") + ).get("summary", {}) authenticated_summary = summarize_retsum_data(authenticated_summary.values()) non_amended_entries = { diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js index 6f1844f9e..de1e9b6bc 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js @@ -170,8 +170,12 @@ frappe.ui.form.on(DOCTYPE, { const only_books_data = error_log != undefined; if (error_log) { frappe.msgprint({ - message: __("Error while preparing GSTR-1 data, please check {0} for more deatils.", - [`error log`]), + message: __( + "Error while preparing GSTR-1 data, please check {0} for more deatils.", + [ + `error log`, + ] + ), title: "GSTR-1 Download Failed", indicator: "red", }); @@ -195,6 +199,10 @@ frappe.ui.form.on(DOCTYPE, { company_gstin: render_empty_state, + file_nil_gstr1(frm) { + frm.gstr1.render_form_actions(); + }, + month_or_quarter(frm) { render_empty_state(frm); }, @@ -221,6 +229,8 @@ frappe.ui.form.on(DOCTYPE, { const data = frm.doc.__gst_data; if (!data?.status) return; + frm.doc.file_nil_gstr1 = data.is_nil + // Toggle HTML fields frm.refresh(); @@ -300,6 +310,7 @@ class GSTR1 { } this.set_output_gst_balances(); + this.toggle_file_nil_gstr1(); // refresh tabs this.TABS.forEach(_tab => { @@ -356,6 +367,10 @@ class GSTR1 { }); } + refresh_no_data_message() { + this.tabs.filed_tab.tabmanager.refresh_no_data_message(); + } + // RENDER render() { @@ -477,14 +492,20 @@ class GSTR1 { File: this.gstr1_action.file_gstr1_data, }; + // No need to upload if nil gstr1 + const status = + this.frm.doc.file_nil_gstr1 && this.status == "Not Filed" + ? "Uploaded" + : this.status; + let primary_button_label = { "Not Filed": "Upload", Uploaded: "Proceed to File", "Ready to File": "File", - }[this.status] || "Generate"; + }[status] || "Generate"; - if (this.status === "Ready to File") { + if (status === "Ready to File") { this.frm.add_custom_button(__("Mark as Unfiled"), () => { this.gstr1_action.mark_as_unfiled(); }); @@ -687,6 +708,16 @@ class GSTR1 { else this.$wrapper.find(".filter-selector").hide(); } + toggle_file_nil_gstr1() { + if (!this.data || !is_gstr1_api_enabled()) return; + + const has_records = this.data.books_summary?.some(row => row.no_of_records > 0); + + if (!has_records && this.data.status != "Filed") + this.frm.set_df_property("file_nil_gstr1", "hidden", 0); + else this.frm.set_df_property("file_nil_gstr1", "hidden", 1); + } + async set_output_gst_balances() { //Checks if gst-ledger-difference element is there and removes if already present const gst_liability = await get_net_gst_liability(this.frm); @@ -743,7 +774,7 @@ class GSTR1 { args: { month_or_quarter, year, company }, }); - if (!je_details || !je_details.data) return; + if (!je_details) return; this.create_journal_entry_dialog(je_details); } @@ -878,6 +909,10 @@ class TabManager { this.set_creation_time_string(); } + refresh_no_data_message() { + this.datatable.refresh(null, null, this.get_no_data_message()); + } + refresh_view(view, category, filters) { if (!category && view === "Detailed") return; @@ -2114,7 +2149,10 @@ class FiledTab extends GSTR1_TabManager { get_no_data_message() { if (this.instance.data?.is_nil) - return __("You have filed a Nil GSTR-1 for this period"); + if (this.status === "Filed") + return __("You have filed a Nil GSTR-1 for this period"); + else + return __("You are filing a Nil GSTR-1 for this period"); return this.DEFAULT_NO_DATA_MESSAGE; } @@ -2645,11 +2683,18 @@ class GSTR1Action extends FileGSTR1Dialog { proceed_to_file() { const action = "proceed_to_file"; - this.perform_gstr1_action(action, r => { - // already proceed to file - if (r.message) this.handle_proceed_to_file_response(r.message); - else this.check_action_status_with_retry(action); - }); + this.frm.gstr1.data.is_nil = this.frm.doc.file_nil_gstr1; + this.frm.gstr1.refresh_no_data_message(); + + this.perform_gstr1_action( + action, + r => { + // already proceed to file + if (r.message) this.handle_proceed_to_file_response(r.message); + else this.check_action_status_with_retry(action); + }, + { is_nil_return: this.frm.doc.file_nil_gstr1 } + ); } async mark_as_unfiled() { diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json index ee26f0955..3aec4f6c7 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json @@ -7,6 +7,7 @@ "field_order": [ "form", "company", + "file_nil_gstr1", "column_break_ejve", "company_gstin", "column_break_ldkv", @@ -81,13 +82,20 @@ "fieldtype": "Select", "label": "Month/Quarter", "reqd": 1 + }, + { + "default": "0", + "fieldname": "file_nil_gstr1", + "fieldtype": "Check", + "hidden": 1, + "label": "File Nil GSTR-1" } ], "hide_toolbar": 1, "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-05-27 19:30:01.074149", + "modified": "2024-12-26 12:43:21.979607", "modified_by": "Administrator", "module": "GST India", "name": "GSTR-1 Beta", diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py index 6c2c8f1e5..32e6e7d10 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py @@ -287,6 +287,9 @@ def get_journal_entries(month_or_quarter, year, company): .run(as_dict=True) ) + if not data: + return + return {"data": data, "posting_date": to_date} diff --git a/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py b/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py index 79563fbc2..307716a79 100644 --- a/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py +++ b/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py @@ -76,8 +76,7 @@ def download_gstr1_json_data(gstr1_log): json_data.update(response) - if json_data.isnil == "Y": - gstr1_log.db_set("is_nil", 1) + gstr1_log.db_set("is_nil", json_data.isnil == "Y") mapped_data = convert_to_internal_data_format(json_data) gstr1_log.update_json_for(data_field, mapped_data, reset_reconcile=True)