Add virtual docfield through which you can make callable properties for the controllerversion-14
@@ -17,6 +17,7 @@ | |||||
"hide_days", | "hide_days", | ||||
"hide_seconds", | "hide_seconds", | ||||
"reqd", | "reqd", | ||||
"is_virtual", | |||||
"search_index", | "search_index", | ||||
"column_break_18", | "column_break_18", | ||||
"options", | "options", | ||||
@@ -534,13 +535,19 @@ | |||||
"fieldname": "show_dashboard", | "fieldname": "show_dashboard", | ||||
"fieldtype": "Check", | "fieldtype": "Check", | ||||
"label": "Show Dashboard" | "label": "Show Dashboard" | ||||
}, | |||||
{ | |||||
"default": "0", | |||||
"fieldname": "is_virtual", | |||||
"fieldtype": "Check", | |||||
"label": "Virtual" | |||||
} | } | ||||
], | ], | ||||
"idx": 1, | "idx": 1, | ||||
"index_web_pages_for_search": 1, | "index_web_pages_for_search": 1, | ||||
"istable": 1, | "istable": 1, | ||||
"links": [], | "links": [], | ||||
"modified": "2022-01-03 11:56:19.812863", | |||||
"modified": "2022-01-27 21:22:20.529072", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Core", | "module": "Core", | ||||
"name": "DocField", | "name": "DocField", | ||||
@@ -558,7 +558,8 @@ docfield_properties = { | |||||
'allow_in_quick_entry': 'Check', | 'allow_in_quick_entry': 'Check', | ||||
'hide_border': 'Check', | 'hide_border': 'Check', | ||||
'hide_days': 'Check', | 'hide_days': 'Check', | ||||
'hide_seconds': 'Check' | |||||
'hide_seconds': 'Check', | |||||
'is_virtual': 'Check', | |||||
} | } | ||||
doctype_link_properties = { | doctype_link_properties = { | ||||
@@ -14,6 +14,7 @@ | |||||
"non_negative", | "non_negative", | ||||
"reqd", | "reqd", | ||||
"unique", | "unique", | ||||
"is_virtual", | |||||
"in_list_view", | "in_list_view", | ||||
"in_standard_filter", | "in_standard_filter", | ||||
"in_global_search", | "in_global_search", | ||||
@@ -115,6 +116,12 @@ | |||||
"fieldtype": "Check", | "fieldtype": "Check", | ||||
"label": "Unique" | "label": "Unique" | ||||
}, | }, | ||||
{ | |||||
"default": "0", | |||||
"fieldname": "is_virtual", | |||||
"fieldtype": "Check", | |||||
"label": "Is Virtual" | |||||
}, | |||||
{ | { | ||||
"default": "0", | "default": "0", | ||||
"fieldname": "in_list_view", | "fieldname": "in_list_view", | ||||
@@ -436,7 +443,7 @@ | |||||
"index_web_pages_for_search": 1, | "index_web_pages_for_search": 1, | ||||
"istable": 1, | "istable": 1, | ||||
"links": [], | "links": [], | ||||
"modified": "2022-01-03 14:50:32.035768", | |||||
"modified": "2022-01-27 21:45:22.349776", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Custom", | "module": "Custom", | ||||
"name": "Customize Form Field", | "name": "Customize Form Field", | ||||
@@ -244,7 +244,13 @@ class BaseDocument(object): | |||||
continue | continue | ||||
df = self.meta.get_field(fieldname) | df = self.meta.get_field(fieldname) | ||||
if df: | |||||
if df and df.get("is_virtual"): | |||||
if d[fieldname] is None: | |||||
_val = getattr(self, fieldname, None) | |||||
if _val and not callable(_val): | |||||
d[fieldname] = _val | |||||
elif df: | |||||
if df.fieldtype=="Check": | if df.fieldtype=="Check": | ||||
d[fieldname] = 1 if cint(d[fieldname]) else 0 | d[fieldname] = 1 if cint(d[fieldname]) else 0 | ||||
@@ -264,11 +270,6 @@ class BaseDocument(object): | |||||
if isinstance(d[fieldname], list) and df.fieldtype not in table_fields: | if isinstance(d[fieldname], list) and df.fieldtype not in table_fields: | ||||
frappe.throw(_('Value for {0} cannot be a list').format(_(df.label))) | frappe.throw(_('Value for {0} cannot be a list').format(_(df.label))) | ||||
if d[fieldname] is None: | |||||
_val = getattr(self, fieldname, None) | |||||
if _val and not callable(_val): | |||||
d[fieldname] = _val | |||||
if convert_dates_to_str and isinstance(d[fieldname], ( | if convert_dates_to_str and isinstance(d[fieldname], ( | ||||
datetime.datetime, | datetime.datetime, | ||||
datetime.date, | datetime.date, | ||||