Skip to content

Commit

Permalink
fix: get reason from gst settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Dec 10, 2024
1 parent 1342d1b commit 7610144
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
23 changes: 20 additions & 3 deletions india_compliance/gst_india/client_scripts/e_invoice_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
},
Expand All @@ -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")
Expand Down Expand Up @@ -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);
}

$(`
<div class="alert alert-warning" role="alert">
Sales invoice will be cancelled along with the IRN.
Expand Down Expand Up @@ -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),
Expand All @@ -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) {
Expand Down
22 changes: 20 additions & 2 deletions india_compliance/gst_india/client_scripts/e_waybill_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},
Expand Down Expand Up @@ -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),
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion india_compliance/gst_india/overrides/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down

0 comments on commit 7610144

Please sign in to comment.