fix(null-handling): for doctype, doctype, ignore null values
This commit is contained in:
parent
e5b97de255
commit
e2d3b86374
1 changed files with 6 additions and 2 deletions
|
|
@ -197,7 +197,7 @@ class BaseDocument(object):
|
|||
|
||||
return value
|
||||
|
||||
def get_valid_dict(self, sanitize=True, convert_dates_to_str=False):
|
||||
def get_valid_dict(self, sanitize=True, convert_dates_to_str=False, ignore_nulls = False):
|
||||
d = frappe._dict()
|
||||
for fieldname in self.meta.get_valid_columns():
|
||||
d[fieldname] = self.get(fieldname)
|
||||
|
|
@ -234,6 +234,9 @@ class BaseDocument(object):
|
|||
if convert_dates_to_str and isinstance(d[fieldname], (datetime.datetime, datetime.time, datetime.timedelta)):
|
||||
d[fieldname] = str(d[fieldname])
|
||||
|
||||
if d[fieldname] == None and ignore_nulls:
|
||||
del d[fieldname]
|
||||
|
||||
return d
|
||||
|
||||
def init_valid_columns(self):
|
||||
|
|
@ -306,7 +309,8 @@ class BaseDocument(object):
|
|||
self.creation = self.modified = now()
|
||||
self.created_by = self.modified_by = frappe.session.user
|
||||
|
||||
d = self.get_valid_dict(convert_dates_to_str=True)
|
||||
# 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 ('DocType', 'DocField', 'DocPerm'))
|
||||
|
||||
columns = list(d)
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue