Pārlūkot izejas kodu

feat: Virtual DocField

Add virtual docfield through which you can make callable properties for
the controller
version-14
Gavin D'souza pirms 3 gadiem
vecāks
revīzija
9e3e3f804a
4 mainītis faili ar 25 papildinājumiem un 9 dzēšanām
  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 Parādīt failu

@@ -17,6 +17,7 @@
"hide_days",
"hide_seconds",
"reqd",
"is_virtual",
"search_index",
"column_break_18",
"options",
@@ -534,13 +535,19 @@
"fieldname": "show_dashboard",
"fieldtype": "Check",
"label": "Show Dashboard"
},
{
"default": "0",
"fieldname": "is_virtual",
"fieldtype": "Check",
"label": "Virtual"
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-01-03 11:56:19.812863",
"modified": "2022-01-27 21:22:20.529072",
"modified_by": "Administrator",
"module": "Core",
"name": "DocField",


+ 2
- 1
frappe/custom/doctype/customize_form/customize_form.py Parādīt failu

@@ -558,7 +558,8 @@ docfield_properties = {
'allow_in_quick_entry': 'Check',
'hide_border': 'Check',
'hide_days': 'Check',
'hide_seconds': 'Check'
'hide_seconds': 'Check',
'is_virtual': 'Check',
}

doctype_link_properties = {


+ 8
- 1
frappe/custom/doctype/customize_form_field/customize_form_field.json Parādīt failu

@@ -14,6 +14,7 @@
"non_negative",
"reqd",
"unique",
"is_virtual",
"in_list_view",
"in_standard_filter",
"in_global_search",
@@ -115,6 +116,12 @@
"fieldtype": "Check",
"label": "Unique"
},
{
"default": "0",
"fieldname": "is_virtual",
"fieldtype": "Check",
"label": "Is Virtual"
},
{
"default": "0",
"fieldname": "in_list_view",
@@ -436,7 +443,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-01-03 14:50:32.035768",
"modified": "2022-01-27 21:45:22.349776",
"modified_by": "Administrator",
"module": "Custom",
"name": "Customize Form Field",


+ 7
- 6
frappe/model/base_document.py Parādīt failu

@@ -244,7 +244,13 @@ class BaseDocument(object):
continue

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":
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:
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], (
datetime.datetime,
datetime.date,


Notiek ielāde…
Atcelt
Saglabāt