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

test: GSTR-1 beta #2244

Draft
wants to merge 72 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f7c8798
feat: gstr-1 filed log
vorasmit Mar 11, 2024
004bafe
fix: gstr-1 apis
vishakhdesai Mar 22, 2024
5314d4f
Merge branch 'develop' into gstr-1
vorasmit Apr 8, 2024
eb92d21
fix: GSTR-1 Mapping
vishakhdesai Apr 12, 2024
fca10a9
Merge pull request #1913 from vishakhdesai/gstr_1_apis
vorasmit Apr 12, 2024
59a4167
feat: GSTR-1 UI (#1910)
divyam-mistry Apr 12, 2024
ef53933
Merge pull request #2033 from vishakhdesai/gstr1-mapping
vorasmit Apr 12, 2024
03e65c8
feat: gstr-1 filed log (#2034)
vorasmit May 12, 2024
eeba304
fix: file naming and sheet naming
priyanshshah2442 May 13, 2024
a0ececf
fix: Sheet naming as per mapping
priyanshshah2442 May 13, 2024
93ed669
fix: changes required to make it work
vorasmit May 13, 2024
2045ab4
fix: excel column widths
vishakhdesai May 14, 2024
de1a19a
fix: width for specific column in books and recncile excel download
priyanshshah2442 May 15, 2024
e342c49
fix: export gstr-1 excel
vishakhdesai May 15, 2024
0e32fa4
Merge branch 'develop' into gstr1
vorasmit May 15, 2024
8911490
fix: as per review
priyanshshah2442 May 15, 2024
0881028
fix: default formatting changes in excel format
vorasmit May 15, 2024
6910a27
fix: excel-export refactor
vishakhdesai May 15, 2024
6569abc
fix: don't send ecommerce gstin info to gov in regular sections
vorasmit May 16, 2024
4248141
fix: b2b invoice types and enum
vorasmit May 16, 2024
cbeac8e
fix: refactor aggregate_invoices in NilRated GSTR-1 Mapping
vishakhdesai May 16, 2024
29caf75
fix: delete flag instead of zero values to handle missing in books
vorasmit May 16, 2024
26340e3
fix: check for production api's enabled for gstr-1
vorasmit May 16, 2024
302c2c2
refactor: file and code blocks restructuring
vorasmit May 16, 2024
101be7c
refactor: indentation to spaces
vorasmit May 16, 2024
1da6b2c
fix: remove unrequired data
vorasmit May 16, 2024
7408c32
fix: fixed failing test cases and re-arranged fields in Gov excel exp…
vishakhdesai May 17, 2024
0df5f10
fix: set flag for otp_requested
vorasmit May 17, 2024
7dec73e
fix: default permissions and update mark as filed
vorasmit May 17, 2024
7200b29
fix: save gstr1 filed upto in gstin doc
vorasmit May 17, 2024
c7bbff6
fix: minor codacy issues
vorasmit May 18, 2024
2267e93
fix: semgrep rules
vorasmit May 18, 2024
0399d4e
fix: more fixes for codacy
vorasmit May 18, 2024
f57afe4
refactor: gstr-1 generation and summarization
vorasmit May 20, 2024
5458ed1
fix: correct empty state text
vorasmit May 20, 2024
74957f4
fix: default frequency to monthly
vorasmit May 20, 2024
0e2ee5b
fix: readonly fields for filed log
vorasmit May 20, 2024
9c2b335
chore: correct function name
vorasmit May 20, 2024
1d4ef10
refactor: enum names
vorasmit May 20, 2024
66662c8
refactor: data export and comminify utilities
vorasmit May 20, 2024
e4d5121
refactor: common columns for reconcile
vorasmit May 20, 2024
ea73cd7
chore: linters
vorasmit May 20, 2024
4481756
fix: ecommerce data summary conversion
vorasmit May 22, 2024
9265002
fix: fallback for legacy summary data.
vorasmit May 24, 2024
1764d29
fix: process additional returns information after commit
vorasmit May 24, 2024
1339f3f
fix: show gstr_1 beta alert on existing report
vorasmit May 24, 2024
da1607f
refactor: gstr-1 beta js
vorasmit May 24, 2024
1a66af7
Merge branch 'develop' into gstr1
vorasmit May 24, 2024
7ab0cc8
fix: codacy issues
vorasmit May 24, 2024
5571999
chore: comments and todos
vorasmit May 24, 2024
e5c8cf1
fix: gstr-1 json map doc-string added
vishakhdesai May 27, 2024
98bca6d
fix: consistent data conversion, brief comments
vorasmit May 27, 2024
5e3f562
fix: buttons based on API status
vorasmit May 27, 2024
e9e95a8
fix: modified docstring in gstr_1_json_map and fixed test cases
vishakhdesai May 27, 2024
1589977
fix: non-mandatory fields in backend (single doctype), year options s…
vorasmit May 27, 2024
7a8118c
chore: formatting changes
vorasmit May 27, 2024
91e0f9f
chore: mark fields as mandatory
vorasmit May 27, 2024
2a23f94
fix: return filed upto from db
vorasmit May 28, 2024
34eacca
fix: test cases and update ignored categories for overview
vorasmit May 28, 2024
1a59f28
fix: re-compute if files are missing
vorasmit May 28, 2024
ba1e2c0
fix: support delete permissions for beta
vorasmit May 28, 2024
3ec047b
fix: changes as per review
vorasmit May 30, 2024
aaa5530
fix: correct data computation for nil exempt
vorasmit May 30, 2024
46a5a72
fix: show aggregated data for filing
vorasmit May 30, 2024
80f810f
refactor: renamed to GSTR-1 log
vorasmit May 30, 2024
1c04146
fix: minor enhancements to ui
vorasmit May 30, 2024
218fbc3
fix: load normalized data in download_gstr1_json and fixed test cases
vishakhdesai May 30, 2024
7b2101f
Merge branch 'develop' into gstr1
vorasmit Jun 5, 2024
4e1f9f3
fix: support dynamic filters for detailed view
vorasmit Jun 5, 2024
eaf2793
fix: disabled detail view
vorasmit Jun 5, 2024
8b2a4a8
fix: ignore tax rate when getting difference
vorasmit Jun 5, 2024
6b2fb1a
fix: test cases for gstr1
priyanshshah2442 Jun 6, 2024
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
5 changes: 5 additions & 0 deletions india_compliance/gst_india/api_classes/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ def get_gstin_info(self, gstin):
)

return response

def get_returns_info(self, gstin, fy):
return self.get(
"returns", params={"action": "RETTRACK", "gstin": gstin, "fy": fy}
)
24 changes: 24 additions & 0 deletions india_compliance/gst_india/api_classes/returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ class ReturnsAPI(ReturnsAuthenticate):
"RET2B1023": "not_generated",
"RET2B1016": "no_docs_found",
"RT-3BAS1009": "no_docs_found",
"RET11417": "no_docs_found", # GSTR-1 Exports
"RET2B1018": "requested_before_cutoff_date",
"RTN_24": "queued",
"AUTH158": "invalid_otp", # Invalid OTP
"AUTH4033": "invalid_otp", # Invalid Session
# "AUTH4034": "invalid_otp", # Invalid OTP
"AUTH4038": "authorization_failed", # Session Expired
Expand Down Expand Up @@ -396,3 +398,25 @@ def get_data(self, action, return_period, otp=None):
endpoint="returns/gstr2a",
otp=otp,
)


