Skip to content

Commit

Permalink
fix: always keep default rows set in default_list_data
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Nov 28, 2023
1 parent 72a7770 commit f05c352
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crm/fcrm/doctype/crm_list_view_settings/crm_list_view_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For license information, please see license.txt
import json
import frappe
from frappe.model.document import Document
from frappe.model.document import Document, get_controller


class CRMListViewSettings(Document):
Expand All @@ -11,19 +11,35 @@ class CRMListViewSettings(Document):

@frappe.whitelist()
def update(doctype, columns, rows):
default_rows = sync_default_list_rows(doctype)

if default_rows:
rows = rows + default_rows

rows = remove_duplicates(rows)

if not frappe.db.exists("CRM List View Settings", doctype):
# create new CRM List View Settings
doc = frappe.new_doc("CRM List View Settings")
doc.name = doctype
doc.columns = json.dumps(columns)
doc.rows = json.dumps(remove_duplicates(rows))
doc.rows = json.dumps(rows)
doc.insert()
else:
# update existing CRM List View Settings
doc = frappe.get_doc("CRM List View Settings", doctype)
doc.columns = json.dumps(columns)
doc.rows = json.dumps(remove_duplicates(rows))
doc.rows = json.dumps(rows)
doc.save()

def remove_duplicates(l):
return list(dict.fromkeys(l))
return list(dict.fromkeys(l))

def sync_default_list_rows(doctype):
list = get_controller(doctype)
rows = []

if hasattr(list, "default_list_data"):
rows = list.default_list_data().get("rows")

return rows

0 comments on commit f05c352

Please sign in to comment.