From 51db776930446e83dff34ad9c7b861894a5cd8a9 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sat, 12 Oct 2024 14:02:00 +0530 Subject: [PATCH] fix: created crm settings and added restore defaults button --- crm/fcrm/doctype/fcrm_settings/__init__.py | 0 .../doctype/fcrm_settings/fcrm_settings.js | 42 +++++++++++++++++++ .../doctype/fcrm_settings/fcrm_settings.json | 40 ++++++++++++++++++ .../doctype/fcrm_settings/fcrm_settings.py | 12 ++++++ .../fcrm_settings/test_fcrm_settings.py | 9 ++++ 5 files changed, 103 insertions(+) create mode 100644 crm/fcrm/doctype/fcrm_settings/__init__.py create mode 100644 crm/fcrm/doctype/fcrm_settings/fcrm_settings.js create mode 100644 crm/fcrm/doctype/fcrm_settings/fcrm_settings.json create mode 100644 crm/fcrm/doctype/fcrm_settings/fcrm_settings.py create mode 100644 crm/fcrm/doctype/fcrm_settings/test_fcrm_settings.py diff --git a/crm/fcrm/doctype/fcrm_settings/__init__.py b/crm/fcrm/doctype/fcrm_settings/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/crm/fcrm/doctype/fcrm_settings/fcrm_settings.js b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.js new file mode 100644 index 000000000..4264130fc --- /dev/null +++ b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.js @@ -0,0 +1,42 @@ +// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on("FCRM Settings", { + // refresh(frm) { + + // }, + restore_defaults: function (frm) { + let message = __( + "This will restore (if not exist) all the default statuses, custom fields and layouts. Delete & Restore will delete default layouts and then restore them." + ); + let d = new frappe.ui.Dialog({ + title: __("Restore Defaults"), + primary_action_label: __("Restore"), + primary_action: () => { + frm.call("restore_defaults", { force: false }, () => { + frappe.show_alert({ + message: __( + "Default statuses, custom fields and layouts restored successfully." + ), + indicator: "green", + }); + }); + d.hide(); + }, + secondary_action_label: __("Delete & Restore"), + secondary_action: () => { + frm.call("restore_defaults", { force: true }, () => { + frappe.show_alert({ + message: __( + "Default statuses, custom fields and layouts restored successfully." + ), + indicator: "green", + }); + }); + d.hide(); + }, + }); + d.show(); + d.set_message(message); + }, +}); diff --git a/crm/fcrm/doctype/fcrm_settings/fcrm_settings.json b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.json new file mode 100644 index 000000000..c76784ae4 --- /dev/null +++ b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.json @@ -0,0 +1,40 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2024-09-29 13:48:02.715924", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "restore_defaults" + ], + "fields": [ + { + "fieldname": "restore_defaults", + "fieldtype": "Button", + "label": "Restore Defaults" + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2024-09-29 13:49:07.835379", + "modified_by": "Administrator", + "module": "FCRM", + "name": "FCRM Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "creation", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py new file mode 100644 index 000000000..65e6d6f31 --- /dev/null +++ b/crm/fcrm/doctype/fcrm_settings/fcrm_settings.py @@ -0,0 +1,12 @@ +# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import frappe +from frappe.model.document import Document +from crm.install import after_install + + +class FCRMSettings(Document): + @frappe.whitelist() + def restore_defaults(self, force=False): + after_install(force) diff --git a/crm/fcrm/doctype/fcrm_settings/test_fcrm_settings.py b/crm/fcrm/doctype/fcrm_settings/test_fcrm_settings.py new file mode 100644 index 000000000..8e626f3e5 --- /dev/null +++ b/crm/fcrm/doctype/fcrm_settings/test_fcrm_settings.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +# import frappe +from frappe.tests import UnitTestCase + + +class TestFCRMSettings(UnitTestCase): + pass