fix: remove custom fields as well on reset to default

This commit is contained in:
shadrak gurupnor 2022-02-28 13:52:15 +05:30
parent 91b220c37c
commit d76eca36fe
2 changed files with 14 additions and 5 deletions

View file

@ -134,7 +134,7 @@ frappe.ui.form.on("Customize Form", {
);
frm.add_custom_button(
__("Reset Property Setters"),
__("Reset to defaults"),
function() {
frappe.customize_form.confirm(
__("Remove all customizations?"),
@ -315,9 +315,9 @@ frappe.customize_form.confirm = function(msg, frm) {
if (!frm.doc.doc_type) return;
var d = new frappe.ui.Dialog({
title: 'Reset Property Setters',
title: 'Reset To Defaults',
fields: [
{fieldtype:"HTML", options:__("All property setters will be removed. Please confirm.")},
{fieldtype:"HTML", options:__("All customizations will be removed. Please confirm.")},
],
primary_action: function() {
return frm.call({
@ -328,7 +328,7 @@ frappe.customize_form.confirm = function(msg, frm) {
frappe.msgprint(r.exc);
} else {
d.hide();
frappe.show_alert({message:__('Property Setters Reset'), indicator:'green'});
frappe.show_alert({message:__('Customizations Reset'), indicator:'green'});
frappe.customize_form.clear_locals_and_refresh(frm);
}
}

View file

@ -487,12 +487,21 @@ def reset_customization(doctype):
setters = frappe.get_all("Property Setter", filters={
'doc_type': doctype,
'field_name': ['!=', 'naming_series'],
'property': ['!=', 'options']
'property': ['!=', 'options'],
'owner': ['!=', 'Administrator']
}, pluck='name')
for setter in setters:
frappe.delete_doc("Property Setter", setter)
custom_fields = frappe.get_all("Custom Field", filters={
'dt': doctype,
'owner': ['!=', 'Administrator']
}, pluck='name')
for field in custom_fields:
frappe.delete_doc("Custom Field", field)
frappe.clear_cache(doctype=doctype)
doctype_properties = {