From e98519211e7a2de57dca8e72148daf9155ff57ea Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 8 Jun 2023 18:07:12 +0530 Subject: [PATCH] feat: let people reset layout back to original (#21290) --- .../doctype/customize_form/customize_form.js | 30 +++++++++++++++++++ .../doctype/customize_form/customize_form.py | 20 ++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js index aefa0e9a7e..3937079365 100644 --- a/frappe/custom/doctype/customize_form/customize_form.js +++ b/frappe/custom/doctype/customize_form/customize_form.js @@ -126,6 +126,14 @@ frappe.ui.form.on("Customize Form", { __("Actions") ); + frm.add_custom_button( + __("Reset Layout"), + () => { + frm.trigger("reset_layout"); + }, + __("Actions") + ); + frm.add_custom_button( __("Set Permissions"), function () { @@ -164,6 +172,28 @@ frappe.ui.form.on("Customize Form", { } }, + reset_layout(frm) { + frappe.confirm( + __("Layout will be reset to standard layout, are you sure you want to do this?"), + null, + () => { + return frm.call({ + doc: frm.doc, + method: "reset_to_defaults", + callback: function (r) { + if (!r.exc) { + frappe.show_alert({ + message: __("Layout Reset"), + indicator: "green", + }); + frappe.customize_form.clear_locals_and_refresh(frm); + } + }, + }); + } + ); + }, + setup_export(frm) { if (frappe.boot.developer_mode) { frm.add_custom_button( diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 24a9559f97..f403079cd8 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -35,7 +35,7 @@ class CustomizeForm(Document): if not self.doc_type: return - meta = frappe.get_meta(self.doc_type) + meta = frappe.get_meta(self.doc_type, cached=False) self.validate_doctype(meta) @@ -568,6 +568,24 @@ class CustomizeForm(Document): reset_customization(self.doc_type) self.fetch_to_customize() + @frappe.whitelist() + def reset_layout(self): + if not self.doc_type: + return + + property_setter = frappe.db.get_value( + "Property Setter", + filters={ + "doc_type": self.doc_type, + "property": "field_order", + "is_system_generated": False, + }, + ) + if property_setter: + frappe.delete_doc("Property Setter", property_setter) + + self.fetch_to_customize() + @classmethod def allow_fieldtype_change(self, old_type: str, new_type: str) -> bool: """allow type change, if both old_type and new_type are in same field group.