From bbb45e004b915767c114eced997bf54b87574098 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Thu, 14 Aug 2025 16:07:29 +0400 Subject: [PATCH] added anti-delete to standart groups --- taxes_az/hooks.py | 8 +++++++- taxes_az/item_group.py | 6 ++++++ taxes_az/public/js/item_group.js | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 taxes_az/item_group.py create mode 100644 taxes_az/public/js/item_group.js diff --git a/taxes_az/hooks.py b/taxes_az/hooks.py index 5f07704..ac5b17d 100644 --- a/taxes_az/hooks.py +++ b/taxes_az/hooks.py @@ -42,9 +42,15 @@ doctype_js = { "public/js/xml_mapping/mapping_storage.js", "public/js/xml_mapping/xml_generator.js" ], - "Company": "client/company.js" + "Company": "client/company.js", + "Item Group": "public/js/item_group.js" } +doc_events = { + "Item Group": { + "on_trash": "taxes_az.item_group.validate_item_group_deletion" + } +} # Includes in # ------------------ diff --git a/taxes_az/item_group.py b/taxes_az/item_group.py new file mode 100644 index 0000000..7aef6ab --- /dev/null +++ b/taxes_az/item_group.py @@ -0,0 +1,6 @@ +import frappe +from frappe import _ + +def validate_item_group_deletion(doc, method): + if doc.is_standard: + frappe.throw(_("Cannot delete standard Item Group")) \ No newline at end of file diff --git a/taxes_az/public/js/item_group.js b/taxes_az/public/js/item_group.js new file mode 100644 index 0000000..15c9ea1 --- /dev/null +++ b/taxes_az/public/js/item_group.js @@ -0,0 +1,25 @@ +frappe.ui.form.on('Item Group', { + refresh: function(frm) { + if (frm.doc.is_standard) { + frm.set_intro(__("This is a root item group and cannot be edited."), true); + frm.disable_form(); + } + }, + + onload: function(frm) { + if (frm.doc.is_standard) { + frm.set_intro(__("This is a root item group and cannot be edited."), true); + frm.disable_form(); + } + }, + + is_standard: function(frm) { + if (frm.doc.is_standard) { + frm.set_intro(__("This is a root item group and cannot be edited."), true); + frm.disable_form(); + } else { + frm.set_intro(''); + frm.enable_form(); + } + } +}); \ No newline at end of file