voucher import tool - throw message if empty columns are found

This commit is contained in:
Anand Doshi 2013-03-05 14:44:05 +05:30
parent 94f44b4073
commit 18c1980e38

View File

@ -1,6 +1,6 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt
from webnotes.utils import flt, comma_and
@webnotes.whitelist()
def get_template():
@ -231,6 +231,14 @@ def get_data(rows, company_abbr):
if r[0]=="--------Data----------":
start_row = i+2
# check for empty columns
empty_columns = [i+1 for i, c in enumerate(rows[i+1]) if not c]
if empty_columns:
raise Exception, """Column No(s). %s %s empty. \
Please remove them and try again.""" % (comma_and(empty_columns),
len(empty_columns)==1 and "is" or "are")
columns = [c.replace(" ", "_").lower() for c in rows[i+1]
if not c.endswith(" - " + company_abbr)]
accounts = [c for c in rows[i+1] if c.endswith(" - " + company_abbr)]