Merge lp:~openerp-commiter/openobject-addons/trunk-impoer_coda_error into lp:~openerp-dev/openobject-addons/trunk-bugfixes-Ind

Proposed by Ashvin Rathod (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-commiter/openobject-addons/trunk-impoer_coda_error
Merge into: lp:~openerp-dev/openobject-addons/trunk-bugfixes-Ind
Diff against target: 209 lines (+100/-97)
1 file modified
account_coda/wizard/account_coda_import.py (+100/-97)
To merge this branch: bzr merge lp:~openerp-commiter/openobject-addons/trunk-impoer_coda_error
Reviewer Review Type Date Requested Status
Mustufa Rangwala (Open ERP) Needs Fixing
Purnendu Singh (OpenERP) Pending
Review via email: mp+62452@code.launchpad.net

Description of the change

Hello,

Fix: error occurs when import instead of coda file(txt).

Thanks,
ara

To post a comment you must log in.
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

Seems not good try and except.
I think you should put try and except at proper place or you can use except Exception,e ..

Thanks,
mra

review: Needs Fixing

Unmerged revisions

4694. By Ashvin Rathod (OpenERP)

[FIX] account_coda: rror occurs when import instead of coda file(txt).

4693. By Naresh(OpenERP)

[MERGE FROM TRUNK]

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_coda/wizard/account_coda_import.py'
2--- account_coda/wizard/account_coda_import.py 2011-03-14 10:27:42 +0000
3+++ account_coda/wizard/account_coda_import.py 2011-05-26 10:37:27 +0000
4@@ -90,105 +90,108 @@
5 recordlist = base64.decodestring(codafile).split('\n')
6 recordlist.pop()
7 for line in recordlist:
8- if line[0] == '0':
9- # header data
10-
11- bank_statement["bank_statement_line"]={}
12- bank_statement_lines = {}
13- bank_statement['date'] = str2date(line[5:11])
14- bank_statement['journal_id']=data.journal_id.id
15- period_id = account_period_obj.search(cr, uid, [('date_start', '<=', time.strftime('%Y-%m-%d', time.strptime(bank_statement['date'], "%y/%m/%d"))), ('date_stop', '>=', time.strftime('%Y-%m-%d', time.strptime(bank_statement['date'], "%y/%m/%d")))])
16- bank_statement['period_id'] = period_id and period_id[0] or False
17- bank_statement['state']='draft'
18- elif line[0] == '1':
19- # old balance data
20- bal_start = list2float(line[43:58])
21- if line[42] == '1':
22- bal_start = - bal_start
23- bank_statement["balance_start"]= bal_start
24- bank_statement["acc_number"]=line[5:17]
25- bank_statement["acc_holder"]=line[64:90]
26- bank_statement['name'] = journal_code + ' ' + str(line[2:5])
27-
28- elif line[0]=='2':
29- # movement data record 2
30- if line[1]=='1':
31- # movement data record 2.1
32- if bank_statement_lines.has_key(line[2:6]):
33- continue
34- st_line = {}
35- st_line['extra_note'] = ''
36- st_line['statement_id']=0
37- st_line['ref'] = line[2:10]
38- st_line['date'] = time.strftime('%Y-%m-%d', time.strptime(str2date(line[115:121]), "%y/%m/%d")),
39- st_line_amt = list2float(line[32:47])
40-
41- if line[61]=='1':
42- st_line['toreconcile'] = True
43- st_line['name']=line[65:77]
44- else:
45- st_line['toreconcile'] = False
46- st_line['name']=line[62:115]
47-
48- st_line['free_comm'] = st_line['name']
49- st_line['val_date']=time.strftime('%Y-%m-%d', time.strptime(str2date(line[47:53]), "%y/%m/%d")),
50- st_line['entry_date']=time.strftime('%Y-%m-%d', time.strptime(str2date(line[115:121]), "%y/%m/%d")),
51- st_line['partner_id']=0
52- if line[31] == '1':
53- st_line_amt = - st_line_amt
54- st_line['account_id'] = def_pay_acc
55- else:
56- st_line['account_id'] = def_rec_acc
57- st_line['amount'] = st_line_amt
58- bank_statement_lines[line[2:6]]=st_line
59- bank_statement["bank_statement_line"]=bank_statement_lines
60- elif line[1] == '2':
61- st_line_name = line[2:6]
62- bank_statement_lines[st_line_name].update({'account_id': data.awaiting_account.id})
63-
64- elif line[1] == '3':
65- # movement data record 3.1
66- st_line_name = line[2:6]
67- st_line_partner_acc = str(line[10:47]).strip()
68- cntry_number=line[10:47].strip()
69- contry_name=line[47:125].strip()
70- bank_ids = partner_bank_obj.search(cr, uid, [('acc_number', '=', st_line_partner_acc)])
71- bank_statement_lines[st_line_name].update({'cntry_number': cntry_number, 'contry_name': contry_name})
72- if bank_ids:
73- bank = partner_bank_obj.browse(cr, uid, bank_ids[0], context=context)
74- if line and bank.partner_id:
75- bank_statement_lines[st_line_name].update({'partner_id': bank.partner_id.id})
76- if bank_statement_lines[st_line_name]['amount'] < 0:
77- bank_statement_lines[st_line_name].update({'account_id': bank.partner_id.property_account_payable.id})
78- else:
79- bank_statement_lines[st_line_name].update({'account_id': bank.partner_id.property_account_receivable.id})
80- else:
81- nb_err += 1
82- err_log += _('The bank account %s is not defined for the partner %s.\n')%(cntry_number, contry_name)
83+ try:
84+ if line[0] == '0':
85+ # header data
86+
87+ bank_statement["bank_statement_line"]={}
88+ bank_statement_lines = {}
89+ bank_statement['date'] = str2date(line[5:11])
90+ bank_statement['journal_id']=data.journal_id.id
91+ period_id = account_period_obj.search(cr, uid, [('date_start', '<=', time.strftime('%Y-%m-%d', time.strptime(bank_statement['date'], "%y/%m/%d"))), ('date_stop', '>=', time.strftime('%Y-%m-%d', time.strptime(bank_statement['date'], "%y/%m/%d")))])
92+ bank_statement['period_id'] = period_id and period_id[0] or False
93+ bank_statement['state']='draft'
94+ elif line[0] == '1':
95+ # old balance data
96+ bal_start = list2float(line[43:58])
97+ if line[42] == '1':
98+ bal_start = - bal_start
99+ bank_statement["balance_start"]= bal_start
100+ bank_statement["acc_number"]=line[5:17]
101+ bank_statement["acc_holder"]=line[64:90]
102+ bank_statement['name'] = journal_code + ' ' + str(line[2:5])
103+
104+ elif line[0]=='2':
105+ # movement data record 2
106+ if line[1]=='1':
107+ # movement data record 2.1
108+ if bank_statement_lines.has_key(line[2:6]):
109+ continue
110+ st_line = {}
111+ st_line['extra_note'] = ''
112+ st_line['statement_id']=0
113+ st_line['ref'] = line[2:10]
114+ st_line['date'] = time.strftime('%Y-%m-%d', time.strptime(str2date(line[115:121]), "%y/%m/%d")),
115+ st_line_amt = list2float(line[32:47])
116+
117+ if line[61]=='1':
118+ st_line['toreconcile'] = True
119+ st_line['name']=line[65:77]
120+ else:
121+ st_line['toreconcile'] = False
122+ st_line['name']=line[62:115]
123+
124+ st_line['free_comm'] = st_line['name']
125+ st_line['val_date']=time.strftime('%Y-%m-%d', time.strptime(str2date(line[47:53]), "%y/%m/%d")),
126+ st_line['entry_date']=time.strftime('%Y-%m-%d', time.strptime(str2date(line[115:121]), "%y/%m/%d")),
127+ st_line['partner_id']=0
128+ if line[31] == '1':
129+ st_line_amt = - st_line_amt
130+ st_line['account_id'] = def_pay_acc
131+ else:
132+ st_line['account_id'] = def_rec_acc
133+ st_line['amount'] = st_line_amt
134+ bank_statement_lines[line[2:6]]=st_line
135+ bank_statement["bank_statement_line"]=bank_statement_lines
136+ elif line[1] == '2':
137+ st_line_name = line[2:6]
138 bank_statement_lines[st_line_name].update({'account_id': data.awaiting_account.id})
139
140- bank_statement["bank_statement_line"]=bank_statement_lines
141- elif line[0]=='3':
142- if line[1] == '1':
143- st_line_name = line[2:6]
144- bank_statement_lines[st_line_name]['extra_note'] += '\n' + line[40:113]
145- elif line[1] == '2':
146- st_line_name = line[2:6]
147- bank_statement_lines[st_line_name]['extra_note'] += '\n' + line[10:115]
148- elif line[1] == '3':
149- st_line_name = line[2:6]
150- bank_statement_lines[st_line_name]['extra_note'] += '\n' + line[10:100]
151- elif line[0]=='8':
152- # new balance record
153- bal_end = list2float(line[42:57])
154- if line[41] == '1':
155- bal_end = - bal_end
156- bank_statement["balance_end_real"]= bal_end
157-
158- elif line[0]=='9':
159- # footer record
160-
161- bank_statements.append(bank_statement)
162+ elif line[1] == '3':
163+ # movement data record 3.1
164+ st_line_name = line[2:6]
165+ st_line_partner_acc = str(line[10:47]).strip()
166+ cntry_number=line[10:47].strip()
167+ contry_name=line[47:125].strip()
168+ bank_ids = partner_bank_obj.search(cr, uid, [('acc_number', '=', st_line_partner_acc)])
169+ bank_statement_lines[st_line_name].update({'cntry_number': cntry_number, 'contry_name': contry_name})
170+ if bank_ids:
171+ bank = partner_bank_obj.browse(cr, uid, bank_ids[0], context=context)
172+ if line and bank.partner_id:
173+ bank_statement_lines[st_line_name].update({'partner_id': bank.partner_id.id})
174+ if bank_statement_lines[st_line_name]['amount'] < 0:
175+ bank_statement_lines[st_line_name].update({'account_id': bank.partner_id.property_account_payable.id})
176+ else:
177+ bank_statement_lines[st_line_name].update({'account_id': bank.partner_id.property_account_receivable.id})
178+ else:
179+ nb_err += 1
180+ err_log += _('The bank account %s is not defined for the partner %s.\n')%(cntry_number, contry_name)
181+ bank_statement_lines[st_line_name].update({'account_id': data.awaiting_account.id})
182+
183+ bank_statement["bank_statement_line"]=bank_statement_lines
184+ elif line[0]=='3':
185+ if line[1] == '1':
186+ st_line_name = line[2:6]
187+ bank_statement_lines[st_line_name]['extra_note'] += '\n' + line[40:113]
188+ elif line[1] == '2':
189+ st_line_name = line[2:6]
190+ bank_statement_lines[st_line_name]['extra_note'] += '\n' + line[10:115]
191+ elif line[1] == '3':
192+ st_line_name = line[2:6]
193+ bank_statement_lines[st_line_name]['extra_note'] += '\n' + line[10:100]
194+ elif line[0]=='8':
195+ # new balance record
196+ bal_end = list2float(line[42:57])
197+ if line[41] == '1':
198+ bal_end = - bal_end
199+ bank_statement["balance_end_real"]= bal_end
200+
201+ elif line[0]=='9':
202+ # footer record
203+
204+ bank_statements.append(bank_statement)
205+ except:
206+ raise osv.except_osv(_('Warning !'), _('Select valid coda file to create bank statement'))
207 #end for
208 bkst_list=[]
209 for statement in bank_statements:

Subscribers

People subscribed via source and target branches