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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
24 changes: 15 additions & 9 deletions india_compliance/gst_india/client_scripts/e_invoice_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,17 @@ function show_mark_e_invoice_as_generated_dialog(frm) {
title: __("Update e-Invoice Details"),
fields: get_generated_e_invoice_dialog_fields(),
primary_action_label: __("Update"),
primary_action(values) {
frappe.call({
async primary_action(values) {
await taxpayer_api.call({
method: "india_compliance.gst_india.utils.e_invoice.mark_e_invoice_as_generated",
args: {
doctype: frm.doctype,
docname: frm.doc.name,
values,
},
callback: () => {
d.hide();
frm.refresh();
},
}
});
d.hide();
frm.refresh();
},
});

Expand All @@ -231,17 +229,25 @@ function get_generated_e_invoice_dialog_fields() {
fieldtype: "Data",
reqd: 1,
},
{
label: "Fetch Invoice Details",
fieldname: "fetch_invoice_details",
fieldtype: "Check",
default: 1,
},
{
label: "Acknowledgement Number",
fieldname: "ack_no",
fieldtype: "Data",
reqd: 1,
mandatory_depends_on: "eval: !doc.fetch_invoice_details",
depends_on: "eval: !doc.fetch_invoice_details",
},
{
label: "Acknowledged On",
fieldname: "ack_dt",
fieldtype: "Datetime",
reqd: 1,
mandatory_depends_on: "eval: !doc.fetch_invoice_details",
depends_on: "eval: !doc.fetch_invoice_details",
},
];
return fields;
Expand Down
26 changes: 22 additions & 4 deletions india_compliance/gst_india/doctype/e_invoice_log/e_invoice_log.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
// Copyright (c) 2022, Resilient Tech and contributors
// For license information, please see license.txt

// frappe.ui.form.on('e-Invoice Log', {
// refresh: function(frm) {
frappe.ui.form.on('e-Invoice Log', {
refresh: function (frm) { },

// }
// });
fetch_e_invoice_details: function (frm) {
if (frm.doc.fetch_e_invoice_details) {
frm.add_custom_button(__('Fetch E-Invoice Details'), function () {
frappe.call({
method: "india_compliance.gst_india.utils.e_invoice.fetch_e_invoice_details",
args: {
"irn": frm.doc.irn,
"docname": frm.doc.reference_name,
},
callback: function () {
frm.reload_doc();
}
});
})
}
else {
frm.remove_custom_button(__('Fetch E-Invoice Details'));
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"column_break_1",
"acknowledgement_number",
"acknowledged_on",
"fetch_e_invoice_details",
"signed_data_section",
"invoice_data",
"signed_invoice",
Expand Down Expand Up @@ -131,6 +132,13 @@
"label": "Reference Document Name",
"options": "reference_doctype",
"read_only": 1
},
{
"default": "0",
"depends_on": "eval: !doc.invoice_data",
"fieldname": "fetch_e_invoice_details",
"fieldtype": "Check",
"label": "Fetch E-Invoice Details"
}
],
"in_create": 1,
Expand All @@ -140,7 +148,7 @@
"link_fieldname": "irn"
}
],
"modified": "2024-09-19 18:59:01.195753",
"modified": "2025-02-21 12:58:02.214762",
"modified_by": "Administrator",
"module": "GST India",
"name": "e-Invoice Log",
Expand Down
26 changes: 26 additions & 0 deletions india_compliance/gst_india/utils/e_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

from india_compliance.exceptions import GSPServerError
from india_compliance.gst_india.api_classes.e_invoice import EInvoiceAPI
from india_compliance.gst_india.api_classes.taxpayer_base import (
otp_handler,
)
from india_compliance.gst_india.api_classes.taxpayer_e_invoice import (
EInvoiceAPI as TaxpayerEInvoiceAPI,
)
Expand Down Expand Up @@ -385,10 +388,14 @@ def log_and_process_e_invoice_cancellation(doc, values, result, message):


@frappe.whitelist()
@otp_handler
def mark_e_invoice_as_generated(doctype, docname, values):
doc = load_doc(doctype, docname, "submit")

values = frappe.parse_json(values)
if values.fetch_invoice_details:
return fetch_e_invoice_details(values.irn, doc=doc)

result = frappe._dict(
{
"Irn": values.irn,
Expand All @@ -397,6 +404,25 @@ def mark_e_invoice_as_generated(doctype, docname, values):
"einvoice_status": "Manually Generated",
}
)
return log_and_process_e_invoice_generation(
doc, result, message="e-Invoice updated successfully"
)


@frappe.whitelist()
@otp_handler
def fetch_e_invoice_details(irn, docname=None, doc=None):
if not doc:
doc = load_doc("Sales Invoice", docname, "submit")

api = EInvoiceAPI(doc)
result = api.get_e_invoice_by_irn(irn)

if result.error_code == "2148":
frappe.throw(_("Requested IRN data is not available"))

if result.error_code == "2283":
result = TaxpayerEInvoiceAPI(doc).get_irn_details(irn)

return log_and_process_e_invoice_generation(
doc, result, message="e-Invoice updated successfully"
Expand Down