fix: Show Error for invalid template

- For template with invalid extension or not enough rows
This commit is contained in:
Faris Ansari 2019-11-19 17:33:28 +05:30
parent e67652261e
commit af4f9b2e3e

View file

@ -80,6 +80,12 @@ class Importer:
return file_content, extn
def read_content(self, content, extension):
error_title = _("Template Error")
if extension not in ("csv", "xlsx", "xls"):
frappe.throw(
_("Import template should be of type .csv, .xlsx or .xls"), title=error_title
)
if extension == "csv":
data = read_csv_content(content)
elif extension == "xlsx":
@ -87,6 +93,11 @@ class Importer:
elif extension == "xls":
data = read_xls_file_from_attached_file(content)
if len(data) <= 1:
frappe.throw(
_("Import template should contain a Header and atleast one row."), title=error_title
)
self.header_row = data[0]
self.data = data[1:]