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 519d575
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
16 changes: 14 additions & 2 deletions india_compliance/gst_india/client_scripts/e_invoice_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ function is_irn_cancellable(frm) {
);
}

function show_cancel_e_invoice_dialog(frm, callback) {
async function show_cancel_e_invoice_dialog(frm, callback) {
const auto_cancel_e_invoice = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_invoice")
if(auto_cancel_e_invoice === 1) {
callback && callback();
return
}

const d = new frappe.ui.Dialog({
title: frm.doc.ewaybill
? __("Cancel e-Invoice and e-Waybill")
Expand Down Expand Up @@ -243,7 +249,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 +271,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
16 changes: 14 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 @@ -685,7 +685,13 @@ 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 auto_cancel_e_waybill = await frappe.db.get_single_value("GST Settings", "auto_cancel_e_waybill");
if(auto_cancel_e_waybill === 1){
callback && callback();
return
}

const d = new frappe.ui.Dialog({
title: __("Cancel e-Waybill"),
fields: get_cancel_e_waybill_dialog_fields(frm),
Expand All @@ -711,7 +717,7 @@ function show_cancel_e_waybill_dialog(frm, callback) {
d.show();
}

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 +748,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 519d575

Please sign in to comment.