From 3feb2ea6a1962739fc56671cc1a0f6ca5d64d5bc Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Tue, 22 Oct 2024 12:23:18 +0530 Subject: [PATCH] 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 75ea1ca07..ca211f797 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 0c7e31968..7175dbf8e 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 4f98e1235..1be063f62 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 2df782df5..44bd0a756 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 d0f7f0028..d22528a6d 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 7c941bb49..0262de2b4 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 a889da558..f2cb9fa0c 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]; },