fix: always keep default rows set in default_list_data
This commit is contained in:
parent
72a7770d31
commit
f05c352461
@ -2,7 +2,7 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
import json
|
import json
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document, get_controller
|
||||||
|
|
||||||
|
|
||||||
class CRMListViewSettings(Document):
|
class CRMListViewSettings(Document):
|
||||||
@ -11,19 +11,35 @@ class CRMListViewSettings(Document):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def update(doctype, columns, rows):
|
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):
|
if not frappe.db.exists("CRM List View Settings", doctype):
|
||||||
# create new CRM List View Settings
|
# create new CRM List View Settings
|
||||||
doc = frappe.new_doc("CRM List View Settings")
|
doc = frappe.new_doc("CRM List View Settings")
|
||||||
doc.name = doctype
|
doc.name = doctype
|
||||||
doc.columns = json.dumps(columns)
|
doc.columns = json.dumps(columns)
|
||||||
doc.rows = json.dumps(remove_duplicates(rows))
|
doc.rows = json.dumps(rows)
|
||||||
doc.insert()
|
doc.insert()
|
||||||
else:
|
else:
|
||||||
# update existing CRM List View Settings
|
# update existing CRM List View Settings
|
||||||
doc = frappe.get_doc("CRM List View Settings", doctype)
|
doc = frappe.get_doc("CRM List View Settings", doctype)
|
||||||
doc.columns = json.dumps(columns)
|
doc.columns = json.dumps(columns)
|
||||||
doc.rows = json.dumps(remove_duplicates(rows))
|
doc.rows = json.dumps(rows)
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
def remove_duplicates(l):
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user