Skip to content

Commit

Permalink
fix: minor refactor and change in gstr-1 from_date nad to_date
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Dec 24, 2024
1 parent 672334a commit 6b39d0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,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.is_quarterly
filters.month_or_quarter, filters.year
)

_filters = frappe._dict(
Expand Down
24 changes: 7 additions & 17 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 @@ -329,9 +329,7 @@ def get_net_gst_liability(company, company_gstin, month_or_quarter, year, is_qua

frappe.has_permission("GSTR-1 Beta", throw=True)

from_date, to_date = get_gstr_1_from_and_to_date(
month_or_quarter, year, is_quarterly
)
from_date, to_date = get_gstr_1_from_and_to_date(month_or_quarter, year)

filters = frappe._dict(
{
Expand Down Expand Up @@ -387,25 +385,17 @@ 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, is_quarterly: str
) -> tuple:
def get_gstr_1_from_and_to_date(month_or_quarter: str, year: 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
"""
if is_quarterly == "Quarterly":
month_index = MONTH.index(month_or_quarter)
start_month = end_month = MONTH.index(month_or_quarter) + 1
if start_month % 3 == 0:
start_month -= 2

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:
# Monthly (default)
from_date = getdate(f"{year}-{month_or_quarter}-01")
to_date = get_last_day(from_date)
from_date = getdate(f"{year}-{start_month}-01")
to_date = get_last_day(f"{year}-{end_month}-01")

return from_date, to_date

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def patch_filing_preference(gstin):
"filing_preference": ["is", "not set"],
"gstin": gstin,
"return_period": ["!=", "ALL"],
"return_type": "GSTR1",
},
fields=["name", "return_period", "gstin"],
)
Expand Down

0 comments on commit 6b39d0a

Please sign in to comment.