Skip to content

Commit

Permalink
feat: auto-reconcile purchases with GSTR2A (#1437)
Browse files Browse the repository at this point in the history
* fix: Refresh auth token in Purchase Reconciliation Tool (#1319)

Co-authored-by: Smit Vora <smitvora203@gmail.com>

* fix: Reconcile Purchases for Multiple GSTIN (#1367)

* fix: auto refresh auth token

* fix: linters

* fix: Auto Reconcile Purchases (#1562)

* fix: auto reconcile purchases

* fix: comments added

* fix: refactor gst settings ui

* fix: seperate cron jobs to download gstr2a and 2b and auto reconciliation

* fix: make a class for all the methods -AutoReconciliation

* refactor: sequence of functions, minor functional refactor, renames

---------

Co-authored-by: Smit Vora <smitvora203@gmail.com>

* fix: linters, test case

* refactor: no need for auto purchase reco companies

* fix: default settings for auto reco tool

---------
Co-authored-by: Vishakh Desai <vishakhdesai@gmail.com>

(cherry picked from commit e1bb1cc)
  • Loading branch information
vorasmit authored and mergify[bot] committed Mar 18, 2024
1 parent 73e1027 commit 8e06d9c
Show file tree
Hide file tree
Showing 15 changed files with 1,010 additions and 80 deletions.
42 changes: 27 additions & 15 deletions india_compliance/gst_india/api_classes/returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ def autheticate_with_otp(self, otp=None):
endpoint="authenticate",
)

def refresh_auth_token(self, auth_token):
def refresh_auth_token(self):
auth_token = self.get_auth_token()

if not auth_token:
return

return super().post(
json={
"action": "REFRESHTOKEN",
Expand Down Expand Up @@ -151,15 +156,22 @@ def decrypt_response(self, response):
values,
)

# cache of parent doctype GST Settings is not cleared by default so clear it manually
frappe.clear_document_cache("GST Settings")

return response

def encrypt_request(self, json):
if not json:
return

if json.get("app_key"):
json["app_key"] = encrypt_using_public_key(
self.app_key, self.get_public_certificate()
json["app_key"] = (
aes_encrypt_data(self.app_key, self.session_key)
if json.get("action") == "REFRESHTOKEN"
else encrypt_using_public_key(
self.app_key, self.get_public_certificate()
)
)

if json.get("otp"):
Expand All @@ -179,6 +191,18 @@ def get_public_certificate(self):

return certificate.encode()

def get_auth_token(self):
if not self.auth_token:
return None

if not self.session_expiry:
return None

if self.session_expiry <= now_datetime():
return None

return self.auth_token


class ReturnsAPI(ReturnsAuthenticate):
API_NAME = "GST Returns"
Expand Down Expand Up @@ -333,18 +357,6 @@ def generate_app_key(self):

return app_key

def get_auth_token(self):
if not self.auth_token:
return None

if not self.session_expiry:
return None

if self.session_expiry <= now_datetime():
return None

return self.auth_token

def download_files(self, return_period, token, otp=None):
response = self.get(
"FILEDET",
Expand Down
193 changes: 193 additions & 0 deletions india_compliance/gst_india/data/test_purchase_reconciliation_tool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"TEST_CASES": {
"TEST_EXACT_MATCH": [
{
"PURCHASE_INVOICE": {
"bill_no": "BILL-23-00001"
},
"INWARD_SUPPLY": {
"bill_no": "BILL-23-00001"
},
"RECONCILED_DATA": {
"action": "No Action",
"bill_date": "2023-12-11",
"bill_no": "BILL-23-00001",
"classification": "B2B",
"differences": "",
"inward_supply_company_gstin": "24AAQCA8719H1ZC",
"inward_supply_name": "",
"match_status": "Exact Match",
"purchase_company_gstin": "24AAQCA8719H1ZC",
"purchase_doctype": "Purchase Invoice",
"purchase_invoice_name": "",
"supplier_gstin": "24AABCR6898M1ZN",
"supplier_name": "_Test Registered Supplier",
"tax_difference": 0.0,
"taxable_value_difference": 0.0
}
},
{
"BILL_OF_ENTRY": {
"bill_no": "BILL-23-00011"
},
"INWARD_SUPPLY": {
"supplier_name": "_Test Foreign Supplier",
"bill_no": "BILL-23-00011",
"bill_date": "2023-12-11",
"classification": "IMPG",
"doc_type": "Bill of Entry",
"supply_type": "",
"place_of_supply": "24-Gujarat",
"items": [
{
"taxable_value": 10000,
"rate": 18,
"igst": 1800
}
],
"document_value": 11800,
"supplier_gstin": null,
"itc_availability": "Yes",
"return_period_2b": "122023",
"gen_date_2b": "2023-12-11"
},
"RECONCILED_DATA": {
"action": "No Action",
"bill_date": "2023-12-11",
"bill_no": "BILL-23-00011",
"classification": "IMPG",
"differences": "",
"inward_supply_company_gstin": "24AAQCA8719H1ZC",
"inward_supply_name": "",
"match_status": "Exact Match",
"purchase_company_gstin": "24AAQCA8719H1ZC",
"purchase_doctype": "Bill of Entry",
"purchase_invoice_name": "",
"supplier_gstin": "_Test Foreign Supplier",
"supplier_name": "_Test Foreign Supplier",
"tax_difference": 0.0,
"taxable_value_difference": 0.0
}
},
{
"PURCHASE_INVOICE": {
"bill_no": "BILL-23-00010",
"company_gstin": "29AABCR1718E1ZL"
},
"INWARD_SUPPLY": {
"bill_no": "BILL-23-00010",
"company_gstin": "29AABCR1718E1ZL"
},
"RECONCILED_DATA": {
"action": "No Action",
"bill_date": "2023-12-11",
"bill_no": "BILL-23-00010",
"classification": "B2B",
"differences": "",
"inward_supply_company_gstin": "29AABCR1718E1ZL",
"inward_supply_name": "",
"match_status": "Exact Match",
"purchase_company_gstin": "29AABCR1718E1ZL",
"purchase_doctype": "Purchase Invoice",
"purchase_invoice_name": "",
"supplier_gstin": "24AABCR6898M1ZN",
"supplier_name": "_Test Registered Supplier",
"tax_difference": 0.0,
"taxable_value_difference": 0.0
}
}
],
"TEST_DIFFERENT_COMPANY_GSTIN_MISMATCH": [
{
"PURCHASE_INVOICE": {
"bill_no": "BILL-23-00021",
"company_gstin": "24AAQCA8719H1ZC"
},
"INWARD_SUPPLY": {
"bill_no": "BILL-23-00021",
"company_gstin": "29AABCR1718E1ZL"
},
"RECONCILED_DATA": {
"action": "No Action",
"bill_date": "2023-12-11",
"bill_no": "BILL-23-00021",
"classification": "B2B",
"differences": "COMPANY_GSTIN",
"inward_supply_company_gstin": "29AABCR1718E1ZL",
"inward_supply_name": "",
"match_status": "Mismatch",
"purchase_company_gstin": "24AAQCA8719H1ZC",
"purchase_doctype": "Purchase Invoice",
"purchase_invoice_name": "",
"supplier_gstin": "24AABCR6898M1ZN",
"supplier_name": "_Test Registered Supplier",
"tax_difference": 0.0,
"taxable_value_difference": 0.0
}
}
],
"TEST_ROUNDING_DIFFERENCE_SUGGESTED_MATCH": [
{
"PURCHASE_INVOICE": {
"bill_no": "BILL-23-00030"
},
"INWARD_SUPPLY": {
"bill_no": "BILL-23-00030",
"items": [
{
"taxable_value": 10000.50,
"rate": 18,
"sgst": 900.045,
"cgst": 900.045
}
],
"document_value": 11800.09
},
"RECONCILED_DATA": {
"action": "No Action",
"bill_date": "2023-12-11",
"bill_no": "BILL-23-00030",
"classification": "B2B",
"differences": "Rounding Difference, TAXABLE_VALUE, CGST, SGST",
"inward_supply_company_gstin": "24AAQCA8719H1ZC",
"inward_supply_name": "",
"match_status": "Suggested Match",
"purchase_company_gstin": "24AAQCA8719H1ZC",
"purchase_doctype": "Purchase Invoice",
"purchase_invoice_name": "",
"supplier_gstin": "24AABCR6898M1ZN",
"supplier_name": "_Test Registered Supplier",
"tax_difference": -0.09,
"taxable_value_difference": -0.5
}
}
],
"TEST_BILL_NO_SUGGESTED_MATCH": [
{
"PURCHASE_INVOICE": {
"bill_no": "BILL-23-00040"
},
"INWARD_SUPPLY": {
"bill_no": "BILL-23-00045"
},
"RECONCILED_DATA": {
"action": "No Action",
"bill_date": "2023-12-11",
"bill_no": "BILL-23-00040",
"classification": "B2B",
"differences": "",
"inward_supply_company_gstin": "24AAQCA8719H1ZC",
"inward_supply_name": "",
"match_status": "Suggested Match",
"purchase_company_gstin": "24AAQCA8719H1ZC",
"purchase_doctype": "Purchase Invoice",
"purchase_invoice_name": "",
"supplier_gstin": "24AABCR6898M1ZN",
"supplier_name": "_Test Registered Supplier",
"tax_difference": 0.0,
"taxable_value_difference": 0.0
}
}
]
}
}

0 comments on commit 8e06d9c

Please sign in to comment.