From fde5478507ba107768d83980e8f16512ad35e197 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 18 Oct 2024 10:58:44 +0530 Subject: [PATCH 01/14] fix: add quarterly field in gstr-1-beta and gst return log and remove from gst settings --- .../doctype/gst_return_log/gst_return_log.json | 10 +++++++++- .../doctype/gst_settings/gst_settings.json | 9 +-------- .../gst_india/doctype/gstr_1_beta/gstr_1_beta.json | 14 +++++++++++++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json index 78857c16f5..c3d2d8c58a 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json @@ -12,6 +12,7 @@ "return_period", "company", "return_type", + "is_quarterly", "column_break_sqwh", "filing_date", "acknowledgement_number", @@ -187,6 +188,13 @@ "label": "Return Type", "read_only": 1, "reqd": 1 + }, + { + "default": "0", + "fieldname": "is_quarterly", + "fieldtype": "Check", + "label": "Is Quarterly", + "read_only": 1 } ], "in_create": 1, @@ -197,7 +205,7 @@ "link_fieldname": "reference_docname" } ], - "modified": "2024-08-14 17:53:03.509293", + "modified": "2024-10-18 10:51:57.440489", "modified_by": "Administrator", "module": "GST India", "name": "GST Return Log", diff --git a/india_compliance/gst_india/doctype/gst_settings/gst_settings.json b/india_compliance/gst_india/doctype/gst_settings/gst_settings.json index 49b8f8a9d5..d1edc45c7a 100644 --- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.json +++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.json @@ -45,7 +45,6 @@ "e_invoice_applicable_companies", "gstr_1_section_break", "compare_gstr_1_data", - "filing_frequency", "column_break_cxmn", "restrict_changes_after_gstr_1", "role_allowed_to_modify", @@ -585,12 +584,6 @@ "fieldname": "column_break_cxmn", "fieldtype": "Column Break" }, - { - "fieldname": "filing_frequency", - "fieldtype": "Select", - "label": "Filing Frequency", - "options": "Monthly\nQuarterly" - }, { "depends_on": "eval: doc.restrict_changes_after_gstr_1", "fieldname": "role_allowed_to_modify", @@ -633,7 +626,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-07-25 19:16:25.036677", + "modified": "2024-10-17 17:30:39.135632", "modified_by": "Administrator", "module": "GST India", "name": "GST Settings", 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 ee26f09558..d141d7b16d 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 @@ -13,6 +13,8 @@ "year", "column_break_qcor", "month_or_quarter", + "column_break_auof", + "is_quarterly", "data_section", "tabs_html", "tabs_empty_state", @@ -81,13 +83,23 @@ "fieldtype": "Select", "label": "Month/Quarter", "reqd": 1 + }, + { + "fieldname": "column_break_auof", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "is_quarterly", + "fieldtype": "Check", + "label": "Is Quarterly" } ], "hide_toolbar": 1, "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-05-27 19:30:01.074149", + "modified": "2024-10-17 18:50:23.515301", "modified_by": "Administrator", "module": "GST India", "name": "GSTR-1 Beta", From 3feb2ea6a1962739fc56671cc1a0f6ca5d64d5bc Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Tue, 22 Oct 2024 12:23:18 +0530 Subject: [PATCH 02/14] fix: changes based on new field --- .../doctype/gst_return_log/generate_gstr_1.py | 2 +- .../doctype/gst_return_log/gst_return_log.js | 2 +- .../doctype/gst_settings/gst_settings.py | 15 +++++++++++---- .../doctype/gstr_1_beta/gstr_1_beta.js | 16 ++++++++++------ .../doctype/gstr_1_beta/gstr_1_beta.py | 19 +++++++++++-------- india_compliance/gst_india/setup/__init__.py | 1 - india_compliance/public/js/utils.js | 5 ++--- 7 files changed, 36 insertions(+), 24 deletions(-) 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 75ea1ca070..ca211f797a 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 @@ -577,7 +577,7 @@ def get_books_gstr1_data(self, filters, aggregate=False): return books_data from_date, to_date = get_gstr_1_from_and_to_date( - filters.month_or_quarter, filters.year + filters.month_or_quarter, filters.year, filters.is_quarterly ) _filters = frappe._dict( diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js index 0c7e31968a..7175dbf8e4 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js @@ -4,7 +4,7 @@ frappe.ui.form.on("GST Return Log", { refresh(frm) { const [month_or_quarter, year] = india_compliance.get_month_year_from_period( - frm.doc.return_period + frm.doc.return_period, frm.doc.is_quarterly ); frm.add_custom_button(__("View GSTR-1"), () => { diff --git a/india_compliance/gst_india/doctype/gst_settings/gst_settings.py b/india_compliance/gst_india/doctype/gst_settings/gst_settings.py index 4f98e12359..1be063f62e 100644 --- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.py +++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.py @@ -536,12 +536,19 @@ def restrict_gstr_1_transaction_for(posting_date, company_gstin, gst_settings=No def update_is_not_latest_gstr1_data(posting_date, company_gstin): period = posting_date.strftime("%m%Y") - frappe.db.set_value( - "GST Return Log", f"GSTR1-{period}-{company_gstin}", "is_latest_data", 0 - ) + gst_return_log = f"GSTR1-{period}-{company_gstin}" + frappe.db.set_value("GST Return Log", gst_return_log, "is_latest_data", 0) frappe.publish_realtime( "is_not_latest_data", - message={"filters": {"company_gstin": company_gstin, "period": period}}, + message={ + "filters": { + "company_gstin": company_gstin, + "period": period, + "is_quarterly": frappe.db.get_value( + "GST Return Log", gst_return_log, "is_quarterly" + ), + } + }, doctype="GSTR-1 Beta", ) 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 2df782df56..44bd0a7564 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 @@ -108,8 +108,6 @@ frappe.ui.form.on(DOCTYPE, { frm.trigger("company"); }); - frm.filing_frequency = gst_settings.filing_frequency; - // Set Default Values set_default_company_gstin(frm); set_options_for_year(frm); @@ -122,7 +120,7 @@ frappe.ui.form.on(DOCTYPE, { const { filters } = message; const [month_or_quarter, year] = - india_compliance.get_month_year_from_period(filters.period); + india_compliance.get_month_year_from_period(filters.period, filters.is_quarterly); if ( frm.doc.company_gstin !== filters.company_gstin || @@ -191,6 +189,11 @@ frappe.ui.form.on(DOCTYPE, { set_options_for_month_or_quarter(frm); }, + is_quarterly(frm){ + render_empty_state(frm); + set_options_for_month_or_quarter(frm); + }, + refresh(frm) { // Primary Action frm.disable_save(); @@ -2136,7 +2139,7 @@ function set_options_for_month_or_quarter(frm) { if (frm.doc.year === current_year) { // Options for current year till current month - if (frm.filing_frequency === "Monthly") + if (frm.doc.is_quarterly === 0) options = india_compliance.MONTH.slice(0, current_month_idx + 1); else { let quarter_idx; @@ -2149,11 +2152,11 @@ function set_options_for_month_or_quarter(frm) { } } else if (frm.doc.year === "2017") { // Options for 2017 from July to December - if (frm.filing_frequency === "Monthly") + if (frm.doc.is_quarterly === 0) options = india_compliance.MONTH.slice(6); else options = india_compliance.QUARTER.slice(2); } else { - if (frm.filing_frequency === "Monthly") options = india_compliance.MONTH; + if (frm.doc.is_quarterly === 0) options = india_compliance.MONTH; else options = india_compliance.QUARTER; } @@ -2181,6 +2184,7 @@ async function get_net_gst_liability(frm) { year: frm.doc.year, company_gstin: frm.doc.company_gstin, company: frm.doc.company, + is_quarterly: frm.doc.is_quarterly, }, }); 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 d0f7f00280..d22528a6d4 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 @@ -7,7 +7,7 @@ from frappe import _ from frappe.model.document import Document from frappe.query_builder.functions import Date, Sum -from frappe.utils import get_last_day, getdate +from frappe.utils import cint, get_last_day, getdate from india_compliance.gst_india.api_classes.taxpayer_base import ( TaxpayerBaseAPI, @@ -83,6 +83,7 @@ def generate_gstr1(self, sync_for=None, recompute_books=False): gstr1_log.gstin = self.company_gstin gstr1_log.return_period = period gstr1_log.return_type = "GSTR1" + gstr1_log.is_quarterly = self.is_quarterly gstr1_log.insert() settings = frappe.get_cached_doc("GST Settings") @@ -125,6 +126,7 @@ def _generate_gstr1(self): company_gstin=self.company_gstin, month_or_quarter=self.month_or_quarter, year=self.year, + is_quarterly=self.is_quarterly, ) try: @@ -166,14 +168,16 @@ def on_generate(self, data, filters=None): @frappe.whitelist() -def get_net_gst_liability(company, company_gstin, month_or_quarter, year): +def get_net_gst_liability(company, company_gstin, month_or_quarter, year, is_quarterly): """ Returns the net output balance for the given return period as per ledger entries """ frappe.has_permission("GSTR-1 Beta", throw=True) - from_date, to_date = get_gstr_1_from_and_to_date(month_or_quarter, year) + from_date, to_date = get_gstr_1_from_and_to_date( + month_or_quarter, year, is_quarterly + ) filters = frappe._dict( { @@ -229,15 +233,14 @@ def get_period(month_or_quarter: str, year: str) -> str: return f"{month_number}{year}" -def get_gstr_1_from_and_to_date(month_or_quarter: str, year: str) -> tuple: +def get_gstr_1_from_and_to_date( + month_or_quarter: str, year: str, is_quarterly: str +) -> tuple: """ Returns the from and to date for the given month or quarter and year This is used to filter the data for the given period in Books """ - - filing_frequency = frappe.get_cached_value("GST Settings", None, "filing_frequency") - - if filing_frequency == "Quarterly": + if cint(is_quarterly): start_month, end_month = month_or_quarter.split("-") from_date = getdate(f"{year}-{start_month}-01") to_date = get_last_day(f"{year}-{end_month}-01") diff --git a/india_compliance/gst_india/setup/__init__.py b/india_compliance/gst_india/setup/__init__.py index 7c941bb497..0262de2b4f 100644 --- a/india_compliance/gst_india/setup/__init__.py +++ b/india_compliance/gst_india/setup/__init__.py @@ -220,7 +220,6 @@ def set_default_gst_settings(): # GSTR-1 "compare_gstr_1_data": 1, "freeze_transactions": 1, - "filing_frequency": "Monthly", } if frappe.conf.developer_mode: diff --git a/india_compliance/public/js/utils.js b/india_compliance/public/js/utils.js index a889da558e..f2cb9fa0c0 100644 --- a/india_compliance/public/js/utils.js +++ b/india_compliance/public/js/utils.js @@ -30,7 +30,7 @@ Object.assign(india_compliance, { QUARTER: ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"], - get_month_year_from_period(period) { + get_month_year_from_period(period, is_quarterly) { /** * Returns month or quarter and year from the period * Month or quarter depends on the filing frequency set in GST Settings @@ -39,11 +39,10 @@ Object.assign(india_compliance, { * @returns {Array} - [month_or_quarter, year] */ - const { filing_frequency } = gst_settings; const month_number = period.slice(0, 2); const year = period.slice(2); - if (filing_frequency === "Monthly") return [this.MONTH[month_number - 1], year]; + if (is_quarterly === 0) return [this.MONTH[month_number - 1], year]; else return [this.QUARTER[Math.floor(month_number / 3)], year]; }, From 46b66e193476c10ca3695e9c13e2bb6bb5f6cba9 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 25 Oct 2024 16:48:10 +0530 Subject: [PATCH 03/14] fix: verify gst filing preference and change if require --- .../doctype/gstr_1_beta/gstr_1_beta.js | 11 +++- .../doctype/gstr_1_beta/gstr_1_beta.py | 66 +++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) 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 44bd0a7564..09bb9701da 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 @@ -157,11 +157,16 @@ frappe.ui.form.on(DOCTYPE, { if ( frm.doc.company_gstin !== filters.company_gstin || - frm.doc.month_or_quarter != filters.month_or_quarter || frm.doc.year != filters.year ) return; + frm.doc.is_quarterly = filters.is_quarterly + set_options_for_month_or_quarter(frm, set_only_options=true); + frm.doc.month_or_quarter = filters.month_or_quarter + frm.refresh_field("is_quarterly") + frm.refresh_field("month_or_quarter") + frappe.after_ajax(() => { frm.doc.__gst_data = data ; frm.trigger("load_gstr1_data"); @@ -2120,7 +2125,7 @@ function set_options_for_year(frm) { frm.set_value("year", current_year.toString()); } -function set_options_for_month_or_quarter(frm) { +function set_options_for_month_or_quarter(frm, set_only_options=false) { /** * Set options for Month or Quarter based on the year and current date * 1. If the year is current year, then options are till current month @@ -2161,6 +2166,8 @@ function set_options_for_month_or_quarter(frm) { } set_field_options("month_or_quarter", options); + if (set_only_options) return + if (frm.doc.year === current_year) // set second last option as default frm.set_value("month_or_quarter", options[options.length - 2]); 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 d22528a6d4..eb29fcd1ee 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 @@ -13,9 +13,14 @@ TaxpayerBaseAPI, otp_handler, ) +from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.utils import get_gst_accounts_by_type +from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict from india_compliance.gst_india.utils.gstin_info import get_gstr_1_return_status +MONTH = list(get_month_or_quarter_dict().keys())[4:] +QUARTER = ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"] + class GSTR1Beta(Document): @@ -52,7 +57,8 @@ def mark_as_filed(self): @frappe.whitelist() @otp_handler def generate_gstr1(self, sync_for=None, recompute_books=False): - period = get_period(self.month_or_quarter, self.year) + self.validate_and_update_filing_frequency() + period = get_period(self.valid_month_or_quarter, self.year) # get gstr1 log if log_name := frappe.db.exists( @@ -83,7 +89,7 @@ def generate_gstr1(self, sync_for=None, recompute_books=False): gstr1_log.gstin = self.company_gstin gstr1_log.return_period = period gstr1_log.return_type = "GSTR1" - gstr1_log.is_quarterly = self.is_quarterly + gstr1_log.is_quarterly = self.valid_is_quarterly gstr1_log.insert() settings = frappe.get_cached_doc("GST Settings") @@ -124,9 +130,9 @@ def _generate_gstr1(self): filters = frappe._dict( company=self.company, company_gstin=self.company_gstin, - month_or_quarter=self.month_or_quarter, + month_or_quarter=self.valid_month_or_quarter, year=self.year, - is_quarterly=self.is_quarterly, + is_quarterly=self.valid_is_quarterly, ) try: @@ -149,6 +155,8 @@ def on_generate(self, data, filters=None): Once data is generated, update the status and publish the data """ if not filters: + self.is_quarterly = self.valid_is_quarterly + self.month_or_quarter = self.valid_month_or_quarter filters = self if getattr(self, "gstr1_log", None): @@ -163,6 +171,56 @@ def on_generate(self, data, filters=None): doctype=self.doctype, ) + def validate_and_update_filing_frequency(self): + api = GSTR1API(company_gstin=self.company_gstin) + filters = { + "fy": api.get_fy(), + "gstin": self.company_gstin, + "action": "GETPREF", + } + if response := frappe.db.get_list( + "Integration Request", + {"data": frappe.as_json(filters, indent=4), "output": ["like", "%result%"]}, + pluck="output", + limit=1, + order_by="creation desc", + ): + output = frappe.parse_json(response[0]) + preference = self.get_preference(output.result.get("response")) + + else: + response = api.get_filing_preference() + preference = self.get_preference(response.response) + + if (self.is_quarterly == 1 and preference == "Q") or ( + self.is_quarterly == 0 and preference == "M" + ): + self.valid_is_quarterly = self.is_quarterly + self.valid_month_or_quarter = self.month_or_quarter + return + + self.toggle_filing_preference() + + def toggle_filing_preference(self): + self.valid_is_quarterly = 1 if self.is_quarterly == 0 else 0 + + if self.valid_is_quarterly: + # If the user has selected a month but the preference is quarter + quarter = MONTH.index(self.month_or_quarter) // 3 + self.valid_month_or_quarter = QUARTER[quarter] + else: + # If the user has selected a quarter but uthe preference is month + quarter_idx = QUARTER.index(self.month_or_quarter) + self.valid_month_or_quarter = MONTH[quarter_idx * 3] + + def get_preference(self, response): + if "-" in self.month_or_quarter: + quarter_idx = QUARTER.index(self.month_or_quarter) + else: + quarter_idx = MONTH.index(self.month_or_quarter) // 3 + + return response[quarter_idx].get("preference") + ####### DATA ###################################################################################### From 6d06a0c50a399cb4f2e1a39e1098f862788737ff Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 25 Oct 2024 19:16:55 +0530 Subject: [PATCH 04/14] refactor: no need to refresh fields --- india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 2 -- 1 file changed, 2 deletions(-) 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 09bb9701da..7879a49234 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 @@ -164,8 +164,6 @@ frappe.ui.form.on(DOCTYPE, { frm.doc.is_quarterly = filters.is_quarterly set_options_for_month_or_quarter(frm, set_only_options=true); frm.doc.month_or_quarter = filters.month_or_quarter - frm.refresh_field("is_quarterly") - frm.refresh_field("month_or_quarter") frappe.after_ajax(() => { frm.doc.__gst_data = data ; From eaef956486336e4665544d6a13150d5ab3f42356 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Sat, 26 Oct 2024 17:56:53 +0530 Subject: [PATCH 05/14] fix: fetch filling preference once per quarter --- .../gst_india/api_classes/taxpayer_base.py | 11 ++--- .../doctype/gstr_1_beta/gstr_1_beta.py | 41 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/india_compliance/gst_india/api_classes/taxpayer_base.py b/india_compliance/gst_india/api_classes/taxpayer_base.py index 1e92ffee0f..e000ab4d32 100644 --- a/india_compliance/gst_india/api_classes/taxpayer_base.py +++ b/india_compliance/gst_india/api_classes/taxpayer_base.py @@ -465,16 +465,17 @@ def validate_auth_token(self): return - def get_filing_preference(self): + def get_filing_preference(self, date=None): return self.get( - action="GETPREF", params={"fy": self.get_fy()}, endpoint="returns" + action="GETPREF", params={"fy": self.get_fy(date)}, endpoint="returns" ) @staticmethod - def get_fy(): - date = frappe.utils.getdate() - + def get_fy(date=None): # Standard for India as per GST + if not date: + date = frappe.utils.getdate() + if date.month < 4: return f"{date.year - 1}-{str(date.year)[2:]}" 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 eb29fcd1ee..3cdaaa3849 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 @@ -173,36 +173,43 @@ def on_generate(self, data, filters=None): def validate_and_update_filing_frequency(self): api = GSTR1API(company_gstin=self.company_gstin) - filters = { - "fy": api.get_fy(), - "gstin": self.company_gstin, + + start_date, end_date = get_gstr_1_from_and_to_date( + self.month_or_quarter, self.year, self.is_quarterly + ) + data = { "action": "GETPREF", + "fy": TaxpayerBaseAPI.get_fy(start_date), + "gstin": self.company_gstin, } - if response := frappe.db.get_list( + filters = { + "data": frappe.as_json(data, indent=4), + "output": ["like", "%result%"], + "creation": ["between", [start_date, end_date]], + } + if output := frappe.db.get_list( "Integration Request", - {"data": frappe.as_json(filters, indent=4), "output": ["like", "%result%"]}, + filters, pluck="output", limit=1, order_by="creation desc", ): - output = frappe.parse_json(response[0]) - preference = self.get_preference(output.result.get("response")) + response = frappe.parse_json(output[0]).result.get("response") else: - response = api.get_filing_preference() - preference = self.get_preference(response.response) + response = api.get_filing_preference(date=start_date).response - if (self.is_quarterly == 1 and preference == "Q") or ( - self.is_quarterly == 0 and preference == "M" - ): + expected_preference = self.get_preference(response) + preference = "Q" if self.is_quarterly else "M" + + if preference == expected_preference: self.valid_is_quarterly = self.is_quarterly self.valid_month_or_quarter = self.month_or_quarter - return - - self.toggle_filing_preference() + else: + self.toggle_filing_preference() def toggle_filing_preference(self): - self.valid_is_quarterly = 1 if self.is_quarterly == 0 else 0 + self.valid_is_quarterly = 1 - self.is_quarterly if self.valid_is_quarterly: # If the user has selected a month but the preference is quarter @@ -214,7 +221,7 @@ def toggle_filing_preference(self): self.valid_month_or_quarter = MONTH[quarter_idx * 3] def get_preference(self, response): - if "-" in self.month_or_quarter: + if self.is_quarterly: quarter_idx = QUARTER.index(self.month_or_quarter) else: quarter_idx = MONTH.index(self.month_or_quarter) // 3 From b4625d6222d14aca372d6bd2957f9ef23160f4e0 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Mon, 4 Nov 2024 11:52:25 +0530 Subject: [PATCH 06/14] fix: cache filing preference and add function outline --- india_compliance/gst_india/api_classes/taxpayer_base.py | 3 ++- .../gst_india/doctype/gst_return_log/generate_gstr_1.py | 1 + india_compliance/gst_india/utils/gstin_info.py | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/india_compliance/gst_india/api_classes/taxpayer_base.py b/india_compliance/gst_india/api_classes/taxpayer_base.py index e000ab4d32..2533063180 100644 --- a/india_compliance/gst_india/api_classes/taxpayer_base.py +++ b/india_compliance/gst_india/api_classes/taxpayer_base.py @@ -7,7 +7,7 @@ import frappe import frappe.utils -from frappe import _ +from frappe import _, request_cache from frappe.utils import add_to_date, cint, now_datetime from india_compliance.exceptions import ( @@ -465,6 +465,7 @@ def validate_auth_token(self): return + @request_cache def get_filing_preference(self, date=None): return self.get( action="GETPREF", params={"fy": self.get_fy(date)}, endpoint="returns" 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 ca211f797a..85744ef3e7 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 @@ -503,6 +503,7 @@ def generate_gstr1_data(self, filters, callback=None): # APIs Enabled status = self.get_return_status() + # filing_frequency = self.get_filing_frequency() & update this in filters if status == "Filed": gov_data_field = "filed" diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index 01e02611d6..855e940d93 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -335,6 +335,14 @@ def get_gstr_1_return_status( return "Not Filed" +def get_filing_frequency(gstin, period): + # is not Q1-M1 ? => fetch if available from Q1-M1 + # if not, is it filed for the period or date has surpassed? => if not, then don't fetch and return nothing + + # if filed, then fetch from the filed data + pass + + def get_fy(period, year_increment=0): month, year = period[:2], period[2:] year = str(int(year) + year_increment) From e9d3b10fbef235bdadf5ec9db3181d04497af3ce Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Wed, 6 Nov 2024 19:33:14 +0530 Subject: [PATCH 07/14] fix: changes as per review --- .../doctype/gst_return_log/generate_gstr_1.py | 13 +++- .../gst_return_log/gst_return_log.json | 5 +- .../doctype/gstr_1_beta/gstr_1_beta.js | 40 +++++++++- .../doctype/gstr_1_beta/gstr_1_beta.py | 8 ++ .../gst_india/utils/gstin_info.py | 76 +++++++++++++++++-- 5 files changed, 130 insertions(+), 12 deletions(-) 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 85744ef3e7..645d850734 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 @@ -497,13 +497,24 @@ def generate_gstr1_data(self, filters, callback=None): """ data = {} + from india_compliance.gst_india.utils.gstin_info import get_filing_frequency + + filing_frequency = get_filing_frequency( + self.company, self.gstin, self.return_period + ) + if filing_frequency and filing_frequency != self.is_quarterly: + self.is_quarterly = filing_frequency + filters.is_quarterly = filing_frequency + frappe.db.set_value( + "GST Return Log", self.name, "is_quarterly", filing_frequency + ) + # APIs Disabled if not self.is_gstr1_api_enabled(warn_for_missing_credentials=True): return self.generate_only_books_data(data, filters, callback) # APIs Enabled status = self.get_return_status() - # filing_frequency = self.get_filing_frequency() & update this in filters if status == "Filed": gov_data_field = "filed" diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json index c3d2d8c58a..07f3deda41 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json @@ -190,9 +190,8 @@ "reqd": 1 }, { - "default": "0", "fieldname": "is_quarterly", - "fieldtype": "Check", + "fieldtype": "Data", "label": "Is Quarterly", "read_only": 1 } @@ -205,7 +204,7 @@ "link_fieldname": "reference_docname" } ], - "modified": "2024-10-18 10:51:57.440489", + "modified": "2024-11-06 17:47:55.754860", "modified_by": "Administrator", "module": "GST India", "name": "GST Return Log", 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 7879a49234..7667136d00 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 @@ -181,10 +181,14 @@ frappe.ui.form.on(DOCTYPE, { frm.set_value("company_gstin", options[0]); }, - company_gstin: render_empty_state, + company_gstin(frm){ + render_empty_state(frm); + update_fields_based_on_filing_preference(frm); + }, month_or_quarter(frm) { render_empty_state(frm); + update_fields_based_on_filing_preference(frm); }, year(frm) { @@ -2123,6 +2127,40 @@ function set_options_for_year(frm) { frm.set_value("year", current_year.toString()); } +function update_fields_based_on_filing_preference(frm){ + frappe.call({ + method: "india_compliance.gst_india.doctype.gstr_1_beta.gstr_1_beta.get_filing_preference", + args: {month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin}, + callback: (r) => { + const preference = r.message === undefined ? r.message : cint(r.message); + + if(preference === undefined){ + frm.set_df_property("is_quarterly", "read_only", 0); + return + } + if(preference === frm.doc.is_quarterly){ + frm.set_df_property("is_quarterly", "read_only", 1); + return + } + + frm.doc.is_quarterly = preference + frm.set_df_property("is_quarterly", "read_only", 1) + set_options_for_month_or_quarter(frm, set_only_options=true) + + if(preference == 1){ + const old_month_index = india_compliance.MONTH.indexOf(frm.doc.month_or_quarter) + const quarter = Math.floor(old_month_index / 3) + frm.doc.month_or_quarter = india_compliance.QUARTER[quarter] + }else{ + const old_quarter_index = india_compliance.QUARTER.indexOf(frm.doc.month_or_quarter) * 3 + frm.doc.month_or_quarter = india_compliance.MONTH[old_quarter_index] + } + frm.refresh_field("month_or_quarter") + frm.refresh_field("is_quarterly") + } + }) +} + function set_options_for_month_or_quarter(frm, set_only_options=false) { /** * Set options for Month or Quarter based on the year and current date 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 3cdaaa3849..feeca69276 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 @@ -315,3 +315,11 @@ def get_gstr_1_from_and_to_date( to_date = get_last_day(from_date) return from_date, to_date + + +@frappe.whitelist() +def get_filing_preference(month_or_quarter: str, year: str, company_gstin): + period = get_period(month_or_quarter, year) + return frappe.db.get_value( + "GST Return Log", f"GSTR1-{period}-{company_gstin}", "is_quarterly" + ) diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index 855e940d93..56b4d5ac24 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -1,20 +1,26 @@ import json -from datetime import timedelta +from datetime import date, timedelta from string import whitespace import frappe from frappe import _ -from frappe.utils import getdate +from frappe.utils import cint, getdate from india_compliance.exceptions import GSPServerError from india_compliance.gst_india.api_classes.base import BASE_URL from india_compliance.gst_india.api_classes.e_invoice import EInvoiceAPI from india_compliance.gst_india.api_classes.e_waybill import EWaybillAPI from india_compliance.gst_india.api_classes.public import PublicAPI +from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.doctype.gst_return_log.gst_return_log import ( process_gstr_1_returns_info, ) from india_compliance.gst_india.utils import parse_datetime, titlecase, validate_gstin +from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict + +MONTH = list(get_month_or_quarter_dict().keys())[4:] +QUARTER = ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"] + GST_CATEGORIES = { "Regular": "Registered Regular", @@ -335,12 +341,68 @@ def get_gstr_1_return_status( return "Not Filed" -def get_filing_frequency(gstin, period): - # is not Q1-M1 ? => fetch if available from Q1-M1 - # if not, is it filed for the period or date has surpassed? => if not, then don't fetch and return nothing +def get_filing_frequency(company, gstin, period): + month = cint(period[:2]) + year = cint(period[2:]) + + start_month = (month - 1) // 3 * 3 + 1 + quarter = (month - 1) // 3 + 1 + + start_date = getdate(f"{year}-{start_month}-01") + log_name = f"GSTR1-{start_month:02d}{year}-{gstin}" - # if filed, then fetch from the filed data - pass + if filing_preference := frappe.db.get_value( + "GST Return Log", log_name, "is_quarterly" + ): + return filing_preference + + filing_due_date = date(year, start_month + 1, 13) + if ( + frappe.db.get_value("GST Return Log", log_name, "filing_status") != "Filed" + and getdate() < filing_due_date + ): + return + + api = GSTR1API(company_gstin=gstin) + response = api.get_filing_preference(date=start_date).response + + filing_preference = 1 if response[quarter].get("preference") == "Q" else 0 + frappe.enqueue( + create_gst_return_log_for_quarter, + company, + gstin, + start_month, + year, + filing_preference, + ) + + return filing_preference + + +def create_gst_return_log_for_quarter( + company_name, gstin, start_month, year, filing_frequency +): + return_periods = [] + + for month_offset in range(3): + current_month = start_month + month_offset + period = f"{current_month:02d}{year}" + return_periods.append(period) + + for period in return_periods: + try: + frappe.get_doc( + { + "doctype": "GST Return Log", + "company": company_name, + "gstin": gstin, + "return_period": period, + "return_type": "GSTR1", + "is_quarterly": filing_frequency, + } + ).insert() + except frappe.DuplicateEntryError: + pass def get_fy(period, year_increment=0): From 9eae0d61f4fb9eaaea9f8c49250d7f6645c95a27 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 7 Nov 2024 14:48:02 +0530 Subject: [PATCH 08/14] fix: remove extra code --- .../doctype/gstr_1_beta/gstr_1_beta.py | 76 +------------------ 1 file changed, 4 insertions(+), 72 deletions(-) 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 feeca69276..1a0214194e 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 @@ -13,14 +13,9 @@ TaxpayerBaseAPI, otp_handler, ) -from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.utils import get_gst_accounts_by_type -from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict from india_compliance.gst_india.utils.gstin_info import get_gstr_1_return_status -MONTH = list(get_month_or_quarter_dict().keys())[4:] -QUARTER = ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"] - class GSTR1Beta(Document): @@ -57,8 +52,7 @@ def mark_as_filed(self): @frappe.whitelist() @otp_handler def generate_gstr1(self, sync_for=None, recompute_books=False): - self.validate_and_update_filing_frequency() - period = get_period(self.valid_month_or_quarter, self.year) + period = get_period(self.month_or_quarter, self.year) # get gstr1 log if log_name := frappe.db.exists( @@ -89,7 +83,7 @@ def generate_gstr1(self, sync_for=None, recompute_books=False): gstr1_log.gstin = self.company_gstin gstr1_log.return_period = period gstr1_log.return_type = "GSTR1" - gstr1_log.is_quarterly = self.valid_is_quarterly + gstr1_log.is_quarterly = self.is_quarterly gstr1_log.insert() settings = frappe.get_cached_doc("GST Settings") @@ -130,9 +124,9 @@ def _generate_gstr1(self): filters = frappe._dict( company=self.company, company_gstin=self.company_gstin, - month_or_quarter=self.valid_month_or_quarter, + month_or_quarter=self.month_or_quarter, year=self.year, - is_quarterly=self.valid_is_quarterly, + is_quarterly=self.is_quarterly, ) try: @@ -154,11 +148,6 @@ def on_generate(self, data, filters=None): """ Once data is generated, update the status and publish the data """ - if not filters: - self.is_quarterly = self.valid_is_quarterly - self.month_or_quarter = self.valid_month_or_quarter - filters = self - if getattr(self, "gstr1_log", None): self.gstr1_log.db_set( {"generation_status": "Generated", "is_latest_data": 1} @@ -171,63 +160,6 @@ def on_generate(self, data, filters=None): doctype=self.doctype, ) - def validate_and_update_filing_frequency(self): - api = GSTR1API(company_gstin=self.company_gstin) - - start_date, end_date = get_gstr_1_from_and_to_date( - self.month_or_quarter, self.year, self.is_quarterly - ) - data = { - "action": "GETPREF", - "fy": TaxpayerBaseAPI.get_fy(start_date), - "gstin": self.company_gstin, - } - filters = { - "data": frappe.as_json(data, indent=4), - "output": ["like", "%result%"], - "creation": ["between", [start_date, end_date]], - } - if output := frappe.db.get_list( - "Integration Request", - filters, - pluck="output", - limit=1, - order_by="creation desc", - ): - response = frappe.parse_json(output[0]).result.get("response") - - else: - response = api.get_filing_preference(date=start_date).response - - expected_preference = self.get_preference(response) - preference = "Q" if self.is_quarterly else "M" - - if preference == expected_preference: - self.valid_is_quarterly = self.is_quarterly - self.valid_month_or_quarter = self.month_or_quarter - else: - self.toggle_filing_preference() - - def toggle_filing_preference(self): - self.valid_is_quarterly = 1 - self.is_quarterly - - if self.valid_is_quarterly: - # If the user has selected a month but the preference is quarter - quarter = MONTH.index(self.month_or_quarter) // 3 - self.valid_month_or_quarter = QUARTER[quarter] - else: - # If the user has selected a quarter but uthe preference is month - quarter_idx = QUARTER.index(self.month_or_quarter) - self.valid_month_or_quarter = MONTH[quarter_idx * 3] - - def get_preference(self, response): - if self.is_quarterly: - quarter_idx = QUARTER.index(self.month_or_quarter) - else: - quarter_idx = MONTH.index(self.month_or_quarter) // 3 - - return response[quarter_idx].get("preference") - ####### DATA ###################################################################################### From 333f4cf60cca941b8218d40ac217bd87bcad67de Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 7 Nov 2024 19:12:10 +0530 Subject: [PATCH 09/14] fix: changes as per comments and refactor --- .../doctype/gst_return_log/generate_gstr_1.py | 36 +++++--- .../doctype/gstr_1_beta/gstr_1_beta.js | 69 ++++++++------- .../doctype/gstr_1_beta/gstr_1_beta.py | 1 - .../gst_india/utils/gstin_info.py | 84 +++++++++---------- 4 files changed, 101 insertions(+), 89 deletions(-) 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 645d850734..8240ad9241 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,8 +4,9 @@ import frappe from frappe import unscrub -from frappe.utils import flt +from frappe.utils import cstr, flt +from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict from india_compliance.gst_india.utils.gstr_1 import GSTR1_SubCategory from india_compliance.gst_india.utils.gstr_1.__init__ import ( CATEGORY_SUB_CATEGORY_MAPPING, @@ -21,6 +22,9 @@ summarize_retsum_data, ) +MONTH = list(get_month_or_quarter_dict().keys())[4:] +QUARTER = ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"] + class SummarizeGSTR1: AMOUNT_FIELDS = { @@ -497,18 +501,6 @@ def generate_gstr1_data(self, filters, callback=None): """ data = {} - from india_compliance.gst_india.utils.gstin_info import get_filing_frequency - - filing_frequency = get_filing_frequency( - self.company, self.gstin, self.return_period - ) - if filing_frequency and filing_frequency != self.is_quarterly: - self.is_quarterly = filing_frequency - filters.is_quarterly = filing_frequency - frappe.db.set_value( - "GST Return Log", self.name, "is_quarterly", filing_frequency - ) - # APIs Disabled if not self.is_gstr1_api_enabled(warn_for_missing_credentials=True): return self.generate_only_books_data(data, filters, callback) @@ -516,6 +508,15 @@ def generate_gstr1_data(self, filters, callback=None): # APIs Enabled status = self.get_return_status() + from india_compliance.gst_india.utils.gstin_info import get_filing_frequency + + filing_frequency = get_filing_frequency(self.gstin, self.return_period) + + if cstr(filing_frequency) and filing_frequency != self.is_quarterly: + self.db_set({"is_quarterly": filing_frequency}) + filters.is_quarterly = filing_frequency + update_month_or_quarter(filters) + if status == "Filed": gov_data_field = "filed" else: @@ -671,3 +672,12 @@ def normalize_data(data): data[subcategory] = [*subcategory_data.values()] return data + + +def update_month_or_quarter(filters): + if filters.is_quarterly == 1: + quarter = MONTH.index(filters.month_or_quarter) // 3 + filters.month_or_quarter = QUARTER[quarter] + else: + quarter_idx = QUARTER.index(filters.month_or_quarter) + filters.month_or_quarter = MONTH[(quarter_idx * 3) + 2] 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 7667136d00..abcc28a601 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 @@ -161,9 +161,11 @@ frappe.ui.form.on(DOCTYPE, { ) return; - frm.doc.is_quarterly = filters.is_quarterly - set_options_for_month_or_quarter(frm, set_only_options=true); - frm.doc.month_or_quarter = filters.month_or_quarter + if(frm.doc.is_quarterly != filters.is_quarterly){ + frm.doc.is_quarterly = filters.is_quarterly + set_options_for_month_or_quarter(frm, set_only_options=true) + frm.doc.month_or_quarter = filters.month_or_quarter + } frappe.after_ajax(() => { frm.doc.__gst_data = data ; @@ -2127,38 +2129,43 @@ function set_options_for_year(frm) { frm.set_value("year", current_year.toString()); } -function update_fields_based_on_filing_preference(frm){ - frappe.call({ +async function update_fields_based_on_filing_preference(frm){ + let {message : preference } = await frappe.call({ method: "india_compliance.gst_india.doctype.gstr_1_beta.gstr_1_beta.get_filing_preference", args: {month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin}, - callback: (r) => { - const preference = r.message === undefined ? r.message : cint(r.message); + }) - if(preference === undefined){ - frm.set_df_property("is_quarterly", "read_only", 0); - return - } - if(preference === frm.doc.is_quarterly){ - frm.set_df_property("is_quarterly", "read_only", 1); - return - } + if(preference === undefined){ + frm.set_df_property("is_quarterly", "read_only", 0); + return + } - frm.doc.is_quarterly = preference - frm.set_df_property("is_quarterly", "read_only", 1) - set_options_for_month_or_quarter(frm, set_only_options=true) - - if(preference == 1){ - const old_month_index = india_compliance.MONTH.indexOf(frm.doc.month_or_quarter) - const quarter = Math.floor(old_month_index / 3) - frm.doc.month_or_quarter = india_compliance.QUARTER[quarter] - }else{ - const old_quarter_index = india_compliance.QUARTER.indexOf(frm.doc.month_or_quarter) * 3 - frm.doc.month_or_quarter = india_compliance.MONTH[old_quarter_index] - } - frm.refresh_field("month_or_quarter") - frm.refresh_field("is_quarterly") - } - }) + preference = cint(preference) + + if(preference === frm.doc.is_quarterly){ + frm.set_df_property("is_quarterly", "read_only", 1); + return + } + + update_preference(frm, preference) +} + +function update_preference(frm, preference){ + frm.doc.is_quarterly = preference + frm.set_df_property("is_quarterly", "read_only", 1) + set_options_for_month_or_quarter(frm, set_only_options=true) + + if(preference === 1){ + const month_index = india_compliance.MONTH.indexOf(frm.doc.month_or_quarter) + const quarter = Math.floor(month_index / 3) + frm.doc.month_or_quarter = india_compliance.QUARTER[quarter] + }else{ + const quarter_index = india_compliance.QUARTER.indexOf(frm.doc.month_or_quarter) * 3 + // added 2 to set month_or_quarter as last month of that quarter + frm.doc.month_or_quarter = india_compliance.MONTH[quarter_index+2] + } + frm.refresh_field("month_or_quarter") + frm.refresh_field("is_quarterly") } function set_options_for_month_or_quarter(frm, set_only_options=false) { 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 1a0214194e..0e3be5ff2d 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 @@ -83,7 +83,6 @@ def generate_gstr1(self, sync_for=None, recompute_books=False): gstr1_log.gstin = self.company_gstin gstr1_log.return_period = period gstr1_log.return_type = "GSTR1" - gstr1_log.is_quarterly = self.is_quarterly gstr1_log.insert() settings = frappe.get_cached_doc("GST Settings") diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index 56b4d5ac24..0003623b11 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -1,10 +1,10 @@ import json -from datetime import date, timedelta +from datetime import timedelta from string import whitespace import frappe from frappe import _ -from frappe.utils import cint, getdate +from frappe.utils import cint, get_last_day, getdate from india_compliance.exceptions import GSPServerError from india_compliance.gst_india.api_classes.base import BASE_URL @@ -16,11 +16,6 @@ process_gstr_1_returns_info, ) from india_compliance.gst_india.utils import parse_datetime, titlecase, validate_gstin -from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict - -MONTH = list(get_month_or_quarter_dict().keys())[4:] -QUARTER = ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"] - GST_CATEGORIES = { "Regular": "Registered Regular", @@ -341,7 +336,7 @@ def get_gstr_1_return_status( return "Not Filed" -def get_filing_frequency(company, gstin, period): +def get_filing_frequency(gstin, period): month = cint(period[:2]) year = cint(period[2:]) @@ -349,18 +344,23 @@ def get_filing_frequency(company, gstin, period): quarter = (month - 1) // 3 + 1 start_date = getdate(f"{year}-{start_month}-01") - log_name = f"GSTR1-{start_month:02d}{year}-{gstin}" + months_of_quarter = [start_month + i for i in range(3)] + log_names = [f"GSTR1-{month:02d}{year}-{gstin}" for month in months_of_quarter] - if filing_preference := frappe.db.get_value( - "GST Return Log", log_name, "is_quarterly" + if filing_preference := frappe.get_list( + "GST Return Log", + filters={"name": ["in", log_names]}, + fields=["is_quarterly", "name"], ): - return filing_preference + for record in filing_preference: + if not record.get("is_quarterly"): + continue - filing_due_date = date(year, start_month + 1, 13) - if ( - frappe.db.get_value("GST Return Log", log_name, "filing_status") != "Filed" - and getdate() < filing_due_date - ): + return record.get("is_quarterly") + + if frappe.db.get_value( + "GST Return Log", log_names[0], "filing_status" + ) != "Filed" and getdate() < get_last_day(start_date): return api = GSTR1API(company_gstin=gstin) @@ -369,40 +369,36 @@ def get_filing_frequency(company, gstin, period): filing_preference = 1 if response[quarter].get("preference") == "Q" else 0 frappe.enqueue( create_gst_return_log_for_quarter, - company, - gstin, - start_month, - year, - filing_preference, + gstin=gstin, + log_names=log_names, + filing_preference=filing_preference, ) return filing_preference -def create_gst_return_log_for_quarter( - company_name, gstin, start_month, year, filing_frequency -): - return_periods = [] +def create_gst_return_log_for_quarter(gstin, log_names, filing_preference): + existing_log = frappe.get_all( + "GST Return Log", filters={"name": ["in", log_names]}, pluck="name" + ) - for month_offset in range(3): - current_month = start_month + month_offset - period = f"{current_month:02d}{year}" - return_periods.append(period) + for log_name in log_names: + if log_name in existing_log: + frappe.db.set_value( + "GST Return Log", log_name, "is_quarterly", filing_preference + ) + continue - for period in return_periods: - try: - frappe.get_doc( - { - "doctype": "GST Return Log", - "company": company_name, - "gstin": gstin, - "return_period": period, - "return_type": "GSTR1", - "is_quarterly": filing_frequency, - } - ).insert() - except frappe.DuplicateEntryError: - pass + frappe.get_doc( + { + "doctype": "GST Return Log", + "name": log_name, + "return_type": "GSTR1", + "is_quarterly": filing_preference, + "return_period": log_name.split("-")[1], + "gstin": gstin, + } + ).insert() def get_fy(period, year_increment=0): From 5779790394cc52b5a02c1c2a87e7acb2dfd17ece Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 8 Nov 2024 13:55:23 +0530 Subject: [PATCH 10/14] fix: changes as per new field and fixing some isuues --- .../doctype/gst_return_log/generate_gstr_1.py | 21 ++++++++++++------- .../doctype/gst_return_log/gst_return_log.js | 5 +++-- .../gst_return_log/gst_return_log.json | 8 +++---- .../doctype/gstr_1_beta/gstr_1_beta.js | 9 ++++---- .../doctype/gstr_1_beta/gstr_1_beta.py | 14 ++++++++++--- .../gst_india/utils/gstin_info.py | 18 +++++++++------- india_compliance/public/js/utils.js | 2 +- 7 files changed, 46 insertions(+), 31 deletions(-) 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 8240ad9241..3b23b2b4d3 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 cstr, flt +from frappe.utils import flt from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict from india_compliance.gst_india.utils.gstr_1 import GSTR1_SubCategory @@ -508,14 +508,13 @@ def generate_gstr1_data(self, filters, callback=None): # APIs Enabled status = self.get_return_status() - from india_compliance.gst_india.utils.gstin_info import get_filing_frequency + from india_compliance.gst_india.utils.gstin_info import get_filing_preference - filing_frequency = get_filing_frequency(self.gstin, self.return_period) + filing_preference = get_filing_preference(self.gstin, self.return_period) - if cstr(filing_frequency) and filing_frequency != self.is_quarterly: - self.db_set({"is_quarterly": filing_frequency}) - filters.is_quarterly = filing_frequency - update_month_or_quarter(filters) + if filing_preference and self.filing_preference is None: + self.db_set({"filing_preference": filing_preference}) + update_filters(filters, filing_preference) if status == "Filed": gov_data_field = "filed" @@ -674,7 +673,13 @@ def normalize_data(data): return data -def update_month_or_quarter(filters): +def update_filters(filters, filing_preference): + is_quarterly = 1 if filing_preference == "Quarterly" else 0 + + if filters.is_quarterly == is_quarterly: + return + + filters.is_quarterly = is_quarterly if filters.is_quarterly == 1: quarter = MONTH.index(filters.month_or_quarter) // 3 filters.month_or_quarter = QUARTER[quarter] diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js index 7175dbf8e4..6c5b7b5bf4 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.js @@ -4,7 +4,7 @@ frappe.ui.form.on("GST Return Log", { refresh(frm) { const [month_or_quarter, year] = india_compliance.get_month_year_from_period( - frm.doc.return_period, frm.doc.is_quarterly + frm.doc.return_period, frm.doc.filing_preference === "Monthly" ? 0 : 1 ); frm.add_custom_button(__("View GSTR-1"), () => { @@ -17,13 +17,14 @@ frappe.ui.form.on("GST Return Log", { clearInterval(interval); resolve(); } - }, 100); + }, 200); }).then(async () => { await cur_frm.set_value({ company: frm.doc.company, company_gstin: frm.doc.gstin, year: year, month_or_quarter: month_or_quarter, + is_quarterly : frm.doc.filing_preference == "Monthly" ? 0 : 1, }); cur_frm.save(); }); diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json index 07f3deda41..95f1bb77df 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.json @@ -12,7 +12,7 @@ "return_period", "company", "return_type", - "is_quarterly", + "filing_preference", "column_break_sqwh", "filing_date", "acknowledgement_number", @@ -190,9 +190,9 @@ "reqd": 1 }, { - "fieldname": "is_quarterly", + "fieldname": "filing_preference", "fieldtype": "Data", - "label": "Is Quarterly", + "label": "Filing Preference", "read_only": 1 } ], @@ -204,7 +204,7 @@ "link_fieldname": "reference_docname" } ], - "modified": "2024-11-06 17:47:55.754860", + "modified": "2024-11-07 23:12:55.966658", "modified_by": "Administrator", "module": "GST India", "name": "GST Return Log", 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 abcc28a601..37c3c385b2 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 @@ -120,7 +120,7 @@ frappe.ui.form.on(DOCTYPE, { const { filters } = message; const [month_or_quarter, year] = - india_compliance.get_month_year_from_period(filters.period, filters.is_quarterly); + india_compliance.get_month_year_from_period(filters.period, frm.doc.is_quarterly); if ( frm.doc.company_gstin !== filters.company_gstin || @@ -162,9 +162,8 @@ frappe.ui.form.on(DOCTYPE, { return; if(frm.doc.is_quarterly != filters.is_quarterly){ - frm.doc.is_quarterly = filters.is_quarterly - set_options_for_month_or_quarter(frm, set_only_options=true) - frm.doc.month_or_quarter = filters.month_or_quarter + frm.set_value("month_or_quarter", filters.month_or_quarter) + frm.set_value("is_quarterly", filters.is_quarterly) } frappe.after_ajax(() => { @@ -2131,7 +2130,7 @@ function set_options_for_year(frm) { async function update_fields_based_on_filing_preference(frm){ let {message : preference } = await frappe.call({ - method: "india_compliance.gst_india.doctype.gstr_1_beta.gstr_1_beta.get_filing_preference", + method: "india_compliance.gst_india.doctype.gstr_1_beta.gstr_1_beta.get_filing_preference_from_log", args: {month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin}, }) 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 0e3be5ff2d..02143be138 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 @@ -147,6 +147,9 @@ def on_generate(self, data, filters=None): """ Once data is generated, update the status and publish the data """ + if not filters: + filters = self + if getattr(self, "gstr1_log", None): self.gstr1_log.db_set( {"generation_status": "Generated", "is_latest_data": 1} @@ -249,8 +252,13 @@ def get_gstr_1_from_and_to_date( @frappe.whitelist() -def get_filing_preference(month_or_quarter: str, year: str, company_gstin): +def get_filing_preference_from_log(month_or_quarter: str, year: str, company_gstin): period = get_period(month_or_quarter, year) - return frappe.db.get_value( - "GST Return Log", f"GSTR1-{period}-{company_gstin}", "is_quarterly" + filing_preference = frappe.db.get_value( + "GST Return Log", f"GSTR1-{period}-{company_gstin}", "filing_preference" ) + + if not filing_preference: + return None + + return 1 if filing_preference == "Quarterly" else 0 diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index 0003623b11..83a3002e90 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -336,12 +336,12 @@ def get_gstr_1_return_status( return "Not Filed" -def get_filing_frequency(gstin, period): +def get_filing_preference(gstin, period): month = cint(period[:2]) year = cint(period[2:]) start_month = (month - 1) // 3 * 3 + 1 - quarter = (month - 1) // 3 + 1 + quarter = (month - 1) // 3 start_date = getdate(f"{year}-{start_month}-01") months_of_quarter = [start_month + i for i in range(3)] @@ -350,13 +350,13 @@ def get_filing_frequency(gstin, period): if filing_preference := frappe.get_list( "GST Return Log", filters={"name": ["in", log_names]}, - fields=["is_quarterly", "name"], + fields=["filing_preference"], ): for record in filing_preference: - if not record.get("is_quarterly"): + if not record.get("filing_preference"): continue - return record.get("is_quarterly") + return record.get("filing_preference") if frappe.db.get_value( "GST Return Log", log_names[0], "filing_status" @@ -366,7 +366,9 @@ def get_filing_frequency(gstin, period): api = GSTR1API(company_gstin=gstin) response = api.get_filing_preference(date=start_date).response - filing_preference = 1 if response[quarter].get("preference") == "Q" else 0 + filing_preference = ( + "Quarterly" if response[quarter].get("preference") == "Q" else "Monthly" + ) frappe.enqueue( create_gst_return_log_for_quarter, gstin=gstin, @@ -385,7 +387,7 @@ def create_gst_return_log_for_quarter(gstin, log_names, filing_preference): for log_name in log_names: if log_name in existing_log: frappe.db.set_value( - "GST Return Log", log_name, "is_quarterly", filing_preference + "GST Return Log", log_name, "filing_preference", filing_preference ) continue @@ -394,7 +396,7 @@ def create_gst_return_log_for_quarter(gstin, log_names, filing_preference): "doctype": "GST Return Log", "name": log_name, "return_type": "GSTR1", - "is_quarterly": filing_preference, + "filing_preference": filing_preference, "return_period": log_name.split("-")[1], "gstin": gstin, } diff --git a/india_compliance/public/js/utils.js b/india_compliance/public/js/utils.js index f2cb9fa0c0..1d8cb79120 100644 --- a/india_compliance/public/js/utils.js +++ b/india_compliance/public/js/utils.js @@ -43,7 +43,7 @@ Object.assign(india_compliance, { const year = period.slice(2); if (is_quarterly === 0) return [this.MONTH[month_number - 1], year]; - else return [this.QUARTER[Math.floor(month_number / 3)], year]; + else return [this.QUARTER[Math.floor(month_number / 3) - 1], year]; }, get_gstin_query(party, party_type = "Company") { From 1ee0d05bf8d7c9da8329d90354a3973062d850e5 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 8 Nov 2024 19:02:05 +0530 Subject: [PATCH 11/14] fix: set filing preference where it is not set --- .../gst_india/utils/gstin_info.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index 83a3002e90..2df2d74836 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -4,6 +4,7 @@ import frappe from frappe import _ +from frappe.query_builder import Case from frappe.utils import cint, get_last_day, getdate from india_compliance.exceptions import GSPServerError @@ -402,6 +403,57 @@ def create_gst_return_log_for_quarter(gstin, log_names, filing_preference): } ).insert() + update_log_without_filing_preference() + + +def update_log_without_filing_preference(): + gst_return_logs = frappe.get_all( + "GST Return Log", + filters={"filing_preference": ["is", "not set"]}, + fields=["name", "return_period", "gstin"], + ) + + if not gst_return_logs: + return + + filing_preferences = {} + logs_to_update = {} + + for log in gst_return_logs: + return_period = log.get("return_period") + gstin = log.get("gstin") + financial_year = get_fy(return_period) + key = f"{financial_year}:{gstin}" + + if key not in filing_preferences: + start_date = getdate(f"{return_period[2:]}-{return_period[:2]}-01") + api = GSTR1API(company_gstin=gstin) + filing_preferences[key] = api.get_filing_preference( + date=start_date + ).response + + month = cint(return_period[:2]) + quarter = (month - 1) // 3 + preference_data = filing_preferences.get(key) + logs_to_update[log.get("name")] = ( + "Quarterly" + if preference_data[quarter].get("preference") == "Q" + else "Monthly" + ) + + gst_return_log = frappe.qb.DocType("GST Return Log") + case_conditions = Case() + + for name, preference_data in logs_to_update.items(): + case_conditions.when(gst_return_log.name == name, preference_data) + + ( + frappe.qb.update(gst_return_log) + .set(gst_return_log.filing_preference, case_conditions) + .where(gst_return_log.name.isin(list(logs_to_update.keys()))) + .run() + ) + def get_fy(period, year_increment=0): month, year = period[:2], period[2:] From 35db9abd113a88cb37b05a7c3c6f47761051c4aa Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Sat, 9 Nov 2024 15:45:33 +0530 Subject: [PATCH 12/14] fix: removeing merge code --- india_compliance/gst_india/utils/gstin_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index 2df2d74836..15152e0ada 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -403,10 +403,10 @@ def create_gst_return_log_for_quarter(gstin, log_names, filing_preference): } ).insert() - update_log_without_filing_preference() + update_logs_without_filing_preference() -def update_log_without_filing_preference(): +def update_logs_without_filing_preference(): gst_return_logs = frappe.get_all( "GST Return Log", filters={"filing_preference": ["is", "not set"]}, From 6eac34822e3f373acf9f1d696644eabbac55687b Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 5 Dec 2024 12:01:18 +0530 Subject: [PATCH 13/14] fix: UI improvement for month or quarter --- .../doctype/gstr_1_beta/gstr_1_beta.js | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) 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 4d91cd6838..9e2b14a305 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 @@ -164,7 +164,7 @@ frappe.ui.form.on(DOCTYPE, { ) return; - if(frm.doc.is_quarterly != filters.is_quarterly){ + if (frm.doc.is_quarterly != filters.is_quarterly) { frm.set_value("month_or_quarter", filters.month_or_quarter) frm.set_value("is_quarterly", filters.is_quarterly) } @@ -185,7 +185,7 @@ frappe.ui.form.on(DOCTYPE, { frm.set_value("company_gstin", options[0]); }, - company_gstin(frm){ + company_gstin(frm) { render_empty_state(frm); update_fields_based_on_filing_preference(frm); }, @@ -200,9 +200,9 @@ frappe.ui.form.on(DOCTYPE, { set_options_for_month_or_quarter(frm); }, - is_quarterly(frm){ + is_quarterly(frm) { render_empty_state(frm); - set_options_for_month_or_quarter(frm); + update_month_or_quarter(frm) }, refresh(frm) { @@ -2893,46 +2893,45 @@ function set_options_for_year(frm) { frm.set_value("year", current_year.toString()); } -async function update_fields_based_on_filing_preference(frm){ - let {message : preference } = await frappe.call({ +async function update_fields_based_on_filing_preference(frm) { + let { message: preference } = await frappe.call({ method: "india_compliance.gst_india.doctype.gstr_1_beta.gstr_1_beta.get_filing_preference_from_log", - args: {month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin}, + args: { month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin }, }) - if(preference === undefined){ + if (preference === undefined) { frm.set_df_property("is_quarterly", "read_only", 0); return } preference = cint(preference) - - if(preference === frm.doc.is_quarterly){ + if (preference === frm.doc.is_quarterly) { frm.set_df_property("is_quarterly", "read_only", 1); return } - update_preference(frm, preference) -} - -function update_preference(frm, preference){ frm.doc.is_quarterly = preference frm.set_df_property("is_quarterly", "read_only", 1) - set_options_for_month_or_quarter(frm, set_only_options=true) + frm.refresh_field("is_quarterly") - if(preference === 1){ - const month_index = india_compliance.MONTH.indexOf(frm.doc.month_or_quarter) - const quarter = Math.floor(month_index / 3) + update_month_or_quarter(frm) +} + +function update_month_or_quarter(frm) { + set_options_for_month_or_quarter(frm, set_only_options = true) + + if (frm.doc.is_quarterly === 1) { + const quarter = cint(india_compliance.MONTH.indexOf(frm.doc.month_or_quarter) / 3) frm.doc.month_or_quarter = india_compliance.QUARTER[quarter] - }else{ - const quarter_index = india_compliance.QUARTER.indexOf(frm.doc.month_or_quarter) * 3 + } else { + const quarter_index = india_compliance.QUARTER.indexOf(frm.doc.month_or_quarter) // added 2 to set month_or_quarter as last month of that quarter - frm.doc.month_or_quarter = india_compliance.MONTH[quarter_index+2] + frm.doc.month_or_quarter = india_compliance.MONTH[(quarter_index * 3) + 2] } frm.refresh_field("month_or_quarter") - frm.refresh_field("is_quarterly") } -function set_options_for_month_or_quarter(frm, set_only_options=false) { +function set_options_for_month_or_quarter(frm, set_only_options = false) { /** * Set options for Month or Quarter based on the year and current date * 1. If the year is current year, then options are till current month From 39bc0721af47896ebcdc1db84a4f12f3e5d046f5 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 5 Dec 2024 17:08:56 +0530 Subject: [PATCH 14/14] fix: update logs with specific gstin --- india_compliance/gst_india/utils/gstin_info.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/india_compliance/gst_india/utils/gstin_info.py b/india_compliance/gst_india/utils/gstin_info.py index f839b8e6c4..4d92f06638 100644 --- a/india_compliance/gst_india/utils/gstin_info.py +++ b/india_compliance/gst_india/utils/gstin_info.py @@ -404,13 +404,13 @@ def create_gst_return_log_for_quarter(gstin, log_names, filing_preference): } ).insert() - update_logs_without_filing_preference() + update_logs_without_filing_preference(gstin) -def update_logs_without_filing_preference(): +def update_logs_without_filing_preference(gstin): gst_return_logs = frappe.get_all( "GST Return Log", - filters={"filing_preference": ["is", "not set"]}, + filters={"filing_preference": ["is", "not set"], "gstin": gstin}, fields=["name", "return_period", "gstin"], ) @@ -445,8 +445,8 @@ def update_logs_without_filing_preference(): gst_return_log = frappe.qb.DocType("GST Return Log") case_conditions = Case() - for name, preference_data in logs_to_update.items(): - case_conditions.when(gst_return_log.name == name, preference_data) + for log_name, filing_preference in logs_to_update.items(): + case_conditions.when(gst_return_log.name == log_name, filing_preference) ( frappe.qb.update(gst_return_log)