diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 0df22a39ef..c94fe8db24 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -18,6 +18,7 @@ from frappe.modules import make_boilerplate, get_doc_path from frappe.database.schema import validate_column_name, validate_column_length from frappe.model.docfield import supports_translation from frappe.modules.import_file import get_file_path +from six import iteritems import frappe.website.render import json @@ -407,6 +408,21 @@ class DocType(Document): make_property_setter(self.name, "naming_series", "default", naming_series[0].default, "Text", validate_fields_for_doctype=False) def before_export(self, docdict): + # remove null and empty fields + def remove_null_fields(o): + to_remove = [] + for attr, value in iteritems(o): + if isinstance(value, list): + for v in value: + remove_null_fields(v) + elif not value: + to_remove.append(attr) + + for attr in to_remove: + del o[attr] + + remove_null_fields(docdict) + # retain order of 'fields' table and change order in 'field_order' docdict["field_order"] = [f.fieldname for f in self.fields] diff --git a/frappe/modules/import_file.py b/frappe/modules/import_file.py index 7a5b96ad1a..fb49dadc7d 100644 --- a/frappe/modules/import_file.py +++ b/frappe/modules/import_file.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals, print_function import frappe, os, json -from frappe.modules import get_module_path, scrub_dt_dn, load_doctype_module +from frappe.modules import get_module_path, scrub_dt_dn from frappe.utils import get_datetime_str from frappe.model.base_document import get_controller