class GSTR1API(ReturnsAPI):
API_NAME = "GSTR-1"

def get_gstr_1_data(self, action, return_period, otp=None):
return self.get(
action,
return_period,
params={"ret_period": return_period},
endpoint="returns/gstr1",
otp=otp,
)

def get_einvoice_data(self, section, return_period, otp=None):
return self.get(
"EINV",
return_period,
params={"ret_period": return_period, "sec": section},
endpoint="returns/einvoice",
otp=otp,
)
43 changes: 15 additions & 28 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,22 @@ function filter_accounts(frm, account_field) {

function show_ic_api_promo(frm) {
if (!frm.doc.__onload?.can_show_promo) return;
const alert_message = `
Looking for API Features?
<a href="/app/india-compliance-account" class="alert-link">
Get started with the India Compliance API!
</a>`;

const alert = $(`
<div
class="alert alert-primary alert-dismissable fade show d-flex justify-content-between border-0"
role="alert"
>
<div>
Looking for API Features?
<a href="/app/india-compliance-account" class="alert-link">
Get started with the India Compliance API!
</a>
</div>
<button
type="button"
class="close"
data-dismiss="alert"
aria-label="Close"
style="outline: 0px solid black !important"
>
<span aria-hidden="true">&times;</span>
</button>
</div>
`).prependTo(frm.layout.wrapper);

alert.on("closed.bs.alert", () => {
frappe.xcall(
"india_compliance.gst_india.doctype.gst_settings.gst_settings.disable_api_promo"
);
});
india_compliance.show_dismissable_alert(
frm.layout.wrapper,
alert_message,
"primary",
() => {
frappe.xcall(
"india_compliance.gst_india.doctype.gst_settings.gst_settings.disable_api_promo"
);
}
);
}

function show_update_gst_category_button(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
"column_break_17",
"e_invoice_applicable_from",
"e_invoice_applicable_companies",
"gstr_1_section_break",
"analyze_filed_data",
"filing_frequency",
"column_break_cxmn",
"restrict_changes_after_gstr_1",
"role_allowed_to_modify",
"other_apis_section",
"autofill_party_info",
"archive_party_info_days",
Expand Down Expand Up @@ -560,12 +566,49 @@
"fieldtype": "Check",
"hidden": 1,
"label": "Is Retry e-Invoice/e-Waybill Pending"
},
{
"fieldname": "gstr_1_section_break",
"fieldtype": "Section Break",
"label": "GSTR-1"
},
{
"default": "0",
"depends_on": "eval: india_compliance.is_api_enabled(doc)",
"description": "Compare Books with GSTR 1 Filed or Invoice data before filing",
"fieldname": "analyze_filed_data",
"fieldtype": "Check",
"label": "Analyze Filed Data"
},
{
"fieldname": "column_break_cxmn",
"fieldtype": "Column Break"
},
{
"fieldname": "filing_frequency",
"fieldtype": "Select",
"label": "Filing Frequency",
"options": "Monthly\nQuarterly"
},
{
"fieldname": "role_allowed_to_modify",
"fieldtype": "Link",
"label": "Role Allowed to Modify Transactions",
"options": "Role"
},
{
"default": "0",
"depends_on": "eval: india_compliance.is_api_enabled(doc)",
"description": "Ensures restrictions to cancel or create transactions after return is marked as filed",
"fieldname": "restrict_changes_after_gstr_1",
"fieldtype": "Check",
"label": "Restrict changes after GSTR 1 is filed"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-03-29 11:54:42.957295",
"modified": "2024-05-17 15:46:11.169920",
"modified_by": "Administrator",
"module": "GST India",
"name": "GST Settings",
Expand Down
100 changes: 98 additions & 2 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
from frappe import _
from frappe.model.document import Document
from frappe.query_builder.functions import IfNull
from frappe.utils import getdate
from frappe.utils import add_to_date, getdate

from india_compliance.gst_india.constants import GST_ACCOUNT_FIELDS, GST_PARTY_TYPES
from india_compliance.gst_india.constants.custom_fields import (
E_INVOICE_FIELDS,
E_WAYBILL_FIELDS,
SALES_REVERSE_CHARGE_FIELDS,
)
from india_compliance.gst_india.doctype.gstin.gstin import get_gstr_1_filed_upto
from india_compliance.gst_india.page.india_compliance_account import (
_disable_api_promo,
post_login,
)
from india_compliance.gst_india.utils import can_enable_api, is_api_enabled
from india_compliance.gst_india.utils.custom_fields import toggle_custom_fields
from india_compliance.gst_india.utils.e_invoice import get_e_invoice_applicability_date
from india_compliance.gst_india.utils.gstin_info import get_gstin_info

E_INVOICE_START_DATE = "2021-01-01"
Expand Down Expand Up @@ -270,6 +270,27 @@ def validate_e_invoice_applicable_companies(self):

company_list.append(row.company)

def is_sek_valid(self, gstin, throw=True, threshold=30):
for credential in self.credentials:
if credential.service == "Returns" and credential.gstin == gstin:
break

else:
if throw:
frappe.throw(
_(
"No credential found for the GSTIN {0} in the GST Settings"
).format(gstin)
)

# TODO: Handle this
return False

if credential.session_expiry and credential.session_expiry > add_to_date(
None, minutes=threshold * -1
):
return True


@frappe.whitelist()
def disable_api_promo():
Expand Down Expand Up @@ -345,6 +366,24 @@ def update_e_invoice_status():
update_not_applicable_status(e_invoice_applicability_date, company)


def get_e_invoice_applicability_date(company, settings=None, throw=True):
if not settings:
settings = frappe.get_cached_doc("GST Settings")

e_invoice_applicable_from = settings.e_invoice_applicable_from

if settings.apply_e_invoice_only_for_selected_companies:
for row in settings.e_invoice_applicable_companies:
if company == row.company:
e_invoice_applicable_from = row.applicable_from
break

else:
return

return e_invoice_applicable_from


def update_pending_status(e_invoice_applicability_date, company=None):
if not e_invoice_applicability_date:
return
Expand Down Expand Up @@ -394,3 +433,60 @@ def update_not_applicable_status(e_invoice_applicability_date=None, company=None
company = query.where(sales_invoice.company == company)

query.run()


def restrict_gstr_1_transaction_for(posting_date, company_gstin, gst_settings=None):
"""
Check if the user is allowed to modify transactions before the GSTR-1 filing date
Additionally, update the `is_not_latest_gstr1_data` field in the GSTR-1 Log
"""
posting_date = getdate(posting_date)

if not gst_settings:
gst_settings = frappe.get_cached_doc("GST Settings")

restrict = True

if not gst_settings.restrict_changes_after_gstr_1:
restrict = False

gstr_1_filed_upto = get_gstr_1_filed_upto(company_gstin)

if not gstr_1_filed_upto:
return False

if posting_date > getdate(gstr_1_filed_upto):
restrict = False

if (
gst_settings.role_allowed_to_modify in frappe.get_roles()
or frappe.session.user == "Administrator"
):
restrict = False

if restrict:
return gstr_1_filed_upto

if restrict is False:
return None

frappe.msgprint(
_("You are modifying transaction after the GSTR-1 is filed for the period."),
indicator="yellow",
)

update_is_not_latest_gstr1_data(posting_date, company_gstin)

return None


def update_is_not_latest_gstr1_data(posting_date, company_gstin):
period = posting_date.strftime("%m%Y")

frappe.db.set_value("GSTR-1 Log", f"{period}-{company_gstin}", "is_latest_data", 0)

frappe.publish_realtime(
"is_not_latest_data",
message={"filters": {"company_gstin": company_gstin, "period": period}},
doctype="GSTR-1 Beta",
)
16 changes: 14 additions & 2 deletions india_compliance/gst_india/doctype/gstin/gstin.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"is_blocked",
"column_break_nrjd",
"last_updated_on",
"cancelled_date"
"cancelled_date",
"section_break_ttzc",
"gstr_1_filed_upto"
],
"fields": [
{
Expand Down Expand Up @@ -59,12 +61,22 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Is Blocked"
},
{
"fieldname": "section_break_ttzc",
"fieldtype": "Section Break"
},
{
"fieldname": "gstr_1_filed_upto",
"fieldtype": "Date",
"hidden": 1,
"label": "GSTR-1 Filed Upto"
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-03-29 11:54:43.241749",
"modified": "2024-05-17 15:38:05.867522",
"modified_by": "Administrator",
"module": "GST India",
"name": "GSTIN",
Expand Down
7 changes: 7 additions & 0 deletions india_compliance/gst_india/doctype/gstin/gstin.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,10 @@ def get_transporter_id_info(transporter_id):
"status": "Active" if response.transin else "Invalid",
}
)


def get_gstr_1_filed_upto(gstin):
if not gstin:
return

return frappe.db.get_value("GSTIN", gstin, "gstr_1_filed_upto")
Empty file.
Loading
Loading