Skip to content

Commit

Permalink
fix: quarterly as data field and some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Dec 20, 2024
1 parent 0e9f78f commit 672334a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,10 @@ def generate_gstr1_data(self, filters, callback=None):
# APIs Enabled
status = self.get_return_status()

# TODO: only if status is unfiled and first month or filing pref is not set
if True:
if (
status != "Filed"
and filters.month_or_quarter in ["January", "April", "July", "October"]
) or not self.filing_preference:
from india_compliance.gst_india.utils.gstin_info import (
get_filing_preference,
)
Expand All @@ -564,9 +566,11 @@ def generate_gstr1_data(self, filters, callback=None):
else:
filing_preference = self.filing_preference

if filing_preference and self.filing_preference is None:
self.db_set({"filing_preference": filing_preference})
update_filters(filters, filing_preference)
if (
self.filing_preference is None
or filters.is_quarterly != self.filing_preference
):
filters.is_quarterly = self.filing_preference = filing_preference

if status == "Filed":
gov_data_field = "filed"
Expand Down Expand Up @@ -725,21 +729,6 @@ def normalize_data(data):
return data


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]
else:
quarter_idx = QUARTER.index(filters.month_or_quarter)
filters.month_or_quarter = MONTH[(quarter_idx * 3) + 2]


class FileGSTR1:
def reset_gstr1(self, force):
verify_request_in_progress(self, force)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,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.filing_preference === "Monthly" ? 0 : 1
);
const [month_or_quarter, year] = india_compliance.get_month_year_from_period(frm.doc.return_period);

