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 39abd9cae..155a70cfa 100644 --- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.js +++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.js @@ -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) { diff --git a/india_compliance/gst_india/doctype/gst_settings/gst_settings.py b/india_compliance/gst_india/doctype/gst_settings/gst_settings.py index 17eba78e8..a219b45a1 100644 --- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.py +++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.py @@ -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 @@ -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, )