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: Fetch e-invoice data for manually generated IRN #2978

Draft
wants to merge 1 commit 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
25 changes: 10 additions & 15 deletions india_compliance/gst_india/client_scripts/e_invoice_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ frappe.ui.form.on("Sales Invoice", {
if (r.message?.error_type == "otp_requested") {
await india_compliance.authenticate_otp(frm.doc.company_gstin);
await frappe.call({
method: "india_compliance.gst_india.utils.e_invoice.handle_duplicate_irn_error",
method: "india_compliance.gst_india.utils.e_invoice.fetch_irn_details_compare_invoice",
args: r.message
});
}
Expand Down Expand Up @@ -212,7 +212,14 @@ function show_mark_e_invoice_as_generated_dialog(frm) {
docname: frm.doc.name,
values,
},
callback: () => {
callback: async (r) => {
if (r.message?.error_type == "otp_requested") {
await india_compliance.authenticate_otp(frm.doc.company_gstin);
await frappe.call({
method: "india_compliance.gst_india.utils.e_invoice.fetch_irn_details_compare_invoice",
args: r.message
});
}
d.hide();
frm.refresh();
},
Expand All @@ -230,19 +237,7 @@ function get_generated_e_invoice_dialog_fields() {
fieldname: "irn",
fieldtype: "Data",
reqd: 1,
},
{
label: "Acknowledgement Number",
fieldname: "ack_no",
fieldtype: "Data",
reqd: 1,
},
{
label: "Acknowledged On",
fieldname: "ack_dt",
fieldtype: "Datetime",
reqd: 1,
},
}
];
return fields;
}
Expand Down
35 changes: 26 additions & 9 deletions india_compliance/gst_india/utils/e_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_datetime,
getdate,
random_string,
rounded,
)

from india_compliance.exceptions import GSPServerError
Expand Down Expand Up @@ -137,7 +138,7 @@ def generate_e_invoice(docname, throw=True, force=False):
current_gstin = data.get("BuyerDtls").get("Gstin")
current_invoice_amount = data.get("ValDtls").get("TotInvVal")

return handle_duplicate_irn_error(
return fetch_irn_details_compare_invoice(
irn_data=result.Desc,
current_gstin=current_gstin,
current_invoice_amount=current_invoice_amount,
Expand Down Expand Up @@ -184,15 +185,16 @@ def generate_e_invoice(docname, throw=True, force=False):


@frappe.whitelist()
def handle_duplicate_irn_error(
def fetch_irn_details_compare_invoice(
irn_data,
current_gstin,
current_invoice_amount,
doc=None,
docname=None,
message=None,
):
"""
Handle Duplicate IRN errors by fetching the IRN details and comparing with the current invoice.
Handle Duplicate IRN errors and Manually Generated by fetching the IRN details and comparing with the current invoice.

Steps:
1. Fetch IRN details using the IRN number using e-Invoice API.
Expand All @@ -206,6 +208,7 @@ def handle_duplicate_irn_error(

doc = doc or load_doc("Sales Invoice", docname, "submit")
api = EInvoiceAPI(doc)
# TODO: test Taxpayer api call and otp and check that Ack dt/No data is coming or not
response = api.get_e_invoice_by_irn(irn_data.Irn)

# Handle error 2283:
Expand Down Expand Up @@ -236,7 +239,12 @@ def handle_duplicate_irn_error(
if response.error_code:
response = irn_data

return log_and_process_e_invoice_generation(doc, response, api.sandbox_mode)
if irn_data.einvoice_status == "Manually Generated":
response.einvoice_status = "Manually Generated"

return log_and_process_e_invoice_generation(
doc, response, api.sandbox_mode, message=message
)


def verify_e_invoice_details(current_gstin, current_invoice_amount, signed_data):
Expand Down Expand Up @@ -389,17 +397,26 @@ def mark_e_invoice_as_generated(doctype, docname, values):
doc = load_doc(doctype, docname, "submit")

values = frappe.parse_json(values)
result = frappe._dict(
irn_data = frappe._dict(
{
"Irn": values.irn,
"AckDt": values.ack_dt,
"AckNo": values.ack_no,
"einvoice_status": "Manually Generated",
}
)

return log_and_process_e_invoice_generation(
doc, result, message="e-Invoice updated successfully"
grand_total_fieldname = (
"base_grand_total"
if doc.get("disable_rounded_total", 1)
else "base_rounded_total"
)
grand_total = abs(rounded(doc.get(grand_total_fieldname), 2))

return fetch_irn_details_compare_invoice(
irn_data,
doc.billing_address_gstin,
grand_total,
doc,
message="e-Invoice updated successfully",
)


Expand Down
Loading