Skip to content

Commit

Permalink
feat: GSTR-1 Beta for filing (#2112)
Browse files Browse the repository at this point in the history
* feat: gstr-1 filed log

* fix: gstr-1 apis

* fix: GSTR-1 Mapping

* feat: GSTR-1 UI (#1910)

* feat: make GSTR-1 page

* fix: minor changes in data

* wip: gstr_1 beta

* wip: gstr-1 beta ui

* fix: working UI with dummy data

* refactor: public js folder structure

* fix: setup base for building columns

* chore: update demo data

* fix: consistent keys for sub categories

* style: dynmic name for `File` tab

* fix: overlap count for nil-rated , non-gst and exempted invoices

* test: test cases for `update item after submit` in Sales Order and Purchase Order (#1979)

* fix: group tax values and amounts for invoice print formats

* fix: missing gst amounts in hsn json

* chore: update compatible version

* chore: use similar color for all number cards

* fix: add overlaping invoice count summary to overview

* fix: group overview in GST sales register beta by category (#2002)

* fix: group overview in GST sales register beta by category

* fix: better way to override datatable totals

* chore: mapped data for gstr1

* fix: setup columns for gstr 1 beta

* fix: add totals row for the summary

* fix(minor): row width and checkbox for datatable

* wip: category and sub-category filtering

* fix: changes as per review

* fix: validate for cess non-advol (#2009)

* fix: validate for cess non-advol

* fix: remove duplicate code

* fix: changes as per view

* chore: fix type, less nesting

---------

Co-authored-by: ljain112 <[email protected]>

* test: test cases for gst sales register beta report (#1965)

* test: test cases for gst sales register beta report

* fix: linters and item_code

* fix: remove gst_treatement and posting date while creating invoices

* fix: remove gst_treatement and posting date while creating invoices

* fix: modified test cases

* test: super setup to cleanup data post tests

* refactor: test cases for sales register and modified required orderby in sales register beta report

* fix: test cases and utility function for appending items in sales invoice

* test: update similar treatment for original test cases

* test: modified test output for overview

---------

* test: test-cases for regional_overrides (#2006)

* fix: test-cases for regional_overrides

* refactor: test case placement and only required test cases

---------

Co-authored-by: Smit Vora <[email protected]>

* fix(minor): better way to override totals in gst sales beta report (#2022)

* fix: uom as per gst (#2019)

* fix: uom as per gst

* chore: refactor and wrap original function

---------

* refactor: seperate gstr_1 utilities

* refactor: commanify gstr_utils and make gstr_2 independent

* fix: prepare mapped data for hsn summary

* fix: added document issued summary in mapped data

* fix: reverse charge as "Y" or "N"

* style: basic tree view for summary

* fix: changed variable name

---------

Co-authored-by: Smit Vora <[email protected]>
Co-authored-by: Abdeali Chharchhodawala <[email protected]>
Co-authored-by: priyanshshah2442 <[email protected]>
Co-authored-by: Priyansh Shah <[email protected]>
Co-authored-by: Smit Vora <[email protected]>
Co-authored-by: Sanket322 <[email protected]>
Co-authored-by: ljain112 <[email protected]>

* feat: gstr-1 filed log (#2034)

* refactor: bring all puzzles together

* style: tree-view spacing

* fix(ui): expand datatable upto borders

* style: improvment of datatable

* fix(ui): setup listeners

* fix: gst settings for gstr-1

* fix: don't sub-categorise nil exempt and non-gst

* fix: nil expempt data for js and trial data

* fix: variable display of data based on status of return and gst settings

* fix: OTP workflow for gstr-1 beta to authenticate APIs

* chore: updated comments

* fix: return status API integration

* fix: gstr-1 mapping refactor

* fix: download APIs setup

* fix: mapping of data for AT and TXP

* fix: tuple key changed to f-string

* fix: tuple keys converted to string in gstr-1 json mapping

* fix: working data pieces

* fix: month and quarter depending on gst settings

* fix: transaction type for all invoices

* fix: summarize filed data

* fix: no of records in summarize filed data

* fix: gstr-1 json map refactor and guess customer name

* chore: update comments, minor refactor in js

* fix: reconcile books and gov data

* fix: mapped-data data format refactor

* fix: reconcile books vs returns

* chore: cleanup unused page

* fix: summarize data

* fix: add supecom category

* fix: totals for gstr-1 summary

* fix: month or quarter options as per selected year

* fix: better reconciliation and summarization

* fix: minor changes to date selection

* fix: refactor columns and consistent categories

* fix: supecom mapping and format date

* fix: working report with actual data

* wip: gst ledger difference

* fix: compute index in HSN and DOC_ISSUE Summary while converting to gov json

* fix: fix e-Invoice tab

* fix: difference in output gst ledger , collapse and expand button , computed on

* fix: minor changes while testing (#19)

* fix: e-Invoice data => unfiled data

* fix(ux): correct totals for books summary with missing records

* fix: subtitle for tabs

* fix: detail view for reconcile data

* refactorr: gstr_1 reconcile html template

* fix: output gst ledger called multiple times

* fix: changes to ledger data, etc

* fix: summarize return-summary data

* fix: summarize returns data with amendments

* wip: endpoint for json export with options

* fix: round books value, default blank table message

* fix: changes as per review

* fix: check gstr-1 filed upto and review js

* fix: highlight difference if there

* fix: validate and update latest data

* refactor: class name, circular import

* chore: update todos

* fix: compute item index while converting to gov json format

* fix: creation time for the report

* fix: recompute books data

* fix: download excel for books data

* fix: download gstr-1 json

* fix: gstr-1 upload errors resolved

* fix: ignore str in json generation

* fix: load data after all existing requests are complete

* fix: update todos, show report from filed log

* fix: action mark as filed

* fix: generate summary for apis disabled

* fix: download reconcile excel and refactor download books excel

* fix: download json causing errror

* fix: excel headers as per review

* fix: colour for header and data

* fix: download filed excel

---------

Co-authored-by: Abdeali Chharchhodawala <[email protected]>
Co-authored-by: Vishakh Desai <[email protected]>
Co-authored-by: priyanshshah2442 <[email protected]>

* fix: file naming and sheet naming

* fix: Sheet naming as per mapping

* fix: changes required to make it work

* fix: excel column widths

* fix: width for specific column in books and recncile excel download

* fix: export gstr-1 excel

* fix: as per review

* fix: default formatting changes in excel format

* fix: excel-export refactor

* fix: don't send ecommerce gstin info to gov in regular sections

* fix: b2b invoice types and enum

* fix: refactor aggregate_invoices in NilRated GSTR-1 Mapping

* fix: delete flag instead of zero values to handle missing in books

* fix: check for production api's enabled for gstr-1

* refactor: file and code blocks restructuring

* refactor: indentation to spaces

* fix: remove unrequired data

* fix: fixed failing test cases and re-arranged fields in Gov excel export as per Gov format

* fix: set flag for otp_requested

* fix: default permissions and update mark as filed

* fix: save gstr1 filed upto in gstin doc

* fix: minor codacy issues

* fix: semgrep rules

* fix: more fixes for codacy

* refactor: gstr-1 generation and summarization

* fix: correct empty state text

* fix: default frequency to monthly

* fix: readonly fields for filed log

* chore: correct function name

* refactor: enum names

* refactor: data export and comminify utilities

* refactor: common columns for reconcile

* chore: linters

* fix: ecommerce data summary conversion

* fix: fallback for legacy summary data.

* fix: process additional returns information after commit

* fix: show gstr_1 beta alert on existing report

* refactor: gstr-1 beta js

* fix: codacy issues

* chore: comments and todos

* fix: gstr-1 json map doc-string added

* fix: consistent data conversion, brief comments

* fix: buttons based on API status

* fix: modified docstring in gstr_1_json_map and fixed test cases

* fix: non-mandatory fields in backend (single doctype), year options set dynamically

* chore: formatting changes

* chore: mark fields as mandatory

* fix: return filed upto from db

* fix: test cases and update ignored categories for overview

* fix: re-compute if files are missing

* fix: support delete permissions for beta

* fix: changes as per review

* fix: correct data computation for nil exempt

* fix: show aggregated data for filing

* refactor: renamed to GSTR-1 log

* fix: minor enhancements to ui

* fix: load normalized data in download_gstr1_json and fixed test cases

* fix: support dynamic filters for detailed view

* fix: disabled detail view

* fix: ignore tax rate when getting difference

* fix: changes as per review

* fix: save aggregated data in books data

* fix: delete unfiled files after return is filed

* fix: update books json after aggregate data

* fix: back button setup for detailed view

* fix: aggregation, Inter vs Intra based on company gstin

* fix: export positive values for select sections

* chore: remove print statement

* fix: b2cs data processing for books excel consistently

* test: rename variable in test case

* fix: json export, upload, sync test

* fix: show only required columns in details view

* fix: update dashboard for other report

---------

Co-authored-by: Vishakh Desai <[email protected]>
Co-authored-by: Divyam Mistry <[email protected]>
Co-authored-by: Abdeali Chharchhodawala <[email protected]>
Co-authored-by: priyanshshah2442 <[email protected]>
Co-authored-by: Priyansh Shah <[email protected]>
Co-authored-by: Sanket322 <[email protected]>
Co-authored-by: ljain112 <[email protected]>
(cherry picked from commit e2f1f3e)

# Conflicts:
#	india_compliance/gst_india/doctype/gst_settings/gst_settings.json
#	india_compliance/gst_india/doctype/gstin/gstin.json
#	india_compliance/gst_india/utils/gstr/__init__.py
#	india_compliance/gst_india/utils/gstr/gstr_1_download.py
#	india_compliance/gst_india/utils/gstr/gstr_1_json_map.py
#	india_compliance/gst_india/utils/gstr/test_gstr_1_json_map.py
#	india_compliance/gst_india/utils/gstr_utils.py
  • Loading branch information
vorasmit authored and mergify[bot] committed Jun 8, 2024
1 parent 20ac4e3 commit 1fc6fa2
Show file tree
Hide file tree
Showing 53 changed files with 11,123 additions and 318 deletions.
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 @@ -229,8 +229,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 @@ -409,3 +411,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
47 changes: 47 additions & 0 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.json
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,53 @@
"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": [],
<<<<<<< HEAD
"modified": "2024-03-21 19:36:00.878806",
=======
"modified": "2024-05-17 15:46:11.169920",
>>>>>>> e2f1f3e2 (feat: GSTR-1 Beta for filing (#2112))
"modified_by": "Administrator",
"module": "GST India",
"name": "GST Settings",
Expand Down
91 changes: 89 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,26 @@ 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)
)

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 +365,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 +432,52 @@ 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

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",
)
18 changes: 17 additions & 1 deletion 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,26 @@
"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": [],
<<<<<<< HEAD
"modified": "2023-08-17 11:32:42.332746",
=======
"modified": "2024-05-17 15:38:05.867522",
>>>>>>> e2f1f3e2 (feat: GSTR-1 Beta for filing (#2112))
"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

0 comments on commit 1fc6fa2

Please sign in to comment.