Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add filing period selection in gstr-1 beta #2669

14 changes: 8 additions & 6 deletions india_compliance/gst_india/api_classes/taxpayer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -465,16 +465,18 @@ def validate_auth_token(self):

return

def get_filing_preference(self):
@request_cache
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:]}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ 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)
Expand Down Expand Up @@ -577,7 +589,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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"), () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"return_period",
"company",
"return_type",
"is_quarterly",
"column_break_sqwh",
"filing_date",
"acknowledgement_number",
Expand Down Expand Up @@ -187,6 +188,12 @@
"label": "Return Type",
"read_only": 1,
"reqd": 1
},
{
"fieldname": "is_quarterly",
"fieldtype": "Data",
"label": "Is Quarterly",
"read_only": 1
}
],
"in_create": 1,
Expand All @@ -197,7 +204,7 @@
"link_fieldname": "reference_docname"
}
],
"modified": "2024-08-14 17:53:03.509293",
"modified": "2024-11-06 17:47:55.754860",
"modified_by": "Administrator",
"module": "GST India",
"name": "GST Return Log",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
65 changes: 56 additions & 9 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 @@ -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);
Expand All @@ -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 ||
Expand Down Expand Up @@ -159,11 +157,14 @@ 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

frappe.after_ajax(() => {
frm.doc.__gst_data = data ;
frm.trigger("load_gstr1_data");
Expand All @@ -180,17 +181,26 @@ 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) {
render_empty_state(frm);
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();
Expand Down Expand Up @@ -2117,7 +2127,41 @@ function set_options_for_year(frm) {
frm.set_value("year", current_year.toString());
}

function set_options_for_month_or_quarter(frm) {
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
* 1. If the year is current year, then options are till current month
Expand All @@ -2136,7 +2180,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;
Expand All @@ -2149,15 +2193,17 @@ 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;
}

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]);
Expand All @@ -2181,6 +2227,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,
},
});

Expand Down
14 changes: 13 additions & 1 deletion india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"year",
"column_break_qcor",
"month_or_quarter",
"column_break_auof",
"is_quarterly",
"data_section",
"tabs_html",
"tabs_empty_state",
Expand Down Expand Up @@ -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",
Expand Down
Loading