fix export fixture

This commit is contained in:
Pratik Vyas 2015-03-05 15:14:02 +05:30
parent 75834b555f
commit d681caa479
2 changed files with 6 additions and 3 deletions

View file

@ -46,8 +46,11 @@ def export_csv(doctype, path):
def export_json(doctype, path, filters=None):
from frappe.utils.response import json_handler
out = []
for doc in frappe.get_all(doctype, fields=["name"], filters=filters, limit_page_length=0, order_by="creation asc"):
out.append(frappe.get_doc(doctype, doc.name).as_dict())
if frappe.db.get_value("DocType", doctype, "issingle"):
out.append(frappe.get_doc(doctype).as_dict())
else:
for doc in frappe.get_all(doctype, fields=["name"], filters=filters, limit_page_length=0, order_by="creation asc"):
out.append(frappe.get_doc(doctype, doc.name).as_dict())
with open(path, "w") as outfile:
outfile.write(json.dumps(out, default=json_handler, indent=1, sort_keys=True))

View file

@ -28,6 +28,6 @@ def export_fixtures():
if isinstance(fixture, basestring):
fixture = [fixture];
if frappe.db.get_value("DocType", fixture[0], "issingle"):
export_fixture(fixture[0], fixture[0], app)
export_fixture(fixture[0], app)
else:
export_csv(fixture, frappe.get_app_path(app, "fixtures", frappe.scrub(fixture[0]) + ".csv"))