fix: create or update quick filter global settings
This commit is contained in:
parent
6fa5133665
commit
5280a478e7
@ -220,6 +220,9 @@ def update_quick_filters(quick_filters: str, old_filters: str, doctype: str):
|
||||
new_filters = [filter for filter in quick_filters if filter not in old_filters]
|
||||
removed_filters = [filter for filter in old_filters if filter not in quick_filters]
|
||||
|
||||
# update or create global quick filter settings
|
||||
create_update_global_settings(doctype, quick_filters)
|
||||
|
||||
# remove old filters
|
||||
for filter in removed_filters:
|
||||
update_in_standard_filter(filter, doctype, 0)
|
||||
@ -229,6 +232,18 @@ def update_quick_filters(quick_filters: str, old_filters: str, doctype: str):
|
||||
update_in_standard_filter(filter, doctype, 1)
|
||||
|
||||
|
||||
def create_update_global_settings(doctype, quick_filters):
|
||||
if global_settings := frappe.db.exists("CRM Global Settings", {"dt": doctype, "type": "Quick Filters"}):
|
||||
frappe.db.set_value("CRM Global Settings", global_settings, "json", json.dumps(quick_filters))
|
||||
else:
|
||||
# create CRM Global Settings doc
|
||||
doc = frappe.new_doc("CRM Global Settings")
|
||||
doc.dt = doctype
|
||||
doc.type = "Quick Filters"
|
||||
doc.json = json.dumps(quick_filters)
|
||||
doc.insert()
|
||||
|
||||
|
||||
def update_in_standard_filter(fieldname, doctype, value):
|
||||
if property_name := frappe.db.exists(
|
||||
"Property Setter",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user