frm.add_custom_button(__("View GSTR-1"), () => {
frappe.set_route("Form", "GSTR-1 Beta");
Expand All @@ -42,7 +40,7 @@ frappe.ui.form.on("GST Return Log", {
company_gstin: frm.doc.gstin,
year: year,
month_or_quarter: month_or_quarter,
is_quarterly : frm.doc.filing_preference == "Monthly" ? 0 : 1,
is_quarterly: frm.doc.filing_preference,
});
cur_frm.save();
});
Expand Down
59 changes: 9 additions & 50 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,18 @@ frappe.ui.form.on(DOCTYPE, {
set_options_for_year(frm);
set_options_for_month_or_quarter(frm, true);

if (is_gstr1_api_enabled()) {
frm.set_df_property("is_quarterly", "read_only", 1);
}

frm.__setup_complete = true;

// Setup Listeners
frappe.realtime.on("is_not_latest_data", message => {
const { filters } = message;

const [month_or_quarter, year] =
india_compliance.get_month_year_from_period(filters.period, frm.doc.is_quarterly);
india_compliance.get_month_year_from_period(filters.period);

if (
frm.doc.company_gstin !== filters.company_gstin ||
Expand Down Expand Up @@ -165,7 +169,6 @@ frappe.ui.form.on(DOCTYPE, {
return;

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)
}

Expand Down Expand Up @@ -200,11 +203,6 @@ frappe.ui.form.on(DOCTYPE, {
set_options_for_month_or_quarter(frm, true);
},

is_quarterly(frm) {
render_empty_state(frm);
update_month_or_quarter(frm)
},

refresh(frm) {
frm.disable_save();

Expand Down Expand Up @@ -2899,36 +2897,10 @@ async function update_fields_based_on_filing_preference(frm) {
args: { month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin },
})

if (preference === undefined) {
frm.set_df_property("is_quarterly", "read_only", 0);
return
}

preference = cint(preference)
if (preference === frm.doc.is_quarterly) {
frm.set_df_property("is_quarterly", "read_only", 1);
return
}
if (preference === undefined || preference === frm.doc.is_quarterly) return;

frm.doc.is_quarterly = preference
frm.set_df_property("is_quarterly", "read_only", 1)
frm.refresh_field("is_quarterly")

update_month_or_quarter(frm)
}

function update_month_or_quarter(frm) {
set_options_for_month_or_quarter(frm)

if (frm.doc.is_quarterly === 1) {
const quarter_index = cint(india_compliance.MONTH.indexOf(frm.doc.month_or_quarter) / 3)
frm.doc.month_or_quarter = india_compliance.QUARTER[quarter_index]
} else {
const quarter_index = india_compliance.QUARTER.indexOf(frm.doc.month_or_quarter)
// last month of that quarter
frm.doc.month_or_quarter = india_compliance.MONTH[(quarter_index * 3) + 2]
}
frm.refresh_field("month_or_quarter")
}

function set_options_for_month_or_quarter(frm, with_update = false) {
Expand All @@ -2950,25 +2922,12 @@ function set_options_for_month_or_quarter(frm, with_update = false) {

if (frm.doc.year === current_year) {
// Options for current year till current month
if (frm.doc.is_quarterly === 0)
options = india_compliance.MONTH.slice(0, current_month_idx + 1);
else {
let quarter_idx;
if (current_month_idx <= 2) quarter_idx = 1;
else if (current_month_idx <= 5) quarter_idx = 2;
else if (current_month_idx <= 8) quarter_idx = 3;
else quarter_idx = 4;

options = india_compliance.QUARTER.slice(0, quarter_idx);
}
options = india_compliance.MONTH.slice(0, current_month_idx + 1);
} else if (frm.doc.year === "2017") {
// Options for 2017 from July to December
if (frm.doc.is_quarterly === 0)
options = india_compliance.MONTH.slice(6);
else options = india_compliance.QUARTER.slice(2);
options = india_compliance.MONTH.slice(6);
} else {
if (frm.doc.is_quarterly === 0) options = india_compliance.MONTH;
else options = india_compliance.QUARTER;
options = india_compliance.MONTH;
}

set_field_options("month_or_quarter", options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@
"fieldtype": "Column Break"
},
{
"default": "0",
"fieldname": "is_quarterly",
"fieldtype": "Check",
"label": "Is Quarterly"
"fieldtype": "Data",
"label": "Filing Preference"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-10-17 18:50:23.515301",
"modified": "2024-12-19 17:25:00.805422",
"modified_by": "Administrator",
"module": "GST India",
"name": "GSTR-1 Beta",
Expand Down
13 changes: 9 additions & 4 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from frappe.model.document import Document
from frappe.query_builder import Case
from frappe.query_builder.functions import Date, IfNull, Sum
from frappe.utils import cint, get_last_day, getdate
from frappe.utils import get_last_day, getdate

from india_compliance.gst_india.api_classes.taxpayer_base import (
TaxpayerBaseAPI,
otp_handler,
)
from india_compliance.gst_india.doctype.gst_return_log.generate_gstr_1 import (
MONTH,
verify_request_in_progress,
)
from india_compliance.gst_india.utils import get_gst_accounts_by_type
Expand Down Expand Up @@ -393,8 +394,12 @@ def get_gstr_1_from_and_to_date(
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
"""
if cint(is_quarterly):
start_month, end_month = month_or_quarter.split("-")
if is_quarterly == "Quarterly":
month_index = MONTH.index(month_or_quarter)

start_month = month_index // 3 * 3 + 1
end_month = start_month + 2

from_date = getdate(f"{year}-{start_month}-01")
to_date = get_last_day(f"{year}-{end_month}-01")
else:
Expand All @@ -415,4 +420,4 @@ def get_filing_preference_from_log(month_or_quarter: str, year: str, company_gst
if not filing_preference:
return None

return 1 if filing_preference == "Quarterly" else 0
return filing_preference
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ def patch_filing_preference(gstin):
filters={
"filing_preference": ["is", "not set"],
"gstin": gstin,
"return_perid": ["!=", "ALL"],
"return_period": ["!=", "ALL"],
},
fields=["name", "return_period", "gstin"],
)

if not logs:
return

gst_return_log = {}
for log in logs:
preference = fetch_filing_preference(log.gstin, log.return_period)
frappe.db.set_value("GST Return Log", log.name, "filing_preference", preference)
gst_return_log[log.name] = {"filing_preference": preference}

frappe.db.bulk_update("GST Return Log", gst_return_log, update_modified=False)
5 changes: 2 additions & 3 deletions india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Object.assign(india_compliance, {

QUARTER: ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"],

get_month_year_from_period(period, is_quarterly) {
get_month_year_from_period(period) {
/**
* Returns month or quarter and year from the period
* Month or quarter depends on the filing frequency set in GST Settings
Expand All @@ -43,8 +43,7 @@ Object.assign(india_compliance, {
const month_number = period.slice(0, 2);
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) - 1], year];
return [this.MONTH[month_number - 1], year];
},

get_gstin_query(party, party_type = "Company") {
Expand Down

0 comments on commit 672334a

Please sign in to comment.