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

fix: Fixes Related to IMS #2998

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions india_compliance/gst_india/api_classes/taxpayer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ def get(self, *args, **kwargs):
return self._request("get", *args, **kwargs, params=params)

def post(self, *args, **kwargs):
self.default_log_values.update(update_gstr_action=True)
return self._request("post", *args, **kwargs)

def put(self, *args, **kwargs):
self.default_log_values.update(update_gstr_action=True)
return self._request("put", *args, **kwargs)

def before_request(self, request_args):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ class IMS extends reconciliation.reconciliation_tabs {
align: "center",
width: 120,
},
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

along with bill number

label: "Date",
fieldname: "bill_date",
_value: (...args) => frappe.datetime.str_to_user(args[0]),
},
{
label: "Match Status",
fieldname: "match_status",
Expand Down Expand Up @@ -415,6 +420,7 @@ class IMS extends reconciliation.reconciliation_tabs {
data.push({
supplier_name_gstin: this.get_supplier_name_gstin(row),
bill_no: row.bill_no,
bill_date: row.bill_date,
classification: row._inward_supply.classification,
ims_action: row.ims_action || "",
match_status: row.match_status,
Expand All @@ -424,6 +430,7 @@ class IMS extends reconciliation.reconciliation_tabs {
inward_supply_name: row.inward_supply_name,
pending_upload: row.pending_upload,
is_supplier_return_filed: row.is_supplier_return_filed,
linked_voucher_type: row._purchase_invoice.doctype,
});
});

Expand Down Expand Up @@ -530,7 +537,7 @@ class IMS extends reconciliation.reconciliation_tabs {
.join("");

const action_performed_html = `
<div class="action-performed-summary m-3 d-flex justify-content-around align-items-center" style="border-bottom: 1px solid var(--border-color);">
<div class="action-performed-summary mt-3 mb-3 w-100 d-flex justify-content-around align-items-center" style="border-bottom: 1px solid var(--border-color);">
${action_performed_cards}
</div>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,31 +384,29 @@ def process_save_or_reset_ims(return_log, action):

if status_cd in ["P", "PE"]:
# Exclude erroneous invoices from previous IMS action update
# This is enqueued because linking of integration request is enqueued
# This is enqueued because creation of integration request is enqueued
# TODO: flag for re-upload?
frappe.enqueue(
update_previous_ims_action,
queue="long",
integration_request=doc.integration_request,
request_id=doc.request_id,
error_report=response.get("error_report") or dict(),
)

return response


def update_previous_ims_action(integration_request, error_report=None):
uploaded_invoices = get_uploaded_invoices(integration_request)
def update_previous_ims_action(request_id, error_report=None):
uploaded_invoices = get_uploaded_invoices(request_id)

for category, invoices in uploaded_invoices.items():
_class = get_data_handler(ReturnType.IMS.value, category.upper())
_class().update_previous_ims_action(invoices, error_report.get(category, []))


def get_uploaded_invoices(integration_request):
def get_uploaded_invoices(request_id):
request_data = frappe.parse_json(
frappe.db.get_value(
"Integration Request", {"name": integration_request}, "data"
)
frappe.db.get_value("Integration Request", {"request_id": request_id}, "data")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets throw so that we know if this fails

)

if not request_data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"engine": "InnoDB",
"field_order": [
"request_type",
"request_id",
"token",
"status",
"creation_time",
Expand Down Expand Up @@ -44,12 +45,18 @@
"label": "Integration Request",
"options": "Integration Request",
"read_only": 1
},
{
"fieldname": "request_id",
"fieldtype": "Data",
"hidden": 1,
"label": "Request id"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-09-12 12:36:05.679413",
"modified": "2025-01-22 16:33:57.014368",
"modified_by": "Administrator",
"module": "GST India",
"name": "GSTR Action",
Expand Down
20 changes: 1 addition & 19 deletions india_compliance/gst_india/doctype/gstr_action/gstr_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def set_gstr_actions(doc, request_type, token, request_id, status=None):

row = {
"request_type": request_type,
"request_id": request_id,
"token": token,
"creation_time": frappe.utils.now_datetime(),
}
Expand All @@ -24,22 +25,3 @@ def set_gstr_actions(doc, request_type, token, request_id, status=None):

doc.append("actions", row)
doc.save()
enqueue_link_integration_request(token, request_id)


def enqueue_link_integration_request(token, request_id):
"""
Integration request is enqueued. Hence, it's name is not available immediately.
Hence, link it after the request is processed.
"""
frappe.enqueue(
link_integration_request, queue="long", token=token, request_id=request_id
)


def link_integration_request(token, request_id):
doc_name = frappe.db.get_value("Integration Request", {"request_id": request_id})
if doc_name:
frappe.db.set_value(
"GSTR Action", {"token": token}, {"integration_request": doc_name}
)
15 changes: 13 additions & 2 deletions india_compliance/gst_india/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ def create_integration_request(
error=None,
reference_doctype=None,
reference_name=None,
update_gstr_action=False,
):
return frappe.get_doc(
doc = frappe.get_doc(
{
"doctype": "Integration Request",
"integration_request_service": "India Compliance API",
Expand All @@ -32,7 +33,17 @@ def create_integration_request(
"reference_doctype": reference_doctype,
"reference_docname": reference_name,
}
).insert(ignore_permissions=True)
)
doc.insert(ignore_permissions=True)

if update_gstr_action:
link_integration_request(request_id, doc.name)


def link_integration_request(request_id, doc_name):
frappe.db.set_value(
"GSTR Action", {"request_id": request_id}, {"integration_request": doc_name}
)


def pretty_json(obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ india_compliance.DataTableManager = class DataTableManager {

value = frappe.format(value, column, { always_show_decimals: true }, data);

if (column.post_format) {
if (column._after_format) {
value = column._after_format(value, column, data);
}

Expand Down
Loading