[IMP] end error messages with a point instead of an exclamation point in account_coda

bzr revid: abo@openerp.com-20120807095820-7e6j6mh9u8gp6cny
This commit is contained in:
Antonin Bourguignon 2012-08-07 11:58:20 +02:00
parent a52eeef519
commit ca16c1d0a1
1 changed files with 159 additions and 160 deletions

View File

@ -2,9 +2,9 @@
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution
# #
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved. # Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the # published by the Free Software Foundation, either version 3 of the
@ -41,7 +41,7 @@ class account_coda_import(osv.osv_memory):
_defaults = { _defaults = {
'coda_fname': lambda *a: '', 'coda_fname': lambda *a: '',
} }
def coda_parsing(self, cr, uid, ids, context=None, batch=False, codafile=None, codafilename=None): def coda_parsing(self, cr, uid, ids, context=None, batch=False, codafile=None, codafilename=None):
if context is None: if context is None:
context = {} context = {}
@ -52,12 +52,12 @@ class account_coda_import(osv.osv_memory):
data=self.browse(cr,uid,ids)[0] data=self.browse(cr,uid,ids)[0]
try: try:
codafile = data.coda_data codafile = data.coda_data
codafilename = data.coda_fname codafilename = data.coda_fname
except: except:
raise osv.except_osv(_('Error!'), _('Wizard in incorrect state. Please hit the Cancel button!')) raise osv.except_osv(_('Error!'), _('Wizard in incorrect state. Please hit the Cancel button.'))
return {} return {}
currency_obj = self.pool.get('res.currency') currency_obj = self.pool.get('res.currency')
coda_bank_account_obj = self.pool.get('coda.bank.account') coda_bank_account_obj = self.pool.get('coda.bank.account')
trans_type_obj = self.pool.get('account.coda.trans.type') trans_type_obj = self.pool.get('account.coda.trans.type')
trans_code_obj = self.pool.get('account.coda.trans.code') trans_code_obj = self.pool.get('account.coda.trans.code')
@ -85,7 +85,7 @@ class account_coda_import(osv.osv_memory):
coda_bank.update({'journal_code': coda_bank['journal'] and journal_obj.browse(cr, uid, coda_bank['journal'][0], context=context).code or ''}) coda_bank.update({'journal_code': coda_bank['journal'] and journal_obj.browse(cr, uid, coda_bank['journal'][0], context=context).code or ''})
coda_bank.update({'iban': partner_bank_obj.browse(cr, uid, coda_bank['bank_id'][0], context=context).iban}) coda_bank.update({'iban': partner_bank_obj.browse(cr, uid, coda_bank['bank_id'][0], context=context).iban})
coda_bank.update({'acc_number': partner_bank_obj.browse(cr, uid, coda_bank['bank_id'][0], context=context).acc_number}) coda_bank.update({'acc_number': partner_bank_obj.browse(cr, uid, coda_bank['bank_id'][0], context=context).acc_number})
coda_bank.update({'currency_name': currency_obj.browse(cr, uid, coda_bank['currency'][0], context=context).name}) coda_bank.update({'currency_name': currency_obj.browse(cr, uid, coda_bank['currency'][0], context=context).name})
trans_type_table = trans_type_obj.read(cr, uid, trans_type_obj.search(cr, uid, []), context=context) trans_type_table = trans_type_obj.read(cr, uid, trans_type_obj.search(cr, uid, []), context=context)
trans_code_table = trans_code_obj.read(cr, uid, trans_code_obj.search(cr, uid, []), context=context) trans_code_table = trans_code_obj.read(cr, uid, trans_code_obj.search(cr, uid, []), context=context)
trans_category_table = trans_category_obj.read(cr, uid, trans_category_obj.search(cr, uid, []), context=context) trans_category_table = trans_category_obj.read(cr, uid, trans_category_obj.search(cr, uid, []), context=context)
@ -96,9 +96,9 @@ class account_coda_import(osv.osv_memory):
err_log = '' err_log = ''
coda_statements = [] coda_statements = []
recordlist = unicode(base64.decodestring(codafile), 'windows-1252', 'strict').split('\n') recordlist = unicode(base64.decodestring(codafile), 'windows-1252', 'strict').split('\n')
for line in recordlist: for line in recordlist:
if not line: if not line:
pass pass
elif line[0] == '0': elif line[0] == '0':
@ -109,11 +109,11 @@ class account_coda_import(osv.osv_memory):
st_line_seq = 0 st_line_seq = 0
glob_lvl_stack = [0] glob_lvl_stack = [0]
# header data # header data
coda_statement['currency'] = 'EUR' # default currency coda_statement['currency'] = 'EUR' # default currency
coda_statement['version'] = line[127] coda_statement['version'] = line[127]
coda_version = line[127] coda_version = line[127]
if coda_version not in ['1','2']: if coda_version not in ['1','2']:
err_string = _('\nCODA V%s statements are not supported, please contact your bank!') % coda_version err_string = _('\nCODA V%s statements are not supported, please contact your bank.') % coda_version
err_code = 'R0001' err_code = 'R0001'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
@ -122,7 +122,7 @@ class account_coda_import(osv.osv_memory):
coda_statement['date'] = str2date(line[5:11]) coda_statement['date'] = str2date(line[5:11])
period_id = period_obj.search(cr , uid, [('date_start' ,'<=', coda_statement['date']), ('date_stop','>=',coda_statement['date'])]) period_id = period_obj.search(cr , uid, [('date_start' ,'<=', coda_statement['date']), ('date_stop','>=',coda_statement['date'])])
if not period_id: if not period_id:
err_string = _("\nThe CODA creation date doesn't fall within a defined Accounting Period!" \ err_string = _("\nThe CODA creation date doesn't fall within a defined Accounting Period." \
"\nPlease create the Accounting Period for date %s.") % coda_statement['date'] "\nPlease create the Accounting Period for date %s.") % coda_statement['date']
err_code = 'R0002' err_code = 'R0002'
if batch: if batch:
@ -130,19 +130,19 @@ class account_coda_import(osv.osv_memory):
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
coda_statement['period_id'] = period_id[0] coda_statement['period_id'] = period_id[0]
coda_statement['state'] = 'draft' coda_statement['state'] = 'draft'
coda_id = coda_obj.search(cr, uid,[ coda_id = coda_obj.search(cr, uid,[
('name', '=', codafilename), ('name', '=', codafilename),
('coda_creation_date', '=', coda_statement['date']), ('coda_creation_date', '=', coda_statement['date']),
]) ])
if coda_id: if coda_id:
err_string = _("\nCODA File with Filename '%s' and Creation Date '%s' has already been imported !") \ err_string = _("\nCODA File with Filename '%s' and Creation Date '%s' has already been imported.") \
% (codafilename, coda_statement['date']) % (codafilename, coda_statement['date'])
err_code = 'W0001' err_code = 'W0001'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Warning !'), err_string) raise osv.except_osv(_('Warning !'), err_string)
elif line[0] == '1': elif line[0] == '1':
if coda_version == '1': if coda_version == '1':
coda_statement['acc_number'] = line[5:17] coda_statement['acc_number'] = line[5:17]
@ -150,24 +150,24 @@ class account_coda_import(osv.osv_memory):
coda_statement['currency'] = line[18:21] coda_statement['currency'] = line[18:21]
elif line[1] == '0': # Belgian bank account BBAN structure elif line[1] == '0': # Belgian bank account BBAN structure
coda_statement['acc_number'] = line[5:17] coda_statement['acc_number'] = line[5:17]
coda_statement['currency'] = line[18:21] coda_statement['currency'] = line[18:21]
elif line[1] == '1': # foreign bank account BBAN structure elif line[1] == '1': # foreign bank account BBAN structure
err_string = _('\nForeign bank accounts with BBAN structure are not supported !') err_string = _('\nForeign bank accounts with BBAN structure are not supported.')
err_code = 'R1001' err_code = 'R1001'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
elif line[1] == '2': # Belgian bank account IBAN structure elif line[1] == '2': # Belgian bank account IBAN structure
coda_statement['acc_number']=line[5:21] coda_statement['acc_number']=line[5:21]
coda_statement['currency'] = line[39:42] coda_statement['currency'] = line[39:42]
elif line[1] == '3': # foreign bank account IBAN structure elif line[1] == '3': # foreign bank account IBAN structure
err_string = _('\nForeign bank accounts with IBAN structure are not supported !') err_string = _('\nForeign bank accounts with IBAN structure are not supported.')
err_code = 'R1002' err_code = 'R1002'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
else: else:
err_string = _('\nUnsupported bank account structure !') err_string = _('\nUnsupported bank account structure.')
err_code = 'R1003' err_code = 'R1003'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
@ -177,11 +177,11 @@ class account_coda_import(osv.osv_memory):
and (coda_statement['currency'] == x['currency_name']) and (coda_statement['description'] == (x['description1'] or x['description2'] or '')) and (coda_statement['currency'] == x['currency_name']) and (coda_statement['description'] == (x['description1'] or x['description2'] or ''))
coda_bank = filter(cba_filter, coda_bank_table) coda_bank = filter(cba_filter, coda_bank_table)
if coda_bank: if coda_bank:
coda_bank = coda_bank[0] coda_bank = coda_bank[0]
coda_statement['type'] = coda_bank['state'] coda_statement['type'] = coda_bank['state']
coda_statement['journal_id'] = coda_bank['journal'] and coda_bank['journal'][0] coda_statement['journal_id'] = coda_bank['journal'] and coda_bank['journal'][0]
coda_statement['currency_id'] = coda_bank['currency'][0] coda_statement['currency_id'] = coda_bank['currency'][0]
coda_statement['coda_bank_account_id'] = coda_bank['id'] coda_statement['coda_bank_account_id'] = coda_bank['id']
def_pay_acc = coda_bank['def_payable'][0] def_pay_acc = coda_bank['def_payable'][0]
def_rec_acc = coda_bank['def_receivable'][0] def_rec_acc = coda_bank['def_receivable'][0]
awaiting_acc = coda_bank['awaiting_account'][0] awaiting_acc = coda_bank['awaiting_account'][0]
@ -189,8 +189,8 @@ class account_coda_import(osv.osv_memory):
find_bbacom = coda_bank['find_bbacom'] find_bbacom = coda_bank['find_bbacom']
find_partner = coda_bank['find_partner'] find_partner = coda_bank['find_partner']
else: else:
err_string = _("\nNo matching CODA Bank Account Configuration record found !") + \ err_string = _("\nNo matching CODA Bank Account Configuration record found.") + \
_("\nPlease check if the 'Bank Account Number', 'Currency' and 'Account Description' fields of your configuration record match with '%s', '%s' and '%s' !") \ _("\nPlease check if the 'Bank Account Number', 'Currency' and 'Account Description' fields of your configuration record match with '%s', '%s' and '%s'.") \
% (coda_statement['acc_number'], coda_statement['currency'], coda_statement['description']) % (coda_statement['acc_number'], coda_statement['currency'], coda_statement['description'])
err_code = 'R1004' err_code = 'R1004'
if batch: if batch:
@ -199,13 +199,13 @@ class account_coda_import(osv.osv_memory):
bal_start = list2float(line[43:58]) # old balance data bal_start = list2float(line[43:58]) # old balance data
if line[42] == '1': # 1= Debit if line[42] == '1': # 1= Debit
bal_start = - bal_start bal_start = - bal_start
coda_statement['balance_start'] = bal_start coda_statement['balance_start'] = bal_start
coda_statement['acc_holder'] = line[64:90] coda_statement['acc_holder'] = line[64:90]
coda_statement['paper_seq_number'] = line[2:5] coda_statement['paper_seq_number'] = line[2:5]
coda_statement['coda_seq_number'] = line[125:128] coda_statement['coda_seq_number'] = line[125:128]
if coda_bank['coda_st_naming']: if coda_bank['coda_st_naming']:
coda_statement['name'] = coda_bank['coda_st_naming'] % { coda_statement['name'] = coda_bank['coda_st_naming'] % {
'code': coda_bank['journal_code'] or '', 'code': coda_bank['journal_code'] or '',
'year': time.strftime('%Y'), 'year': time.strftime('%Y'),
'y': time.strftime('%y'), 'y': time.strftime('%y'),
'coda': line[125:128], 'coda': line[125:128],
@ -213,7 +213,7 @@ class account_coda_import(osv.osv_memory):
} }
else: else:
coda_statement['name'] = '/' coda_statement['name'] = '/'
elif line[0] == '2': elif line[0] == '2':
# movement data record 2 # movement data record 2
if line[1] == '1': if line[1] == '1':
@ -222,7 +222,7 @@ class account_coda_import(osv.osv_memory):
st_line_seq = st_line_seq + 1 st_line_seq = st_line_seq + 1
st_line['sequence'] = st_line_seq st_line['sequence'] = st_line_seq
st_line['type'] = 'general' st_line['type'] = 'general'
st_line['reconcile'] = False st_line['reconcile'] = False
st_line['struct_comm_type'] = '' st_line['struct_comm_type'] = ''
st_line['struct_comm_type_desc'] = '' st_line['struct_comm_type_desc'] = ''
st_line['struct_comm_101'] = '' st_line['struct_comm_101'] = ''
@ -230,25 +230,25 @@ class account_coda_import(osv.osv_memory):
st_line['partner_id'] = 0 st_line['partner_id'] = 0
st_line['account_id'] = 0 st_line['account_id'] = 0
st_line['counterparty_name'] = '' st_line['counterparty_name'] = ''
st_line['counterparty_bic'] = '' st_line['counterparty_bic'] = ''
st_line['counterparty_number'] = '' st_line['counterparty_number'] = ''
st_line['counterparty_currency'] = '' st_line['counterparty_currency'] = ''
st_line['glob_lvl_flag'] = False st_line['glob_lvl_flag'] = False
st_line['globalisation_id'] = 0 st_line['globalisation_id'] = 0
st_line['globalisation_code'] = '' st_line['globalisation_code'] = ''
st_line['globalisation_amount'] = False st_line['globalisation_amount'] = False
st_line['amount'] = False st_line['amount'] = False
st_line['ref'] = line[2:10] st_line['ref'] = line[2:10]
st_line['trans_ref'] = line[10:31] st_line['trans_ref'] = line[10:31]
st_line_amt = list2float(line[32:47]) st_line_amt = list2float(line[32:47])
if line[31] == '1': # 1=debit if line[31] == '1': # 1=debit
st_line_amt = - st_line_amt st_line_amt = - st_line_amt
# processing of amount depending on globalisation code # processing of amount depending on globalisation code
glob_lvl_flag = int(line[124]) glob_lvl_flag = int(line[124])
if glob_lvl_flag > 0: if glob_lvl_flag > 0:
if glob_lvl_stack[-1] == glob_lvl_flag: if glob_lvl_stack[-1] == glob_lvl_flag:
st_line['glob_lvl_flag'] = glob_lvl_flag st_line['glob_lvl_flag'] = glob_lvl_flag
st_line['amount'] = st_line_amt st_line['amount'] = st_line_amt
glob_lvl_stack.pop() glob_lvl_stack.pop()
else: else:
@ -265,23 +265,23 @@ class account_coda_import(osv.osv_memory):
st_line['trans_type'] = line[53] st_line['trans_type'] = line[53]
trans_type = filter(lambda x: st_line['trans_type'] == x['type'], trans_type_table) trans_type = filter(lambda x: st_line['trans_type'] == x['type'], trans_type_table)
if not trans_type: if not trans_type:
err_string = _('\nThe File contains an invalid CODA Transaction Type : %s!') % st_line['trans_type'] err_string = _('\nThe File contains an invalid CODA Transaction Type : %s.') % st_line['trans_type']
err_code = 'R2001' err_code = 'R2001'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
st_line['trans_type_desc'] = trans_type[0]['description'] st_line['trans_type_desc'] = trans_type[0]['description']
st_line['trans_family'] = line[54:56] st_line['trans_family'] = line[54:56]
trans_family = filter(lambda x: (x['type'] == 'family') and (st_line['trans_family'] == x['code']), trans_code_table) trans_family = filter(lambda x: (x['type'] == 'family') and (st_line['trans_family'] == x['code']), trans_code_table)
if not trans_family: if not trans_family:
err_string = _('\nThe File contains an invalid CODA Transaction Family : %s!') % st_line['trans_family'] err_string = _('\nThe File contains an invalid CODA Transaction Family : %s.') % st_line['trans_family']
err_code = 'R2002' err_code = 'R2002'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
st_line['trans_family_desc'] = trans_family[0]['description'] st_line['trans_family_desc'] = trans_family[0]['description']
st_line['trans_code'] = line[56:58] st_line['trans_code'] = line[56:58]
trans_code = filter(lambda x: (x['type'] == 'code') and (st_line['trans_code'] == x['code']) and (trans_family[0]['id'] == x['parent_id'][0]), trans_code = filter(lambda x: (x['type'] == 'code') and (st_line['trans_code'] == x['code']) and (trans_family[0]['id'] == x['parent_id'][0]),
trans_code_table) trans_code_table)
if trans_code: if trans_code:
st_line['trans_code_desc'] = trans_code[0]['description'] st_line['trans_code_desc'] = trans_code[0]['description']
@ -292,49 +292,49 @@ class account_coda_import(osv.osv_memory):
if trans_category: if trans_category:
st_line['trans_category_desc'] = trans_category[0]['description'] st_line['trans_category_desc'] = trans_category[0]['description']
else: else:
st_line['trans_category_desc'] = _('Transaction Category unknown, please consult your bank.') st_line['trans_category_desc'] = _('Transaction Category unknown, please consult your bank.')
# positions 61-115 : communication # positions 61-115 : communication
if line[61] == '1': if line[61] == '1':
st_line['struct_comm_type'] = line[62:65] st_line['struct_comm_type'] = line[62:65]
comm_type = filter(lambda x: st_line['struct_comm_type'] == x['code'], comm_type_table) comm_type = filter(lambda x: st_line['struct_comm_type'] == x['code'], comm_type_table)
if not comm_type: if not comm_type:
err_string = _('\nThe File contains an invalid Structured Communication Type : %s!') % st_line['struct_comm_type'] err_string = _('\nThe File contains an invalid Structured Communication Type : %s.') % st_line['struct_comm_type']
err_code = 'R2003' err_code = 'R2003'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
st_line['struct_comm_type_desc'] = comm_type[0]['description'] st_line['struct_comm_type_desc'] = comm_type[0]['description']
st_line['communication'] = st_line['name'] = line[65:115] st_line['communication'] = st_line['name'] = line[65:115]
if st_line['struct_comm_type'] == '101': if st_line['struct_comm_type'] == '101':
bbacomm = line[65:77] bbacomm = line[65:77]
st_line['struct_comm_101'] = st_line['name'] = '+++' + bbacomm[0:3] + '/' + bbacomm[3:7] + '/' + bbacomm[7:] + '+++' st_line['struct_comm_101'] = st_line['name'] = '+++' + bbacomm[0:3] + '/' + bbacomm[3:7] + '/' + bbacomm[7:] + '+++'
else: else:
st_line['communication'] = st_line['name'] = line[62:115] st_line['communication'] = st_line['name'] = line[62:115]
st_line['entry_date'] = str2date(line[115:121]) st_line['entry_date'] = str2date(line[115:121])
# positions 122-124 not processed # positions 122-124 not processed
coda_statement_lines[st_line_seq] = st_line coda_statement_lines[st_line_seq] = st_line
coda_statement['coda_statement_lines'] = coda_statement_lines coda_statement['coda_statement_lines'] = coda_statement_lines
elif line[1] == '2': elif line[1] == '2':
# movement data record 2.2 # movement data record 2.2
if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]: if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]:
err_string = _('\nCODA parsing error on movement data record 2.2, seq nr %s!' \ err_string = _('\nCODA parsing error on movement data record 2.2, seq nr %s.' \
'\nPlease report this issue via your OpenERP support channel.') % line[2:10] '\nPlease report this issue via your OpenERP support channel.') % line[2:10]
err_code = 'R2004' err_code = 'R2004'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Error!'), err_string) raise osv.except_osv(_('Error!'), err_string)
coda_statement['coda_statement_lines'][st_line_seq]['name'] += line[10:63] coda_statement['coda_statement_lines'][st_line_seq]['name'] += line[10:63]
coda_statement['coda_statement_lines'][st_line_seq]['communication'] += line[10:63] coda_statement['coda_statement_lines'][st_line_seq]['communication'] += line[10:63]
coda_statement['coda_statement_lines'][st_line_seq]['counterparty_bic'] = line[98:109].strip() coda_statement['coda_statement_lines'][st_line_seq]['counterparty_bic'] = line[98:109].strip()
elif line[1] == '3': elif line[1] == '3':
# movement data record 2.3 # movement data record 2.3
if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]: if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]:
err_string = _('\nCODA parsing error on movement data record 2.3, seq nr %s!' \ err_string = _('\nCODA parsing error on movement data record 2.3, seq nr %s.' \
'\nPlease report this issue via your OpenERP support channel.') % line[2:10] '\nPlease report this issue via your OpenERP support channel.') % line[2:10]
err_code = 'R2005' err_code = 'R2005'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Error!'), err_string) raise osv.except_osv(_('Error!'), err_string)
st_line = coda_statement_lines[st_line_seq] st_line = coda_statement_lines[st_line_seq]
if coda_version == '1': if coda_version == '1':
counterparty_number = line[10:22] counterparty_number = line[10:22]
@ -346,7 +346,7 @@ class account_coda_import(osv.osv_memory):
counterparty_currency = line[23:26].strip() counterparty_currency = line[23:26].strip()
else: else:
counterparty_number = line[10:44].strip() counterparty_number = line[10:44].strip()
counterparty_currency = line[44:47].strip() counterparty_currency = line[44:47].strip()
counterparty_name = line[47:82].strip() counterparty_name = line[47:82].strip()
st_line['name'] += line[82:125] st_line['name'] += line[82:125]
st_line['communication'] += line[82:125] st_line['communication'] += line[82:125]
@ -354,15 +354,15 @@ class account_coda_import(osv.osv_memory):
st_line['counterparty_currency'] = counterparty_currency st_line['counterparty_currency'] = counterparty_currency
st_line['counterparty_name'] = counterparty_name st_line['counterparty_name'] = counterparty_name
if counterparty_currency not in [coda_bank['currency_name'], '']: if counterparty_currency not in [coda_bank['currency_name'], '']:
err_string = _('\nCODA parsing error on movement data record 2.3, seq nr %s!' \ err_string = _('\nCODA parsing error on movement data record 2.3, seq nr %s.' \
'\nPlease report this issue via your OpenERP support channel.') % line[2:10] '\nPlease report this issue via your OpenERP support channel.') % line[2:10]
err_code = 'R2006' err_code = 'R2006'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Error!'), err_string) raise osv.except_osv(_('Error!'), err_string)
# partner matching and reconciliation # partner matching and reconciliation
if st_line['type'] == 'general': if st_line['type'] == 'general':
match = False match = False
bank_ids = False bank_ids = False
# prepare reconciliation for bba scor # prepare reconciliation for bba scor
@ -379,14 +379,14 @@ class account_coda_import(osv.osv_memory):
else: else:
st_line['account_id'] = partner.property_account_receivable.id or def_rec_acc st_line['account_id'] = partner.property_account_receivable.id or def_rec_acc
st_line['type'] = 'customer' st_line['type'] = 'customer'
if invoice.type in ['in_invoice', 'out_invoice']: if invoice.type in ['in_invoice', 'out_invoice']:
iml_ids = move_line_obj.search(cr, uid, [('move_id', '=', invoice.move_id.id), ('reconcile_id', '=', False), ('account_id.reconcile', '=', True)]) iml_ids = move_line_obj.search(cr, uid, [('move_id', '=', invoice.move_id.id), ('reconcile_id', '=', False), ('account_id.reconcile', '=', True)])
if iml_ids: if iml_ids:
st_line['reconcile'] = iml_ids[0] st_line['reconcile'] = iml_ids[0]
match = True match = True
else: else:
coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \ coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \
"\n There is no invoice matching the Structured Communication '%s'!" \ "\n There is no invoice matching the Structured Communication '%s'." \
"\n Please verify and adjust the invoice and perform the import again or otherwise change the corresponding entry manually in the generated Bank Statement.") \ "\n Please verify and adjust the invoice and perform the import again or otherwise change the corresponding entry manually in the generated Bank Statement.") \
% (coda_statement['name'], st_line['ref'], reference) % (coda_statement['name'], st_line['ref'], reference)
# lookup partner via counterparty_number # lookup partner via counterparty_number
@ -402,10 +402,10 @@ class account_coda_import(osv.osv_memory):
if not match and find_partner and bank_ids: if not match and find_partner and bank_ids:
if len(bank_ids) > 1: if len(bank_ids) > 1:
coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \ coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \
"\n No partner record assigned: There are multiple partners with the same Bank Account Number '%s'!" \ "\n No partner record assigned: There are multiple partners with the same Bank Account Number '%s'." \
"\n Please correct the configuration and perform the import again or otherwise change the corresponding entry manually in the generated Bank Statement.") \ "\n Please correct the configuration and perform the import again or otherwise change the corresponding entry manually in the generated Bank Statement.") \
% (coda_statement['name'], st_line['ref'], counterparty_number) % (coda_statement['name'], st_line['ref'], counterparty_number)
else: else:
bank = partner_bank_obj.browse(cr, uid, bank_ids[0], context) bank = partner_bank_obj.browse(cr, uid, bank_ids[0], context)
st_line['partner_id'] = bank.partner_id.id st_line['partner_id'] = bank.partner_id.id
match = True match = True
@ -418,26 +418,26 @@ class account_coda_import(osv.osv_memory):
elif not match and find_partner: elif not match and find_partner:
if counterparty_number: if counterparty_number:
coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \ coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \
"\n The bank account '%s' is not defined for the partner '%s'!" \ "\n The bank account '%s' is not defined for the partner '%s'." \
"\n Please correct the configuration and perform the import again or otherwise change the corresponding entry manually in the generated Bank Statement.") \ "\n Please correct the configuration and perform the import again or otherwise change the corresponding entry manually in the generated Bank Statement.") \
% (coda_statement['name'], st_line['ref'], % (coda_statement['name'], st_line['ref'],
counterparty_number, counterparty_name) counterparty_number, counterparty_name)
else: else:
coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \ coda_parsing_note += _("\n Bank Statement '%s' line '%s':" \
"\n No matching partner record found!" \ "\n No matching partner record found." \
"\n Please adjust the corresponding entry manually in the generated Bank Statement.") \ "\n Please adjust the corresponding entry manually in the generated Bank Statement.") \
% (coda_statement['name'], st_line['ref']) % (coda_statement['name'], st_line['ref'])
st_line['account_id'] = awaiting_acc st_line['account_id'] = awaiting_acc
# end of partner record lookup # end of partner record lookup
coda_statement_lines[st_line_seq] = st_line coda_statement_lines[st_line_seq] = st_line
coda_statement['coda_statement_lines'] = coda_statement_lines coda_statement['coda_statement_lines'] = coda_statement_lines
else: else:
# movement data record 2.x (x <> 1,2,3) # movement data record 2.x (x <> 1,2,3)
err_string = _('\nMovement data records of type 2.%s are not supported !') % line[1] err_string = _('\nMovement data records of type 2.%s are not supported.') % line[1]
err_code = 'R2007' err_code = 'R2007'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
elif line[0] == '3': elif line[0] == '3':
# information data record 3 # information data record 3
@ -461,19 +461,19 @@ class account_coda_import(osv.osv_memory):
err_code = 'R3001' err_code = 'R3001'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
info_line['trans_type_desc'] = trans_type[0]['description'] info_line['trans_type_desc'] = trans_type[0]['description']
info_line['trans_family'] = line[32:34] info_line['trans_family'] = line[32:34]
trans_family = filter(lambda x: (x['type'] == 'family') and (info_line['trans_family'] == x['code']), trans_code_table) trans_family = filter(lambda x: (x['type'] == 'family') and (info_line['trans_family'] == x['code']), trans_code_table)
if not trans_family: if not trans_family:
err_string = _('\nThe File contains an invalid CODA Transaction Family : %s!') % st_line['trans_family'] err_string = _('\nThe File contains an invalid CODA Transaction Family : %s.') % st_line['trans_family']
err_code = 'R3002' err_code = 'R3002'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Data Error!'), err_string) raise osv.except_osv(_('Data Error!'), err_string)
info_line['trans_family_desc'] = trans_family[0]['description'] info_line['trans_family_desc'] = trans_family[0]['description']
info_line['trans_code'] = line[34:36] info_line['trans_code'] = line[34:36]
trans_code = filter(lambda x: (x['type'] == 'code') and (info_line['trans_code'] == x['code']) and (trans_family[0]['id'] == x['parent_id']), trans_code = filter(lambda x: (x['type'] == 'code') and (info_line['trans_code'] == x['code']) and (trans_family[0]['id'] == x['parent_id']),
trans_code_table) trans_code_table)
if trans_code: if trans_code:
info_line['trans_code_desc'] = trans_code[0]['description'] info_line['trans_code_desc'] = trans_code[0]['description']
@ -484,13 +484,13 @@ class account_coda_import(osv.osv_memory):
if trans_category: if trans_category:
info_line['trans_category_desc'] = trans_category[0]['description'] info_line['trans_category_desc'] = trans_category[0]['description']
else: else:
info_line['trans_category_desc'] = _('Transaction Category unknown, please consult your bank.') info_line['trans_category_desc'] = _('Transaction Category unknown, please consult your bank.')
# positions 40-113 : communication # positions 40-113 : communication
if line[39] == '1': if line[39] == '1':
info_line['struct_comm_type'] = line[40:43] info_line['struct_comm_type'] = line[40:43]
comm_type = filter(lambda x: info_line['struct_comm_type'] == x['code'], comm_type_table) comm_type = filter(lambda x: info_line['struct_comm_type'] == x['code'], comm_type_table)
if not comm_type: if not comm_type:
err_string = _('\nThe File contains an invalid Structured Communication Type : %s!') % info_line['struct_comm_type'] err_string = _('\nThe File contains an invalid Structured Communication Type : %s.') % info_line['struct_comm_type']
err_code = 'R3003' err_code = 'R3003'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
@ -505,18 +505,18 @@ class account_coda_import(osv.osv_memory):
elif line[1] == '2': elif line[1] == '2':
# information data record 3.2 # information data record 3.2
if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]: if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]:
err_string = _('\nCODA parsing error on information data record 3.2, seq nr %s!' \ err_string = _('\nCODA parsing error on information data record 3.2, seq nr %s.' \
'\nPlease report this issue via your OpenERP support channel.') % line[2:10] '\nPlease report this issue via your OpenERP support channel.') % line[2:10]
err_code = 'R3004' err_code = 'R3004'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('Error!'), err_string) raise osv.except_osv(_('Error!'), err_string)
coda_statement['coda_statement_lines'][st_line_seq]['name'] += line[10:115] coda_statement['coda_statement_lines'][st_line_seq]['name'] += line[10:115]
coda_statement['coda_statement_lines'][st_line_seq]['communication'] += line[10:115] coda_statement['coda_statement_lines'][st_line_seq]['communication'] += line[10:115]
elif line[1] == '3': elif line[1] == '3':
# information data record 3.3 # information data record 3.3
if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]: if coda_statement['coda_statement_lines'][st_line_seq]['ref'] != line[2:10]:
err_string = _('\nCODA parsing error on information data record 3.3, seq nr %s!' \ err_string = _('\nCODA parsing error on information data record 3.3, seq nr %s.' \
'\nPlease report this issue via your OpenERP support channel.') % line[2:10] '\nPlease report this issue via your OpenERP support channel.') % line[2:10]
err_code = 'R3005' err_code = 'R3005'
if batch: if batch:
@ -524,7 +524,7 @@ class account_coda_import(osv.osv_memory):
raise osv.except_osv(_('Error!'), err_string) raise osv.except_osv(_('Error!'), err_string)
coda_statement['coda_statement_lines'][st_line_seq]['name'] += line[10:100] coda_statement['coda_statement_lines'][st_line_seq]['name'] += line[10:100]
coda_statement['coda_statement_lines'][st_line_seq]['communication'] += line[10:100] coda_statement['coda_statement_lines'][st_line_seq]['communication'] += line[10:100]
elif line[0] == '4': elif line[0] == '4':
# free communication data record 4 # free communication data record 4
comm_line = {} comm_line = {}
@ -535,21 +535,21 @@ class account_coda_import(osv.osv_memory):
comm_line['communication'] = comm_line['name'] = line[32:112] comm_line['communication'] = comm_line['name'] = line[32:112]
coda_statement_lines[st_line_seq] = comm_line coda_statement_lines[st_line_seq] = comm_line
coda_statement['coda_statement_lines'] = coda_statement_lines coda_statement['coda_statement_lines'] = coda_statement_lines
elif line[0] == '8': elif line[0] == '8':
# new balance record # new balance record
bal_end = list2float(line[42:57]) bal_end = list2float(line[42:57])
if line[41] == '1': # 1=Debit if line[41] == '1': # 1=Debit
bal_end = - bal_end bal_end = - bal_end
coda_statement['balance_end_real'] = bal_end coda_statement['balance_end_real'] = bal_end
elif line[0] == '9': elif line[0] == '9':
# footer record # footer record
coda_statement['balance_min'] = list2float(line[22:37]) coda_statement['balance_min'] = list2float(line[22:37])
coda_statement['balance_plus'] = list2float(line[37:52]) coda_statement['balance_plus'] = list2float(line[37:52])
if not bal_end: if not bal_end:
coda_statement['balance_end_real'] = coda_statement['balance_start'] + coda_statement['balance_plus'] - coda_statement['balance_min'] coda_statement['balance_end_real'] = coda_statement['balance_start'] + coda_statement['balance_plus'] - coda_statement['balance_min']
if coda_parsing_note: if coda_parsing_note:
coda_statement['coda_parsing_note'] = '\nStatement Line matching results:' + coda_parsing_note coda_statement['coda_parsing_note'] = '\nStatement Line matching results:' + coda_parsing_note
else: else:
coda_statement['coda_parsing_note'] = '' coda_statement['coda_parsing_note'] = ''
@ -557,11 +557,11 @@ class account_coda_import(osv.osv_memory):
#end for #end for
err_string = '' err_string = ''
err_code = '' err_code = ''
coda_id = 0 coda_id = 0
coda_note = '' coda_note = ''
line_note = '' line_note = ''
try: try:
coda_id = coda_obj.create(cr, uid,{ coda_id = coda_obj.create(cr, uid,{
'name' : codafilename, 'name' : codafilename,
@ -571,7 +571,7 @@ class account_coda_import(osv.osv_memory):
'user_id': uid, 'user_id': uid,
}) })
context.update({'coda_id': coda_id}) context.update({'coda_id': coda_id})
except osv.except_osv, e: except osv.except_osv, e:
cr.rollback() cr.rollback()
err_string = _('\nApplication Error : ') + str(e) err_string = _('\nApplication Error : ') + str(e)
@ -585,24 +585,24 @@ class account_coda_import(osv.osv_memory):
err_code = 'G0001' err_code = 'G0001'
if batch: if batch:
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('CODA Import failed !'), err_string) raise osv.except_osv(_('CODA Import failed.'), err_string)
nb_err = 0 nb_err = 0
err_string = '' err_string = ''
coda_st_ids = [] coda_st_ids = []
bk_st_ids = [] bk_st_ids = []
for statement in coda_statements: for statement in coda_statements:
# The CODA Statement info is written to two objects: 'coda.bank.statement' and 'account.bank.statement' # The CODA Statement info is written to two objects: 'coda.bank.statement' and 'account.bank.statement'
try: try:
coda_st_id = coda_st_obj.create(cr, uid, { coda_st_id = coda_st_obj.create(cr, uid, {
'name': statement['name'], 'name': statement['name'],
'type': statement['type'], 'type': statement['type'],
'coda_bank_account_id': statement['coda_bank_account_id'], 'coda_bank_account_id': statement['coda_bank_account_id'],
'currency': statement['currency_id'], 'currency': statement['currency_id'],
'journal_id': statement['journal_id'], 'journal_id': statement['journal_id'],
'coda_id': coda_id, 'coda_id': coda_id,
'date': statement['date'], 'date': statement['date'],
@ -613,7 +613,7 @@ class account_coda_import(osv.osv_memory):
}) })
coda_st_ids.append(coda_st_id) coda_st_ids.append(coda_st_id)
if statement['type'] == 'normal': if statement['type'] == 'normal':
context.update({'ebanking_import': 1}) context.update({'ebanking_import': 1})
journal = journal_obj.browse(cr, uid, statement['journal_id'], context=context) journal = journal_obj.browse(cr, uid, statement['journal_id'], context=context)
cr.execute('SELECT balance_end_real \ cr.execute('SELECT balance_end_real \
@ -626,16 +626,15 @@ class account_coda_import(osv.osv_memory):
if journal.default_debit_account_id and (journal.default_credit_account_id == journal.default_debit_account_id): if journal.default_debit_account_id and (journal.default_credit_account_id == journal.default_debit_account_id):
balance_start_check = journal.default_debit_account_id.balance balance_start_check = journal.default_debit_account_id.balance
else: else:
nb_err += 1 nb_err += 1
err_string += _('\nConfiguration Error in journal %s!' \ err_string += _('\nConfiguration Error!\nPlease verify the Default Debit and Credit Account settings in journal %s.') % journal.name
'\nPlease verify the Default Debit and Credit Account settings.') % journal.name
break break
if balance_start_check <> statement['balance_start']: if balance_start_check <> statement['balance_start']:
nb_err += 1 nb_err += 1
err_string += _('\nThe CODA Statement %s Starting Balance (%.2f) does not correspond with the previous Closing Balance (%.2f) in journal %s!') \ err_string += _('\nThe CODA Statement %s Starting Balance (%.2f) does not correspond with the previous Closing Balance (%.2f) in journal %s.') \
% (statement['name'], statement['balance_start'], balance_start_check, journal.name) % (statement['name'], statement['balance_start'], balance_start_check, journal.name)
break break
bk_st_id = bank_st_obj.create(cr, uid, { bk_st_id = bank_st_obj.create(cr, uid, {
'name': statement['name'], 'name': statement['name'],
'journal_id': statement['journal_id'], 'journal_id': statement['journal_id'],
@ -648,7 +647,7 @@ class account_coda_import(osv.osv_memory):
}) })
bk_st_ids.append(bk_st_id) bk_st_ids.append(bk_st_id)
coda_st_obj.write(cr, uid, [coda_st_id], {'statement_id': bk_st_id}, context=context) coda_st_obj.write(cr, uid, [coda_st_id], {'statement_id': bk_st_id}, context=context)
glob_id_stack = [(0, '', 0, '')] # stack with tuples (glob_lvl_flag, glob_code, glob_id, glob_name) glob_id_stack = [(0, '', 0, '')] # stack with tuples (glob_lvl_flag, glob_code, glob_id, glob_name)
lines = statement['coda_statement_lines'] lines = statement['coda_statement_lines']
st_line_seq = 0 st_line_seq = 0
@ -657,7 +656,7 @@ class account_coda_import(osv.osv_memory):
line = lines[x] line = lines[x]
# handling non-transactional records : line['type'] in ['information', 'communication'] # handling non-transactional records : line['type'] in ['information', 'communication']
if line['type'] == 'information': if line['type'] == 'information':
line['globalisation_id'] = glob_id_stack[-1][2] line['globalisation_id'] = glob_id_stack[-1][2]
@ -673,25 +672,25 @@ class account_coda_import(osv.osv_memory):
line['trans_category'], line['trans_category_desc'], line['trans_category'], line['trans_category_desc'],
line['struct_comm_type'], line['struct_comm_type_desc'], line['struct_comm_type'], line['struct_comm_type_desc'],
line['communication']) line['communication'])
coda_st_line_id = coda_st_line_obj.create(cr, uid, { coda_st_line_id = coda_st_line_obj.create(cr, uid, {
'sequence': line['sequence'], 'sequence': line['sequence'],
'ref': line['ref'], 'ref': line['ref'],
'name': line['name'].strip() or '/', 'name': line['name'].strip() or '/',
'type' : 'information', 'type' : 'information',
'date': line['entry_date'], 'date': line['entry_date'],
'statement_id': coda_st_id, 'statement_id': coda_st_id,
'note': line_note, 'note': line_note,
}) })
elif line['type'] == 'communication': elif line['type'] == 'communication':
line_note = _('Free Communication:\n %s') \ line_note = _('Free Communication:\n %s') \
%(line['communication']) %(line['communication'])
coda_st_line_id = coda_st_line_obj.create(cr, uid, { coda_st_line_id = coda_st_line_obj.create(cr, uid, {
'sequence': line['sequence'], 'sequence': line['sequence'],
'ref': line['ref'], 'ref': line['ref'],
'name': line['name'].strip() or '/', 'name': line['name'].strip() or '/',
'type' : 'communication', 'type' : 'communication',
'date': statement['date'], 'date': statement['date'],
@ -699,20 +698,20 @@ class account_coda_import(osv.osv_memory):
'note': line_note, 'note': line_note,
}) })
# handling transactional records, # line['type'] in ['globalisation', 'general', 'supplier', 'customer'] # handling transactional records, # line['type'] in ['globalisation', 'general', 'supplier', 'customer']
else: else:
glob_lvl_flag = line['glob_lvl_flag'] glob_lvl_flag = line['glob_lvl_flag']
if glob_lvl_flag: if glob_lvl_flag:
if glob_id_stack[-1][0] == glob_lvl_flag: if glob_id_stack[-1][0] == glob_lvl_flag:
line['globalisation_id'] = glob_id_stack[-1][2] line['globalisation_id'] = glob_id_stack[-1][2]
glob_id_stack.pop() glob_id_stack.pop()
else: else:
glob_name = line['name'].strip() or '/' glob_name = line['name'].strip() or '/'
glob_code = seq_obj.get(cr, uid, 'statement.line.global') glob_code = seq_obj.get(cr, uid, 'statement.line.global')
glob_id = glob_obj.create(cr, uid, { glob_id = glob_obj.create(cr, uid, {
'code': glob_code, 'code': glob_code,
'name': glob_name, 'name': glob_name,
'type': 'coda', 'type': 'coda',
'parent_id': glob_id_stack[-1][2], 'parent_id': glob_id_stack[-1][2],
@ -720,7 +719,7 @@ class account_coda_import(osv.osv_memory):
}) })
line['globalisation_id'] = glob_id line['globalisation_id'] = glob_id
glob_id_stack.append((glob_lvl_flag, glob_code, glob_id, glob_name)) glob_id_stack.append((glob_lvl_flag, glob_code, glob_id, glob_name))
line_note = _('Partner name: %s \nPartner Account Number: %s' \ line_note = _('Partner name: %s \nPartner Account Number: %s' \
'\nTransaction Type: %s - %s' \ '\nTransaction Type: %s - %s' \
'\nTransaction Family: %s - %s' \ '\nTransaction Family: %s - %s' \
@ -735,54 +734,54 @@ class account_coda_import(osv.osv_memory):
line['trans_category'], line['trans_category_desc'], line['trans_category'], line['trans_category_desc'],
line['struct_comm_type'], line['struct_comm_type_desc'], line['struct_comm_type'], line['struct_comm_type_desc'],
line['communication']) line['communication'])
if line['type'] == 'globalisation': if line['type'] == 'globalisation':
coda_st_line_id = coda_st_line_obj.create(cr, uid, { coda_st_line_id = coda_st_line_obj.create(cr, uid, {
'sequence': line['sequence'], 'sequence': line['sequence'],
'ref': line['ref'], 'ref': line['ref'],
'name': line['name'].strip() or '/', 'name': line['name'].strip() or '/',
'type' : 'globalisation', 'type' : 'globalisation',
'val_date' : line['val_date'], 'val_date' : line['val_date'],
'date': line['entry_date'], 'date': line['entry_date'],
'globalisation_level': line['glob_lvl_flag'], 'globalisation_level': line['glob_lvl_flag'],
'globalisation_amount': line['globalisation_amount'], 'globalisation_amount': line['globalisation_amount'],
'globalisation_id': line['globalisation_id'], 'globalisation_id': line['globalisation_id'],
'partner_id': line['partner_id'] or 0, 'partner_id': line['partner_id'] or 0,
'account_id': line['account_id'], 'account_id': line['account_id'],
'statement_id': coda_st_id, 'statement_id': coda_st_id,
'note': line_note, 'note': line_note,
}) })
else: # line['type'] in ['general', 'supplier', 'customer'] else: # line['type'] in ['general', 'supplier', 'customer']
if glob_lvl_flag == 0: if glob_lvl_flag == 0:
line['globalisation_id'] = glob_id_stack[-1][2] line['globalisation_id'] = glob_id_stack[-1][2]
if not line['account_id']: if not line['account_id']:
line['account_id'] = awaiting_acc line['account_id'] = awaiting_acc
coda_st_line_id = coda_st_line_obj.create(cr, uid, { coda_st_line_id = coda_st_line_obj.create(cr, uid, {
'sequence': line['sequence'], 'sequence': line['sequence'],
'ref': line['ref'], 'ref': line['ref'],
'name': line['name'] or '/', 'name': line['name'] or '/',
'type' : line['type'], 'type' : line['type'],
'val_date' : line['val_date'], 'val_date' : line['val_date'],
'date': line['entry_date'], 'date': line['entry_date'],
'amount': line['amount'], 'amount': line['amount'],
'partner_id': line['partner_id'] or 0, 'partner_id': line['partner_id'] or 0,
'counterparty_name': line['counterparty_name'], 'counterparty_name': line['counterparty_name'],
'counterparty_bic': line['counterparty_bic'], 'counterparty_bic': line['counterparty_bic'],
'counterparty_number': line['counterparty_number'], 'counterparty_number': line['counterparty_number'],
'counterparty_currency': line['counterparty_currency'], 'counterparty_currency': line['counterparty_currency'],
'account_id': line['account_id'], 'account_id': line['account_id'],
'globalisation_level': line['glob_lvl_flag'], 'globalisation_level': line['glob_lvl_flag'],
'globalisation_id': line['globalisation_id'], 'globalisation_id': line['globalisation_id'],
'statement_id': coda_st_id, 'statement_id': coda_st_id,
'note': line_note, 'note': line_note,
}) })
if statement['type'] == 'normal': if statement['type'] == 'normal':
st_line_seq += 1 st_line_seq += 1
voucher_id = False voucher_id = False
line_name = line['name'].strip() line_name = line['name'].strip()
@ -793,7 +792,7 @@ class account_coda_import(osv.osv_memory):
line_name = '/' line_name = '/'
if line['reconcile']: if line['reconcile']:
voucher_vals = { voucher_vals = {
'type': line['type'] == 'supplier' and 'payment' or 'receipt', 'type': line['type'] == 'supplier' and 'payment' or 'receipt',
'name': line_name, 'name': line_name,
'partner_id': line['partner_id'], 'partner_id': line['partner_id'],
@ -808,15 +807,15 @@ class account_coda_import(osv.osv_memory):
voucher_id = voucher_obj.create(cr, uid, voucher_vals, context=context) voucher_id = voucher_obj.create(cr, uid, voucher_vals, context=context)
move_line = move_line_obj.browse(cr, uid, line['reconcile'], context=context) move_line = move_line_obj.browse(cr, uid, line['reconcile'], context=context)
voucher_dict = voucher_obj.onchange_partner_id(cr, uid, [], voucher_dict = voucher_obj.onchange_partner_id(cr, uid, [],
partner_id = line['partner_id'], partner_id = line['partner_id'],
journal_id = statement['journal_id'], journal_id = statement['journal_id'],
price = abs(line['amount']), price = abs(line['amount']),
currency_id = journal.company_id.currency_id.id, currency_id = journal.company_id.currency_id.id,
ttype = line['type'] == 'supplier' and 'payment' or 'receipt', ttype = line['type'] == 'supplier' and 'payment' or 'receipt',
date = line['val_date'], date = line['val_date'],
context = context) context = context)
#_logger.warning('voucher_dict = %s' % voucher_dict) #_logger.warning('voucher_dict = %s' % voucher_dict)
voucher_line_vals = False voucher_line_vals = False
if voucher_dict['value']['line_ids']: if voucher_dict['value']['line_ids']:
for line_dict in voucher_dict['value']['line_ids']: for line_dict in voucher_dict['value']['line_ids']:
@ -831,38 +830,38 @@ class account_coda_import(osv.osv_memory):
bank_st_line_id = bank_st_line_obj.create(cr, uid, { bank_st_line_id = bank_st_line_obj.create(cr, uid, {
'sequence': st_line_seq, 'sequence': st_line_seq,
'ref': line['ref'], 'ref': line['ref'],
'name': line_name, 'name': line_name,
'type' : line['type'], 'type' : line['type'],
'val_date' : line['val_date'], 'val_date' : line['val_date'],
'date': line['entry_date'], 'date': line['entry_date'],
'amount': line['amount'], 'amount': line['amount'],
'partner_id': line['partner_id'] or 0, 'partner_id': line['partner_id'] or 0,
'counterparty_name': line['counterparty_name'], 'counterparty_name': line['counterparty_name'],
'counterparty_bic': line['counterparty_bic'], 'counterparty_bic': line['counterparty_bic'],
'counterparty_number': line['counterparty_number'], 'counterparty_number': line['counterparty_number'],
'counterparty_currency': line['counterparty_currency'], 'counterparty_currency': line['counterparty_currency'],
'account_id': line['account_id'], 'account_id': line['account_id'],
'globalisation_id': line['globalisation_id'], 'globalisation_id': line['globalisation_id'],
'statement_id': bk_st_id, 'statement_id': bk_st_id,
'voucher_id': voucher_id, 'voucher_id': voucher_id,
'note': line_note, 'note': line_note,
}) })
# end 'for x in lines' # end 'for x in lines'
coda_st_obj.write(cr, uid, [coda_st_id], {}, context=context) # calculate balance coda_st_obj.write(cr, uid, [coda_st_id], {}, context=context) # calculate balance
st_balance = coda_st_obj.read(cr, uid, coda_st_id, ['balance_end', 'balance_end_real'], context=context) st_balance = coda_st_obj.read(cr, uid, coda_st_id, ['balance_end', 'balance_end_real'], context=context)
if st_balance['balance_end'] <> st_balance['balance_end_real']: if st_balance['balance_end'] <> st_balance['balance_end_real']:
err_string += _('\nIncorrect ending Balance in CODA Statement %s for Bank Account %s!') \ err_string += _('\nIncorrect ending Balance in CODA Statement %s for Bank Account %s.') \
% (statement['coda_seq_number'], (statement['acc_number'] + ' (' + statement['currency'] + ') - ' + statement['description'])) % (statement['coda_seq_number'], (statement['acc_number'] + ' (' + statement['currency'] + ') - ' + statement['description']))
if statement['type'] == 'normal': if statement['type'] == 'normal':
nb_err += 1 nb_err += 1
break break
else: else:
statement['coda_parsing_note'] += '\n' + err_string statement['coda_parsing_note'] += '\n' + err_string
if statement['type'] == 'normal': if statement['type'] == 'normal':
bank_st_obj.button_dummy(cr, uid, [bk_st_id], context=context) # calculate balance bank_st_obj.button_dummy(cr, uid, [bk_st_id], context=context) # calculate balance
journal_name = journal.name journal_name = journal.name
else: else:
journal_name = _('None') journal_name = _('None')
@ -904,7 +903,7 @@ class account_coda_import(osv.osv_memory):
_logger.error('Unknown Error while processing Statement %s\n%s' % (statement.get('name', '/'),tb)) _logger.error('Unknown Error while processing Statement %s\n%s' % (statement.get('name', '/'),tb))
# end 'for statement in coda_statements' # end 'for statement in coda_statements'
coda_note_header = _('CODA File is Imported :') coda_note_header = _('CODA File is Imported :')
coda_note_footer = _('\n\nNumber of statements : ') + str(len(coda_st_ids)) coda_note_footer = _('\n\nNumber of statements : ') + str(len(coda_st_ids))
err_log = err_log + _('\nNumber of errors : ') + str(nb_err) + '\n' err_log = err_log + _('\nNumber of errors : ') + str(nb_err) + '\n'
@ -920,13 +919,13 @@ class account_coda_import(osv.osv_memory):
if batch: if batch:
err_code = 'G0002' err_code = 'G0002'
return (err_code, err_string) return (err_code, err_string)
raise osv.except_osv(_('CODA Import failed !'), err_string) raise osv.except_osv(_('CODA Import failed.'), err_string)
context.update({ 'bk_st_ids': bk_st_ids}) context.update({ 'bk_st_ids': bk_st_ids})
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'account_coda_import_result_view')], context=context) model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'account_coda_import_result_view')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
self.write(cr, uid, ids, {'note': note}, context=context) self.write(cr, uid, ids, {'note': note}, context=context)
return { return {
'name': _('Import CODA File result'), 'name': _('Import CODA File result'),
'res_id': ids[0], 'res_id': ids[0],
@ -961,7 +960,7 @@ class account_coda_import(osv.osv_memory):
domain += [('id','in', context.get('bk_st_ids', False))] domain += [('id','in', context.get('bk_st_ids', False))]
action.update({'domain': domain}) action.update({'domain': domain})
return action return action
account_coda_import() account_coda_import()
def str2date(date_str): def str2date(date_str):