Skip to content

Commit

Permalink
fix: changes based on new field
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Oct 18, 2024
1 parent fde5478 commit 5ea4171
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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
15 changes: 11 additions & 4 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
16 changes: 10 additions & 6 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 @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
},
});

Expand Down
18 changes: 10 additions & 8 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 @@ -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,
Expand Down Expand Up @@ -125,6 +125,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:
Expand Down Expand Up @@ -166,14 +167,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(
{
Expand Down Expand Up @@ -229,15 +232,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")
Expand Down
1 change: 0 additions & 1 deletion india_compliance/gst_india/setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
},

Expand Down

0 comments on commit 5ea4171

Please sign in to comment.