瀏覽代碼

feat: Virtual DocField

Add virtual docfield through which you can make callable properties for
the controller
version-14
Gavin D'souza 3 年之前
父節點
當前提交
9e3e3f804a
共有 4 個檔案被更改,包括 25 行新增9 行删除
  1. +8
    -1
      frappe/core/doctype/docfield/docfield.json
  2. +2
    -1
      frappe/custom/doctype/customize_form/customize_form.py
  3. +8
    -1
      frappe/custom/doctype/customize_form_field/customize_form_field.json
  4. +7
    -6
      frappe/model/base_document.py

+ 8
- 1
frappe/core/doctype/docfield/docfield.json 查看文件

@@ -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",


+ 2
- 1
frappe/custom/doctype/customize_form/customize_form.py 查看文件

@@ -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 = {


+ 8
- 1
frappe/custom/doctype/customize_form_field/customize_form_field.json 查看文件

@@ -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",


+ 7
- 6
frappe/model/base_document.py 查看文件

@@ -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,


Loading…
取消
儲存