diff --git a/india_compliance/gst_india/client_scripts/e_invoice_actions.js b/india_compliance/gst_india/client_scripts/e_invoice_actions.js
index aff1439769..2f915278be 100644
--- a/india_compliance/gst_india/client_scripts/e_invoice_actions.js
+++ b/india_compliance/gst_india/client_scripts/e_invoice_actions.js
@@ -107,7 +107,7 @@ frappe.ui.form.on("Sales Invoice", {
frappe.validated = false;
- return new Promise(resolve => {
+ return new Promise(async (resolve) => {
const continueCancellation = () => {
frappe.validated = true;
resolve();
@@ -144,6 +144,11 @@ frappe.ui.form.on("Sales Invoice", {
return;
}
+ const auto_cancel_e_invoice = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_invoice");
+ if(auto_cancel_e_invoice === 1){
+ continueCancellation()
+ return
+ }
return show_cancel_e_invoice_dialog(frm, continueCancellation);
});
},
@@ -160,7 +165,7 @@ function is_irn_cancellable(frm) {
);
}
-function show_cancel_e_invoice_dialog(frm, callback) {
+async function show_cancel_e_invoice_dialog(frm, callback) {
const d = new frappe.ui.Dialog({
title: frm.doc.ewaybill
? __("Cancel e-Invoice and e-Waybill")
@@ -188,6 +193,12 @@ function show_cancel_e_invoice_dialog(frm, callback) {
india_compliance.primary_to_danger_btn(d);
d.show();
+ const auto_cancel_e_invoice = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_invoice");
+ if (auto_cancel_e_invoice) {
+ const reason = await frappe.db.get_single_value("GST Settings", "reason_for_e_invoice_cancellation");
+ d.get_field("reason").set_value(reason);
+ }
+
$(`
Sales invoice will be cancelled along with the IRN.
@@ -243,7 +254,7 @@ function get_generated_e_invoice_dialog_fields() {
return fields;
}
-function show_mark_e_invoice_as_cancelled_dialog(frm) {
+async function show_mark_e_invoice_as_cancelled_dialog(frm) {
const d = new frappe.ui.Dialog({
title: __("Update Cancelled e-Invoice Details"),
fields: get_cancel_e_invoice_dialog_fields(frm, true),
@@ -265,6 +276,12 @@ function show_mark_e_invoice_as_cancelled_dialog(frm) {
});
d.show();
+
+ const auto_cancel_e_invoice = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_invoice");
+ if (auto_cancel_e_invoice) {
+ const reason = await frappe.db.get_single_value("GST Settings", "reason_for_e_invoice_cancellation");
+ d.get_field("reason").set_value(reason);
+ }
}
function get_cancel_e_invoice_dialog_fields(frm, manual_cancel = false) {
diff --git a/india_compliance/gst_india/client_scripts/e_waybill_actions.js b/india_compliance/gst_india/client_scripts/e_waybill_actions.js
index 09f2754da2..65d2da60ec 100644
--- a/india_compliance/gst_india/client_scripts/e_waybill_actions.js
+++ b/india_compliance/gst_india/client_scripts/e_waybill_actions.js
@@ -221,6 +221,12 @@ function setup_e_waybill_actions(doctype) {
return;
}
+ const auto_cancel_e_waybill = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_waybill");
+ if(auto_cancel_e_waybill === 1){
+ continueCancellation()
+ return
+ }
+
return show_cancel_e_waybill_dialog(frm, continueCancellation);
});
},
@@ -685,7 +691,7 @@ function show_mark_e_waybill_as_generated_dialog(frm) {
d.show();
}
-function show_cancel_e_waybill_dialog(frm, callback) {
+async function show_cancel_e_waybill_dialog(frm, callback) {
const d = new frappe.ui.Dialog({
title: __("Cancel e-Waybill"),
fields: get_cancel_e_waybill_dialog_fields(frm),
@@ -709,9 +715,15 @@ function show_cancel_e_waybill_dialog(frm, callback) {
india_compliance.primary_to_danger_btn(d);
d.show();
+
+ const auto_cancel_e_waybill = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_waybill");
+ if (auto_cancel_e_waybill) {
+ const reason = await frappe.db.get_single_value("GST Settings", "reason_for_e_waybill_cancellation");
+ d.get_field("reason").set_value(reason);
+ }
}
-function show_mark_e_waybill_as_cancelled_dialog(frm) {
+async function show_mark_e_waybill_as_cancelled_dialog(frm) {
const fields = get_cancel_e_waybill_dialog_fields(frm);
fields.push({
label: "Cancelled On",
@@ -742,6 +754,12 @@ function show_mark_e_waybill_as_cancelled_dialog(frm) {
});
d.show();
+
+ const auto_cancel_e_waybill = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_waybill");
+ if (auto_cancel_e_waybill) {
+ const reason = await frappe.db.get_single_value("GST Settings", "reason_for_e_waybill_cancellation");
+ d.get_field("reason").set_value(reason);
+ }
}
function get_cancel_e_waybill_dialog_fields(frm) {
diff --git a/india_compliance/gst_india/doctype/gst_settings/gst_settings.js b/india_compliance/gst_india/doctype/gst_settings/gst_settings.js
index a4c078b848..c632e4fed8 100644
--- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.js
+++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.js
@@ -34,6 +34,7 @@ frappe.ui.form.on("GST Settings", {
auto_generate_e_invoice: set_auto_generate_e_waybill,
generate_e_waybill_with_e_invoice: set_auto_generate_e_waybill,
auto_cancel_e_invoice: auto_cancel_e_invoice,
+ reason_for_e_invoice_cancellation: reason_for_e_invoice_cancellation,
after_save(frm) {
// sets latest values in frappe.boot for current user
// other users will still need to refresh page
@@ -122,4 +123,8 @@ function set_auto_generate_e_waybill(frm) {
function auto_cancel_e_invoice(frm){
frm.set_value("auto_cancel_e_waybill", frm.doc.auto_cancel_e_invoice)
+}
+
+function reason_for_e_invoice_cancellation(frm){
+ frm.set_value("reason_for_e_waybill_cancellation", frm.doc.reason_for_e_invoice_cancellation)
}
\ No newline at end of file
diff --git a/india_compliance/gst_india/overrides/sales_invoice.py b/india_compliance/gst_india/overrides/sales_invoice.py
index 53a6b797ab..1697068b8e 100644
--- a/india_compliance/gst_india/overrides/sales_invoice.py
+++ b/india_compliance/gst_india/overrides/sales_invoice.py
@@ -187,6 +187,7 @@ def on_submit(doc, method=None):
def before_cancel(doc, method=None):
+ cancel_e_documents(doc)
if ignore_gst_validations(doc):
return
@@ -211,7 +212,7 @@ def before_cancel(doc, method=None):
)
-def on_cancel(doc, method=None):
+def cancel_e_documents(doc, method=None):
if (
not frappe.form_dict
or frappe.form_dict.cmd.endswith("cancel_e_invoice")