Merge pull request #410 from shariquerik/reset-defaults
fix: Restore defaults
This commit is contained in:
commit
8aff67d695
0
crm/fcrm/doctype/fcrm_settings/__init__.py
Normal file
0
crm/fcrm/doctype/fcrm_settings/__init__.py
Normal file
42
crm/fcrm/doctype/fcrm_settings/fcrm_settings.js
Normal file
42
crm/fcrm/doctype/fcrm_settings/fcrm_settings.js
Normal file
@ -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);
|
||||
},
|
||||
});
|
||||
40
crm/fcrm/doctype/fcrm_settings/fcrm_settings.json
Normal file
40
crm/fcrm/doctype/fcrm_settings/fcrm_settings.json
Normal file
@ -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": []
|
||||
}
|
||||
12
crm/fcrm/doctype/fcrm_settings/fcrm_settings.py
Normal file
12
crm/fcrm/doctype/fcrm_settings/fcrm_settings.py
Normal file
@ -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)
|
||||
9
crm/fcrm/doctype/fcrm_settings/test_fcrm_settings.py
Normal file
9
crm/fcrm/doctype/fcrm_settings/test_fcrm_settings.py
Normal file
@ -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
|
||||
@ -9,11 +9,11 @@ from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
def before_install():
|
||||
pass
|
||||
|
||||
def after_install():
|
||||
def after_install(force=False):
|
||||
add_default_lead_statuses()
|
||||
add_default_deal_statuses()
|
||||
add_default_communication_statuses()
|
||||
add_default_fields_layout()
|
||||
add_default_fields_layout(force)
|
||||
add_property_setter()
|
||||
add_email_template_custom_fields()
|
||||
add_default_industries()
|
||||
@ -111,7 +111,7 @@ def add_default_communication_statuses():
|
||||
doc.status = status
|
||||
doc.insert()
|
||||
|
||||
def add_default_fields_layout():
|
||||
def add_default_fields_layout(force=False):
|
||||
quick_entry_layouts = {
|
||||
"CRM Lead-Quick Entry": {
|
||||
"doctype": "CRM Lead",
|
||||
@ -148,7 +148,10 @@ def add_default_fields_layout():
|
||||
|
||||
for layout in quick_entry_layouts:
|
||||
if frappe.db.exists("CRM Fields Layout", layout):
|
||||
continue
|
||||
if force:
|
||||
frappe.delete_doc("CRM Fields Layout", layout)
|
||||
else:
|
||||
continue
|
||||
|
||||
doc = frappe.new_doc("CRM Fields Layout")
|
||||
doc.type = "Quick Entry"
|
||||
@ -158,7 +161,10 @@ def add_default_fields_layout():
|
||||
|
||||
for layout in sidebar_fields_layouts:
|
||||
if frappe.db.exists("CRM Fields Layout", layout):
|
||||
continue
|
||||
if force:
|
||||
frappe.delete_doc("CRM Fields Layout", layout)
|
||||
else:
|
||||
continue
|
||||
|
||||
doc = frappe.new_doc("CRM Fields Layout")
|
||||
doc.type = "Side Panel"
|
||||
@ -217,7 +223,6 @@ def add_default_industries():
|
||||
|
||||
|
||||
def add_default_lead_sources():
|
||||
|
||||
lead_sources = ["Existing Customer", "Reference", "Advertisement", "Cold Calling", "Exhibition", "Supplier Reference", "Mass Mailing", "Customer's Vendor", "Campaign", "Walk In"]
|
||||
|
||||
for source in lead_sources:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user