fix: Show Error for invalid template
- For template with invalid extension or not enough rows
This commit is contained in:
parent
e67652261e
commit
af4f9b2e3e
1 changed files with 11 additions and 0 deletions
|
|
@ -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:]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue