1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2006 ACYSOS S.L. (http://acysos.com) All Rights Reserved.
6
# Pedro Tarrafeta <pedro@acysos.com>
7
# Copyright (c) 2008 Pablo Rocandio. All Rights Reserved.
8
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
9
# Jordi Esteve <jesteve@zikzakmedia.com>
12
# Corregido para instalación TinyERP estándar 4.2.0: Zikzakmedia S.L. 2008
13
# Jordi Esteve <jesteve@zikzakmedia.com>
15
# Añadidas cuentas de remesas y tipos de pago. 2008
16
# Pablo Rocandio <salbet@gmail.com>
18
# Rehecho de nuevo para instalación OpenERP 5.0.0 sobre account_payment_extension: Zikzakmedia S.L. 2009
19
# Jordi Esteve <jesteve@zikzakmedia.com>
21
# This program is free software: you can redistribute it and/or modify
22
# it under the terms of the GNU General Public License as published by
23
# the Free Software Foundation, either version 3 of the License, or
24
# (at your option) any later version.
26
# This program is distributed in the hope that it will be useful,
27
# but WITHOUT ANY WARRANTY; without even the implied warranty of
28
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
# GNU General Public License for more details.
31
# You should have received a copy of the GNU General Public License
32
# along with this program. If not, see <http://www.gnu.org/licenses/>.
34
##############################################################################
40
from mx.DateTime import now
41
from datetime import datetime
42
from tools.translate import _
43
from converter import *
49
join_form = """<?xml version="1.0"?>
50
<form string="Payment order export">
55
'join' : {'string':'Join payment lines of the same partner and bank account', 'type':'boolean'},
58
export_form = """<?xml version="1.0"?>
59
<form string="Payment order export">
60
<field name="pay" filename="pay_fname"/>
61
<field name="pay_fname" invisible="1"/>
62
<field name="note" colspan="4" nolabel="1"/>
67
'string':'Payment order file',
72
'pay_fname': {'string':'File name', 'type':'char', 'size':64},
73
'note' : {'string':'Log', 'type':'text'},
77
def _create_payment_file(self, cr, uid, data, context):
83
pool = pooler.get_pool(cr.dbname)
84
orden = pool.get('payment.order').browse(cr, uid, data['id'], context)
85
if not orden.line_ids:
86
raise Log( _('User error:\n\nWizard can not generate export file, there are not payment lines.'), True )
88
# Comprobamos que exista número de C.C. y que tenga 20 dígitos
89
if not orden.mode.bank_id:
90
raise Log( _('User error:\n\nThe bank account of the company %s is not defined.') % (orden.mode.partner_id.name), True )
91
cc = digits_only(orden.mode.bank_id.acc_number)
93
raise Log( _('User error:\n\nThe bank account number of the company %s has not 20 digits.') % (orden.mode.partner_id.name), True)
95
# Comprobamos que exista el CIF de la compañía asociada al C.C. del modo de pago
96
if not orden.mode.bank_id.partner_id.vat:
97
raise Log(_('User error:\n\nThe company VAT number related to the bank account of the payment mode is not defined.'), True)
100
if data['form']['join']:
101
# Lista con todos los partners+bancos diferentes de la remesa
102
partner_bank_l = reduce(lambda l, x: x not in l and l.append(x) or l,
103
[(recibo.partner_id,recibo.bank_id) for recibo in orden.line_ids], [])
104
# Cómputo de la lista de recibos agrupados por mismo partner+banco.
105
# Los importes se suman, los textos se concatenan con un espacio en blanco y las fechas se escoge el máximo
106
for partner,bank in partner_bank_l:
107
lineas = [recibo for recibo in orden.line_ids if recibo.partner_id==partner and recibo.bank_id==bank]
109
'partner_id': partner,
112
'amount': reduce(lambda x, y: x+y, [l.amount for l in lineas], 0),
113
'communication': reduce(lambda x, y: x+' '+(y or ''), [l.name+' '+l.communication for l in lineas], ''),
114
'communication2': reduce(lambda x, y: x+' '+(y or ''), [l.communication2 for l in lineas], ''),
115
'date': max([l.date for l in lineas]),
116
'ml_maturity_date': max([l.ml_maturity_date]),
117
'create_date': max([l.create_date]),
118
'ml_date_created': max([l.ml_date_created]),
121
# Cada línea de pago es un recibo
122
for l in orden.line_ids:
124
'partner_id': l.partner_id,
125
'bank_id': l.bank_id,
126
'name': l.partner_id.ref,
128
'communication': l.name+' '+l.communication,
129
'communication2': l.communication2,
131
'ml_maturity_date': l.ml_maturity_date,
132
'create_date': l.create_date,
133
'ml_date_created': l.ml_date_created,
136
if orden.mode.require_bank_account:
138
ccc = line['bank_id'] and line['bank_id'].acc_number or False
140
raise Log(_('User error:\n\nThe bank account number of the customer %s is not defined and current payment mode enforces all lines to have a bank account.') % (line['partner_id'].name), True)
141
ccc = digits_only(ccc)
143
raise Log(_('User error:\n\nThe bank account number of the customer %s has not 20 digits.') % (line['partner_id'].name), True)
145
if orden.mode.tipo == 'csb_19':
146
csb = csb_19.csb_19()
147
elif orden.mode.tipo == 'csb_32':
148
csb = csb_32.csb_32()
149
elif orden.mode.tipo == 'csb_34':
150
csb = csb_34.csb_34()
151
elif orden.mode.tipo == 'csb_58':
152
csb = csb_58.csb_58()
154
raise Log(_('User error:\n\nThe payment mode is not CSB 19, CSB 32, CSB 34 or CSB 58'), True)
155
txt_remesa = csb.create_file(pool, cr, uid, orden, recibos, context)
160
'reference': orden.id,
165
# Ensure line breaks use MS-DOS (CRLF) format as standards require.
166
txt_remesa = txt_remesa.replace('\r\n','\n').replace('\n','\r\n')
168
file = base64.encodestring(txt_remesa)
169
fname = (_('remesa') + '_' + orden.mode.tipo + '_' + orden.reference + '.txt').replace('/','-')
170
pool.get('ir.attachment').create(cr, uid, {
171
'name': _('Remesa ') + orden.mode.tipo + ' ' + orden.reference,
173
'datas_fname': fname,
174
'res_model': 'payment.order',
177
log = _("Successfully Exported\n\nSummary:\n Total amount paid: %.2f\n Total Number of Payments: %d\n") % (-orden.total, len(recibos))
178
pool.get('payment.order').set_done(cr,uid,orden.id,context)
181
'reference': orden.id,
184
'state': 'succeeded',
188
class wizard_payment_file_spain(wizard.interface):
192
'result' : {'type' : 'form',
194
'fields' : join_fields,
195
'state' : [('export', 'Ok','gtk-ok') ]}
198
'actions' : [_create_payment_file],
199
'result' : {'type' : 'form',
200
'arch' : export_form,
201
'fields' : export_fields,
202
'state' : [('end', 'Ok','gtk-ok') ]}
206
wizard_payment_file_spain('export_payment_file_spain')
207
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: