1
# -*- encoding: latin-1 -*-
2
##############################################################################
4
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
35
from mx.DateTime import RelativeDateTime, DateTime
37
payment_form = """<?xml version="1.0"?>
38
<form string="Payment Export">
42
export_form = """<?xml version="1.0"?>
43
<form string="Payment Export">
49
'string':'Export File',
67
s = s.replace(k[0],k[1])
70
res= s.encode('ascii','replace')
76
def __init__(self,global_context_dict):
78
for i in global_context_dict:
79
global_context_dict[i]= global_context_dict[i] and tr(global_context_dict[i])
81
self.global_values = global_context_dict
82
self.pre={'padding':'','seg_num1':'0','seg_num2':'1',
83
'seg_num3':'1','seg_num4':'1','seg_num5':'05','seg_num_t':'9',
84
'flag':'0', 'zero5':'00000','flag1':'\n'
86
self.post={'date_value_hdr':'000000','type_paiement':'0'}
87
self.init_local_context()
89
def init_local_context(self):
91
Must instanciate a fields list, field = (name,size)
92
and update a local_values dict.
94
raise "not implemented"
98
for field in self.fields :
99
if self.pre.has_key(field[0]):
100
value = self.pre[field[0]]
101
elif self.global_values.has_key(field[0]):
102
value = self.global_values[field[0]]
104
elif self.post.has_key(field[0]):
105
value = self.post[field[0]]
108
#raise Exception(field[0]+' not found !')
110
res = res + c_ljust(value, field[1])
112
print "error is there"
118
class record_header(record):
120
def init_local_context(self):
124
('creation_date',6),('padding',12),
125
('institution_code',3),('app_code',2),('reg_number',10),('id_sender',11),('id_order_customer',11),('padding',1),
126
('ver_code',1),('bilateral',12),('totalisation_code',1),('padding',4),('ver_subcode',1),('padding',52),('flag1',1)
130
class record_trailer(record):
132
def init_local_context(self):
136
('tot_record',6),('tot_pay_order',6),
137
('tot_amount',15),('padding',100),('flag1',1),
140
class record_payline(record):
142
def init_local_context(self):
144
('seg_num2',1),('sequence',4),('sub_div1',2),('order_exe_date',6),
145
('order_ref',16),('cur_code',3),('padding',1),('code_pay',1),('amt_pay',15),('padding',1),
146
('cur_code_debit',3),('padding',6),
147
('acc_debit',12),('padding',22),('indicate_date',1),('padding',34),('flag1',1),
149
('seg_num3',1),('sequence1',4),('sub_div6',2),('benf_accnt_no',34),('benf_name',35),('benf_address',35),
150
('type_accnt',1),('bank_country_code',2),('padding',14),('flag1',1),
152
('seg_num4',1),('sequence2',4),('sub_div10',2),('order_msg',35),('method_pay',3),('charge_code',3),('padding',1),
153
('cur_code_debit',3),('padding',6),('debit_cost',12),('padding',1),('benf_country_code',2),('padding',55),('flag1',1),
156
def c_ljust(s, size):
158
check before calling ljust
163
s = s.decode('utf-8').encode('latin1','replace').ljust(size)
166
def _create_pay(self,cr,uid,data,context):
172
v1['creation_date']= time.strftime('%y%m%d')
174
v1['reg_number']=''#25-34
175
v1['id_sender']=''#Blank 35-44
176
v1['id_order_customer']=''#Blank 46-56
178
v1['bilateral']='' #see attach ment 1.2 and 59-70
179
v1['totalisation_code ']='0'#two values 0 or 1
180
v1['ver_subcode']='1'
182
pay_header =record_header(v1).generate()
184
pool = pooler.get_pool(cr.dbname)
185
bank_obj=pool.get('res.partner.bank')
186
id_exp= pool.get('account.pay').create(cr,uid,{
189
#look in the mode for insititute_code or protocol number
190
cr.execute("SELECT m.bank_id from payment_order o inner join payment_mode m on o.mode=m.id and o.id in (%s) group by bank_id;"% (data['id']))
191
bank_id=cr.fetchone()
193
bank = bank_obj.browse(cr, uid, bank_id[0], context)
194
v['institution_code']=bank.institution_code
195
pay_line_obj=pool.get('payment.line')
196
pay_line_id = pay_line_obj.search(cr, uid, [('order_id','=',data['id'])])
197
pay_line =pay_line_obj.read(cr, uid, pay_line_id,['partner_id','amount','bank_id'])
203
v['sequence'] = str(seq).rjust(4).replace(' ','0')
205
v['order_exe_date']=''
206
v['order_ref']=''#14-29
207
v['cur_code']='BEF'#static set .but is available in entry line object..
208
v['code_pay']='C'#two values 'C' or 'D'
209
v['amt_pay']=float2str(pay['amount'])
210
total=total+pay['amount']
211
v['acc_debit']=bank.acc_number
212
v['indicate_date']=''# three value blank,1,2,
215
v['sequence1']=str(seq).rjust(4).replace(' ','0')
218
bank1 = bank_obj.read(cr, uid, pay['bank_id'][0])
219
if bank1['state']=='bank':
220
v['benf_accnt_no']=bank1['acc_number']
222
elif bank1['state']=='iban':
223
v['benf_accnt_no']=bank1['iban']
227
v['bank_country_code']=''
228
part_addres_obj=pool.get('res.partner.address')
229
part_address_id = part_addres_obj.search(cr, uid, [('partner_id','=',bank1['partner_id'][0])])
230
part_address = part_addres_obj.browse(cr, uid, part_address_id,context)
231
if bank1['bank_address_id']:
232
bank2 = part_addres_obj.read(cr, uid, bank1['bank_address_id'][0])#get bank address of counrty for pos 113-114 sub06
233
if bank2['country_id']:
234
code_country=pool.get('res.country').read(cr,uid,bank2['country_id'][0],['code'])#get bank address of counrty for pos 113-114 sub06
235
v['bank_country_code']=code_country['code']
236
for i in part_address:
237
v['benf_name']=i.name
238
v['benf_address']=str(i.street)+str(i.street2)+str(i.city)+str(i.state_id.name)+str(i.country_id.name)#continue this record to sub07...pos 8-42
241
v['sequence2']=str(seq).rjust(4).replace(' ','0')
243
v['order_msg']=''#msg from order customer to order cutomer bank
244
v['method_pay']='EUR'#see attachment 1.5..multiple values are available
246
v['cur_code_debit']=''#'BEF'
247
v['debit_cost']='000000000000'#field will only fill when ordering customer account debitted with charges if not field will contain blank or zero
248
v['benf_country_code']=''
249
pay_order =pay_order+record_payline(v).generate()
251
#trailer record........start
252
v2['tot_record']=str(seq)
253
v2['tot_pay_order']=str(seq)
254
v2['tot_amount']=float2str(total)
255
pay_trailer=record_trailer(v2).generate()
257
pay_order=pay_header+pay_order+pay_trailer
259
log= log +'\n'+ str(e) + 'CORRUPTED FILE !\n'
261
pool.get('account.pay').write(cr,uid,[id_exp],{'note':log,'name':base64.encodestring(pay_order or "")})
262
return {'note':log, 'pay': base64.encodestring(pay_order)}
265
#return str(lst).replace('.','')
266
return str(lst).rjust(15).replace('.','0')
268
class wizard_pay_create(wizard.interface):
272
'result' : {'type' : 'form',
273
'arch' : payment_form,
274
'fields' : payment_fields,
275
'state' : [('Create File', 'Export Payment') ]}
278
'actions' : [_create_pay],
279
'result' : {'type' : 'form',
280
'arch' : export_form,
281
'fields' : export_fields,
282
'state' : [('end', 'Ok') ]}
287
wizard_pay_create('account.payment_create')
b'\\ No newline at end of file'