error fixes in voucher import tool
This commit is contained in:
parent
b444ba73e9
commit
4fecbc1b3d
@ -89,77 +89,86 @@ def import_vouchers(common_values, data, start_idx, import_type):
|
|||||||
"against_journal_voucher:against_jv"], d, detail.fields)
|
"against_journal_voucher:against_jv"], d, detail.fields)
|
||||||
|
|
||||||
webnotes.conn.commit()
|
webnotes.conn.commit()
|
||||||
for i in xrange(len(data)):
|
try:
|
||||||
d = data[i][0]
|
webnotes.conn.begin()
|
||||||
jv = webnotes.DictObj()
|
for i in xrange(len(data)):
|
||||||
|
d = data[i][0]
|
||||||
|
if import_type == "Voucher Import: Two Accounts" and flt(d.get("amount")) == 0:
|
||||||
|
webnotes.message_log = ["Amount not specified"]
|
||||||
|
raise Exception
|
||||||
|
elif import_type == "Voucher Import: Multiple Accounts" and \
|
||||||
|
(flt(d.get("total_debit")) == 0 or flt(d.get("total_credit")) == 0):
|
||||||
|
webnotes.message_log = ["Total Debit and Total Credit amount can not be zero"]
|
||||||
|
raise Exception
|
||||||
|
else:
|
||||||
|
d.posting_date = parse_date(d.posting_date)
|
||||||
|
d.due_date = d.due_date and parse_date(d.due_date) or None
|
||||||
|
|
||||||
try:
|
if d.ref_number:
|
||||||
d.posting_date = parse_date(d.posting_date)
|
if not d.ref_date:
|
||||||
d.due_date = d.due_date and parse_date(d.due_date) or None
|
raise webnotes.ValidationError, \
|
||||||
|
"""Ref Date is Mandatory if Ref Number is specified"""
|
||||||
|
d.ref_date = parse_date(d.ref_date)
|
||||||
|
|
||||||
if d.ref_number:
|
d.company = common_values.company
|
||||||
if not d.ref_date:
|
|
||||||
raise webnotes.ValidationError, \
|
|
||||||
"""Ref Date is Mandatory if Ref Number is specified"""
|
|
||||||
d.ref_date = parse_date(d.ref_date)
|
|
||||||
|
|
||||||
d.company = common_values.company
|
jv = Document("Journal Voucher")
|
||||||
|
map_fields(["voucher_type", "posting_date", "naming_series",
|
||||||
|
"remarks:user_remark", "ref_number:cheque_no", "ref_date:cheque_date",
|
||||||
|
"is_opening", "due_date", "company"], d, jv.fields)
|
||||||
|
|
||||||
jv = Document("Journal Voucher")
|
jv.fiscal_year = get_fiscal_year(jv.posting_date)[0]
|
||||||
map_fields(["voucher_type", "posting_date", "naming_series", "remarks:user_remark",
|
|
||||||
"ref_number:cheque_no", "ref_date:cheque_date", "is_opening",
|
|
||||||
"amount:total_debit", "amount:total_credit", "due_date", "company"], d, jv.fields)
|
|
||||||
|
|
||||||
jv.fiscal_year = get_fiscal_year(jv.posting_date)[0]
|
details = []
|
||||||
|
if import_type == "Voucher Import: Two Accounts":
|
||||||
|
map_fields(["amount:total_debit", "amount:total_credit"], d, jv.fields)
|
||||||
|
|
||||||
details = []
|
detail1 = Document("Journal Voucher Detail")
|
||||||
if import_type == "Voucher Import: Two Accounts":
|
detail1.parent = True
|
||||||
detail1 = Document("Journal Voucher Detail")
|
detail1.parentfield = "entries"
|
||||||
detail1.parent = True
|
map_fields(["debit_account:account","amount:debit"], d, detail1.fields)
|
||||||
detail1.parentfield = "entries"
|
apply_cost_center_and_against_invoice(detail1, d)
|
||||||
map_fields(["debit_account:account","amount:debit"], d, detail1.fields)
|
|
||||||
apply_cost_center_and_against_invoice(detail1, d)
|
|
||||||
|
|
||||||
|
|
||||||
detail2 = Document("Journal Voucher Detail")
|
detail2 = Document("Journal Voucher Detail")
|
||||||
detail2.parent = True
|
detail2.parent = True
|
||||||
detail2.parentfield = "entries"
|
detail2.parentfield = "entries"
|
||||||
map_fields(["credit_account:account","amount:credit"], d, detail2.fields)
|
map_fields(["credit_account:account","amount:credit"], d, detail2.fields)
|
||||||
apply_cost_center_and_against_invoice(detail2, d)
|
apply_cost_center_and_against_invoice(detail2, d)
|
||||||
|
|
||||||
details = [detail1, detail2]
|
details = [detail1, detail2]
|
||||||
elif import_type == "Voucher Import: Multiple Accounts":
|
elif import_type == "Voucher Import: Multiple Accounts":
|
||||||
accounts = data[i][1]
|
map_fields(["total_debit", "total_credit"], d, jv.fields)
|
||||||
for acc in accounts:
|
accounts = data[i][1]
|
||||||
detail = Document("Journal Voucher Detail")
|
for acc in accounts:
|
||||||
detail.parent = True
|
detail = Document("Journal Voucher Detail")
|
||||||
detail.parentfield = "entries"
|
detail.parent = True
|
||||||
detail.account = acc
|
detail.parentfield = "entries"
|
||||||
detail.debit = flt(accounts[acc]) > 0 and flt(accounts[acc]) or 0
|
detail.account = acc
|
||||||
detail.credit = flt(accounts[acc]) < 0 and -1*flt(accounts[acc]) or 0
|
detail.debit = flt(accounts[acc]) > 0 and flt(accounts[acc]) or 0
|
||||||
apply_cost_center_and_against_invoice(detail, d)
|
detail.credit = flt(accounts[acc]) < 0 and -1*flt(accounts[acc]) or 0
|
||||||
details.append(detail)
|
apply_cost_center_and_against_invoice(detail, d)
|
||||||
|
details.append(detail)
|
||||||
|
|
||||||
if not details:
|
if not details:
|
||||||
messages.append("""<p style='color: red'>No accounts found.
|
webnotes.message_log = ["""No accounts found.
|
||||||
If you entered accounts correctly, please check template once</p>""")
|
If you entered accounts correctly, please check template once"""]
|
||||||
return
|
raise Exception
|
||||||
webnotes.conn.begin()
|
|
||||||
doclist = DocList([jv]+details)
|
|
||||||
doclist.submit()
|
|
||||||
webnotes.conn.commit()
|
|
||||||
|
|
||||||
messages.append("""<p style='color: green'>[row #%s]
|
doclist = DocList([jv]+details)
|
||||||
<a href=\"#Form/Journal Voucher/%s\">%s</a> imported</p>""" \
|
doclist.submit()
|
||||||
% ((start_idx + 1) + i, jv.name, jv.name))
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
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>" \
|
|
||||||
% ((start_idx + 1) + i, jv.name or "", err_msg or "No message"))
|
|
||||||
webnotes.errprint(webnotes.getTraceback())
|
|
||||||
|
|
||||||
|
messages.append("""<p style='color: green'>[row #%s]
|
||||||
|
<a href=\"#Form/Journal Voucher/%s\">%s</a> imported</p>""" \
|
||||||
|
% ((start_idx + 1) + i, jv.name, jv.name))
|
||||||
|
webnotes.conn.commit()
|
||||||
|
except Exception, e:
|
||||||
|
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>"""
|
||||||
|
% ((start_idx + 1) + i, jv.name or "", err_msg or "No message"))
|
||||||
|
messages.append("<p style='color: red'>All transactions rolled back</p>")
|
||||||
|
webnotes.errprint(webnotes.getTraceback())
|
||||||
webnotes.message_log = []
|
webnotes.message_log = []
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
@ -192,12 +201,18 @@ def get_data(rows, company_abbr):
|
|||||||
d[columns[cidx]] = r[cidx]
|
d[columns[cidx]] = r[cidx]
|
||||||
|
|
||||||
if accounts:
|
if accounts:
|
||||||
total = 0
|
total_debit = total_credit = 0
|
||||||
for acc_idx in xrange(len(accounts)):
|
for acc_idx in xrange(len(accounts)):
|
||||||
col_idx = len(columns) + acc_idx
|
col_idx = len(columns) + acc_idx
|
||||||
acc_dict[accounts[acc_idx]] = r[col_idx]
|
if flt(r[col_idx]) != 0:
|
||||||
if flt(r[col_idx]) > 0: total += flt(r[col_idx])
|
acc_dict[accounts[acc_idx]] = r[col_idx]
|
||||||
d['amount'] = total
|
if flt(r[col_idx]) > 0:
|
||||||
|
total_debit += flt(r[col_idx])
|
||||||
|
else:
|
||||||
|
total_credit += abs(flt(r[col_idx]))
|
||||||
|
|
||||||
|
d['total_debit'] = total_debit
|
||||||
|
d['total_credit'] = total_credit
|
||||||
|
|
||||||
data.append([d, acc_dict])
|
data.append([d, acc_dict])
|
||||||
|
|
||||||
@ -205,7 +220,7 @@ def get_data(rows, company_abbr):
|
|||||||
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]
|
||||||
if not c.endswith(company_abbr)]
|
if not c.endswith(" - " + company_abbr)]
|
||||||
accounts = [c for c in rows[i+1] if c.endswith(company_abbr)]
|
accounts = [c for c in rows[i+1] if c.endswith(" - " + company_abbr)]
|
||||||
|
|
||||||
return data, start_row_idx
|
return data, start_row_idx
|
Loading…
x
Reference in New Issue
Block a user