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 #2766

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 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 @@ -501,16 +501,18 @@ def validate_auth_token(self):

return

def get_filing_preference(self):
@request_cache
def get_filing_preference(self, date=None, fy=None):
return self.get(
action="GETPREF", params={"fy": self.get_fy()}, endpoint="returns"
)
action="GETPREF", params={"fy": fy or self.get_fy(date)}, endpoint="returns"
).response

@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 @@ -7,6 +7,7 @@
from frappe.utils import flt

from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API
from india_compliance.gst_india.utils.__init__ import get_month_or_quarter_dict
from india_compliance.gst_india.utils.gstr_1 import GovJsonKey, GSTR1_SubCategory
from india_compliance.gst_india.utils.gstr_1.__init__ import (
CATEGORY_SUB_CATEGORY_MAPPING,
Expand All @@ -24,13 +25,14 @@
summarize_retsum_data,
)

MONTH = list(get_month_or_quarter_dict().keys())[4:]
QUARTER = ["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"]
status_code_map = {
"P": "Processed",
"PE": "Processed with Errors",
"ER": "Error",
"IP": "In Progress",
}
MAXIMUM_UPLOAD_SIZE = 5200000


class SummarizeGSTR1:
Expand Down Expand Up @@ -550,6 +552,26 @@ def generate_gstr1_data(self, filters, callback=None):
# APIs Enabled
status = self.get_return_status()

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

filing_preference = get_filing_preference(
self.gstin, self.return_period, force=True
)
else:
filing_preference = self.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"
else:
Expand Down Expand Up @@ -623,7 +645,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
Sanket322 marked this conversation as resolved.
Show resolved Hide resolved
)

_filters = frappe._dict(
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
);
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 @@ -35,13 +33,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,
});
cur_frm.save();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"return_period",
"company",
"return_type",
"filing_preference",
"column_break_sqwh",
"filing_date",
"acknowledgement_number",
Expand Down Expand Up @@ -192,6 +193,12 @@
"read_only": 1,
"reqd": 1
},
{
"fieldname": "filing_preference",
"fieldtype": "Data",
"label": "Filing Preference",
"read_only": 1
},
{
"fieldname": "upload_error",
"fieldtype": "Attach",
Expand Down Expand Up @@ -224,7 +231,7 @@
"link_fieldname": "reference_docname"
}
],
"modified": "2024-10-02 12:16:04.271962",
"modified": "2024-12-19 13:28:20.406478",
"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
58 changes: 35 additions & 23 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,12 +108,14 @@ 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);
set_options_for_month_or_quarter(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;

Expand Down Expand Up @@ -162,11 +164,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;

if (frm.doc.is_quarterly != filters.is_quarterly) {
frm.set_value("is_quarterly", filters.is_quarterly)
}

frm.taxpayer_api_call("generate_gstr1").then(r => {
frm.doc.__gst_data = r.message;
frm.trigger("load_gstr1_data");
Expand All @@ -183,15 +188,19 @@ 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);
set_options_for_month_or_quarter(frm, true);
},

refresh(frm) {
Expand Down Expand Up @@ -2882,7 +2891,19 @@ function set_options_for_year(frm) {
frm.set_value("year", current_year.toString());
}

function set_options_for_month_or_quarter(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_from_log",
args: { month_or_quarter: frm.doc.month_or_quarter, year: frm.doc.year, company_gstin: frm.doc.company_gstin },
})

if (preference === undefined || preference === frm.doc.is_quarterly) return;

frm.doc.is_quarterly = preference
frm.refresh_field("is_quarterly")
}

function set_options_for_month_or_quarter(frm, with_update = 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 @@ -2901,28 +2922,18 @@ 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")
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.filing_frequency === "Monthly")
options = india_compliance.MONTH.slice(6);
else options = india_compliance.QUARTER.slice(2);
options = india_compliance.MONTH.slice(6);
} else {
if (frm.filing_frequency === "Monthly") options = india_compliance.MONTH;
else options = india_compliance.QUARTER;
options = india_compliance.MONTH;
}

set_field_options("month_or_quarter", options);

if (!with_update) return

if (frm.doc.year === current_year)
// set second last option as default
frm.set_value("month_or_quarter", options[options.length - 2]);
Expand Down Expand Up @@ -2952,6 +2963,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,
ljain112 marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand Down
13 changes: 12 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,22 @@
"fieldtype": "Select",
"label": "Month/Quarter",
"reqd": 1
},
{
"fieldname": "column_break_auof",
"fieldtype": "Column Break"
},
{
"fieldname": "is_quarterly",
"fieldtype": "Data",
"label": "Filing Preference"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-05-27 19:30:01.074149",
"modified": "2024-12-19 17:25:00.805422",
"modified_by": "Administrator",
"module": "GST India",
"name": "GSTR-1 Beta",
Expand Down
Loading