fixes in data import tool and voucher import tool
This commit is contained in:
parent
037ce25f37
commit
809226bcb7
@ -35,12 +35,12 @@ def upload():
|
|||||||
rows = read_csv_content_from_uploaded_file()
|
rows = read_csv_content_from_uploaded_file()
|
||||||
|
|
||||||
common_values = get_common_values(rows)
|
common_values = get_common_values(rows)
|
||||||
data = get_data(rows)
|
data, start_idx = get_data(rows)
|
||||||
|
|
||||||
if rows[0][0]=="Voucher Import :Single":
|
if rows[0][0]=="Voucher Import :Single":
|
||||||
return import_single(common_values, data)
|
return import_single(common_values, data, start_idx)
|
||||||
else:
|
else:
|
||||||
return import_multiple(common_values, data)
|
return import_multiple(common_values, data, start_idx)
|
||||||
|
|
||||||
def map_fields(field_list, source, target):
|
def map_fields(field_list, source, target):
|
||||||
for f in field_list:
|
for f in field_list:
|
||||||
@ -49,12 +49,12 @@ def map_fields(field_list, source, target):
|
|||||||
else:
|
else:
|
||||||
target[f] = source.get(f)
|
target[f] = source.get(f)
|
||||||
|
|
||||||
def import_multiple(common_values, data):
|
def import_multiple(common_values, data, start_idx):
|
||||||
from webnotes.model.doc import Document
|
from webnotes.model.doc import Document
|
||||||
from webnotes.model.doclist import DocList
|
from webnotes.model.doclist import DocList
|
||||||
from webnotes.model.code import get_obj
|
from webnotes.model.code import get_obj
|
||||||
from accounts.utils import get_fiscal_year_from_date
|
from accounts.utils import get_fiscal_year
|
||||||
from webnotes.utils.dateutils import user_to_str
|
from webnotes.utils.dateutils import parse_date
|
||||||
|
|
||||||
messages = []
|
messages = []
|
||||||
|
|
||||||
@ -82,17 +82,17 @@ def import_multiple(common_values, data):
|
|||||||
jv = webnotes.DictObj()
|
jv = webnotes.DictObj()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
d.posting_date = user_to_str(d.posting_date)
|
d.posting_date = parse_date(d.posting_date)
|
||||||
d.due_date = user_to_str(d.due_date)
|
d.due_date = parse_date(d.due_date)
|
||||||
d.ref_date = user_to_str(d.ref_date)
|
d.ref_date = parse_date(d.ref_date)
|
||||||
d.company = common_values.company
|
d.company = common_values.company
|
||||||
|
|
||||||
jv = Document("Journal Voucher")
|
jv = Document("Journal Voucher")
|
||||||
map_fields(["voucher_type", "posting_date", "naming_series", "remarks:remark",
|
map_fields(["voucher_type", "posting_date", "naming_series", "remarks:remark",
|
||||||
"ref_no:cheque_no", "ref_date:cheque_date", "is_opening",
|
"ref_number:cheque_no", "ref_date:cheque_date", "is_opening",
|
||||||
"amount:total_debit", "amount:total_credit", "due_date", "company"], d, jv.fields)
|
"amount:total_debit", "amount:total_credit", "due_date", "company"], d, jv.fields)
|
||||||
|
|
||||||
jv.fiscal_year = get_fiscal_year_from_date(jv.posting_date)
|
jv.fiscal_year = get_fiscal_year(jv.posting_date)[0]
|
||||||
|
|
||||||
detail1 = Document("Journal Voucher Detail")
|
detail1 = Document("Journal Voucher Detail")
|
||||||
detail1.parent = True
|
detail1.parent = True
|
||||||
@ -112,13 +112,15 @@ def import_multiple(common_values, data):
|
|||||||
doclist.submit()
|
doclist.submit()
|
||||||
webnotes.conn.commit()
|
webnotes.conn.commit()
|
||||||
|
|
||||||
messages.append("<p style='color: green'>[row #%s] %s imported</p>" \
|
messages.append("""<p style='color: green'>[row #%s]
|
||||||
% (i, jv.name))
|
<a href=\"#Form/Journal Voucher/%s\">%s</a> imported</p>""" \
|
||||||
|
% ((start_idx + 1) + i, jv.name, jv.name))
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
webnotes.conn.rollback()
|
webnotes.conn.rollback()
|
||||||
|
err_msg = webnotes.message_log and webnotes.message_log[0] or unicode(e)
|
||||||
messages.append("<p style='color: red'>[row #%s] %s failed: %s</p>" \
|
messages.append("<p style='color: red'>[row #%s] %s failed: %s</p>" \
|
||||||
% (i, jv.name, webnotes.message_log and webnotes.message_log[0] or "No message"))
|
% ((start_idx + 1) + i, jv.name, err_msg or "No message"))
|
||||||
webnotes.errprint(webnotes.getTraceback())
|
webnotes.errprint(webnotes.getTraceback())
|
||||||
|
|
||||||
webnotes.message_log = []
|
webnotes.message_log = []
|
||||||
@ -142,11 +144,13 @@ def get_common_values(rows):
|
|||||||
def get_data(rows):
|
def get_data(rows):
|
||||||
start_row = 0
|
start_row = 0
|
||||||
data = []
|
data = []
|
||||||
|
start_row_idx = 0
|
||||||
|
|
||||||
for i in xrange(len(rows)):
|
for i in xrange(len(rows)):
|
||||||
r = rows[i]
|
r = rows[i]
|
||||||
if r[0]:
|
if r[0]:
|
||||||
if start_row and i >= start_row:
|
if start_row and i >= start_row:
|
||||||
|
if not start_row_idx: start_row_idx = i
|
||||||
d = webnotes.DictObj()
|
d = webnotes.DictObj()
|
||||||
for cidx in xrange(len(columns)):
|
for cidx in xrange(len(columns)):
|
||||||
d[columns[cidx]] = r[cidx]
|
d[columns[cidx]] = r[cidx]
|
||||||
@ -155,7 +159,8 @@ def get_data(rows):
|
|||||||
if r[0]=="--------Data----------":
|
if r[0]=="--------Data----------":
|
||||||
start_row = i+2
|
start_row = i+2
|
||||||
columns = [c.replace(" ", "_").lower() for c in rows[i+1]]
|
columns = [c.replace(" ", "_").lower() for c in rows[i+1]]
|
||||||
return data
|
|
||||||
|
return data, start_row_idx
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_template_single():
|
def get_template_single():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user