Merge pull request #15972 from gavindsouza/virtual-docfield-fixes-0
fix(Virtual DocField): Misc fixes
This commit is contained in:
commit
f5afe4fd4a
3 changed files with 17 additions and 4 deletions
|
|
@ -242,7 +242,7 @@ class BaseDocument(object):
|
|||
|
||||
return value
|
||||
|
||||
def get_valid_dict(self, sanitize=True, convert_dates_to_str=False, ignore_nulls = False):
|
||||
def get_valid_dict(self, sanitize=True, convert_dates_to_str=False, ignore_nulls=False, ignore_virtual=False):
|
||||
d = frappe._dict()
|
||||
for fieldname in self.meta.get_valid_columns():
|
||||
d[fieldname] = self.get(fieldname)
|
||||
|
|
@ -254,6 +254,10 @@ class BaseDocument(object):
|
|||
df = self.meta.get_field(fieldname)
|
||||
|
||||
if df and df.get("is_virtual"):
|
||||
if ignore_virtual:
|
||||
del d[fieldname]
|
||||
continue
|
||||
|
||||
from frappe.utils.safe_exec import get_safe_globals
|
||||
|
||||
if d[fieldname] is None:
|
||||
|
|
@ -412,7 +416,11 @@ class BaseDocument(object):
|
|||
self.created_by = self.modified_by = frappe.session.user
|
||||
|
||||
# if doctype is "DocType", don't insert null values as we don't know who is valid yet
|
||||
d = self.get_valid_dict(convert_dates_to_str=True, ignore_nulls = self.doctype in DOCTYPES_FOR_DOCTYPE)
|
||||
d = self.get_valid_dict(
|
||||
convert_dates_to_str=True,
|
||||
ignore_nulls=self.doctype in DOCTYPES_FOR_DOCTYPE,
|
||||
ignore_virtual=True,
|
||||
)
|
||||
|
||||
columns = list(d)
|
||||
try:
|
||||
|
|
@ -766,7 +774,7 @@ class BaseDocument(object):
|
|||
|
||||
type_map = frappe.db.type_map
|
||||
|
||||
for fieldname, value in self.get_valid_dict().items():
|
||||
for fieldname, value in self.get_valid_dict(ignore_virtual=True).items():
|
||||
df = self.meta.get_field(fieldname)
|
||||
|
||||
if not df or df.fieldtype == 'Check':
|
||||
|
|
@ -844,7 +852,7 @@ class BaseDocument(object):
|
|||
if frappe.flags.in_install:
|
||||
return
|
||||
|
||||
for fieldname, value in self.get_valid_dict().items():
|
||||
for fieldname, value in self.get_valid_dict(ignore_virtual=True).items():
|
||||
if not value or not isinstance(value, str):
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -184,6 +184,7 @@ frappe.patches.v13_0.queryreport_columns
|
|||
frappe.patches.v13_0.jinja_hook
|
||||
frappe.patches.v13_0.update_notification_channel_if_empty
|
||||
frappe.patches.v13_0.set_first_day_of_the_week
|
||||
execute:frappe.reload_doc('custom', 'doctype', 'custom_field')
|
||||
frappe.patches.v14_0.update_workspace2 # 20.09.2021
|
||||
frappe.patches.v14_0.save_ratings_in_fraction #23-12-2021
|
||||
frappe.patches.v14_0.transform_todo_schema
|
||||
|
|
|
|||
|
|
@ -271,6 +271,10 @@ class TestDocument(unittest.TestCase):
|
|||
"""Virtual fields are accessible via API and Form views, whenever .as_dict is invoked
|
||||
"""
|
||||
frappe.db.delete("Custom Field", {"dt": "Note", "fieldname":"age"})
|
||||
note = frappe.new_doc("Note")
|
||||
note.content = "some content"
|
||||
note.title = frappe.generate_hash(length=20)
|
||||
note.insert()
|
||||
|
||||
def patch_note():
|
||||
return patch("frappe.controllers", new={frappe.local.site: {'Note': CustomTestNote}})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue