Skip to content

Commit

Permalink
fix: no neeed to schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed Nov 5, 2024
1 parent 89970b7 commit e13075e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 54 deletions.
44 changes: 8 additions & 36 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,29 @@ frappe.ui.form.on("GST Settings", {
generate_e_waybill_with_e_invoice: set_auto_generate_e_waybill,
before_save: async function (frm) {
const { message } = await frm.call("check_gst_account_changes");
frm.has_gst_account_changed = message
if (message) {
show_gst_account_alert(frm);
}
},
after_save(frm) {
// sets latest values in frappe.boot for current user
// other users will still need to refresh page
Object.assign(gst_settings, frm.doc);
show_gst_account_alert(frm);
},
});

function show_gst_account_alert(frm) {
if (!frm.has_gst_account_changed) return;
//alert already exists
if (frm.layout.wrapper.find(".gst-account-changed-alert").length !== 0) return;

const alert_element = $(ALERT_HTML).prependTo(frm.layout.wrapper);

alert_element
.find("#run-patch-button")
.on("click", () => open_patch_schedule_dialog(alert_element));
}

function open_patch_schedule_dialog(alert_element) {
const dialog = new frappe.ui.Dialog({
title: __("Schedule Patch Execution Time"),
fields: [
{
label: "Execution Time",
fieldname: "execution_time",
fieldtype: "Datetime",
default: `${frappe.datetime.add_days(
frappe.datetime.now_date(),
1
)} 02:00:00`,
},
],
primary_action_label: __("Schedule"),
primary_action(values) {
if (values.execution_time < frappe.datetime.now_datetime()) {
frappe.msgprint(__("Patch run time cannot be in the past"));
return;
}
dialog.hide();
frappe.call({
method: "india_compliance.gst_india.doctype.gst_settings.gst_settings.schedule_gst_patches",
args: { cron_time: values.execution_time },
});
alert_element.remove();
},
alert_element.find("#run-patch-button").on("click", () => {
frappe.call({
method: "india_compliance.gst_india.doctype.gst_settings.gst_settings.apply_gst_patches",
});
alert_element.remove();
});
dialog.show();
}

function filter_accounts(frm, account_field) {
Expand Down
24 changes: 6 additions & 18 deletions india_compliance/gst_india/doctype/gst_settings/gst_settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from datetime import datetime

import frappe
from frappe import _
from frappe.model.document import Document
Expand Down Expand Up @@ -376,23 +374,13 @@ def has_row_changed(self, old_gst_account, new_gst_account):


@frappe.whitelist()
def schedule_gst_patches(cron_time):
dt = datetime.strptime(cron_time, "%Y-%m-%d %H:%M:%S")
cron_format = f"{dt.minute} {dt.hour} {dt.day} {dt.month} {dt.weekday() + 1}"

doc = frappe.get_doc(
{
"doctype": "Scheduled Job Type",
"method": "india_compliance.gst_india.doctype.gst_settings.gst_settings.apply_gst_patches",
"cron_format": cron_format,
"frequency": "Cron",
"create_log": 1,
}
)
doc.insert()


def apply_gst_patches():
if (
not frappe.has_permission("GST Settings", "write")
and "System Manager" not in frappe.get_roles()
):
frappe.throw(_("You do not have enough permissions for this"))

from india_compliance.patches.post_install.improve_item_tax_template import (
execute as execute_improve_item_tax_template,
)
Expand Down

0 comments on commit e13075e

Please sign in to comment.