1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
34
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
35
from lxml.builder import ElementMaker
36
from lxml import etree
44
dates_form = '''<?xml version="1.0"?>
45
<form string="Select period">
46
<field name="company_id"/>
47
<field name="fiscalyear" colspan="4"/>
48
<field name="period" colspan="4" domain="[('fiscalyear_id','=',fiscalyear)]"/>
52
'company_id': {'string': 'Company', 'type': 'many2one',
53
'relation': 'res.company', 'required': True},
54
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
55
'help': 'Keep empty for all open fiscal year'},
56
'period': {'string': 'Period', 'type': 'many2one', 'relation': 'account.period',
60
export_form = """<?xml version="1.0"?>
61
<form string="Payment Export">
62
<field name="report"/>
63
<field name="note" colspan="4" height="300" width="800" nolabel="1"/>
68
'string':'Export File',
73
'note' : {'string':'Log','type':'text'},
77
def _get_report(self,cr,uid,data,context):
78
pool = pooler.get_pool(cr.dbname)
79
fy_id = data['form']['fiscalyear']
80
pe_id = data['form']['period']
81
company_id = data['form']['company_id']
82
ano = int(pool.get('account.fiscalyear').browse(cr, uid, fy_id, context=context).date_start[:4])
83
mes = int(pool.get('account.period').browse(cr, uid, pe_id, context=context).date_start[5:7])
84
rfc = pool.get('res.company').browse(cr, uid, company_id, context=context).partner_id.vat
85
rfc = re.sub('-','',rfc)
86
res = file = self._reporte(rfc,mes,ano)
87
buf=StringIO.StringIO()
89
out=base64.encodestring(buf.getvalue())
92
return {'note': res, 'report': out}
96
class wizard_electronic_report_invoice(wizard.interface):
97
def _reporte(self, rfc, mes, ano):
98
E = ElementMaker(namespace="http://www.buzonfiscal.com/ns/xsd/bf/bfcorp/2",
100
'soapenv':"http://schemas.xmlsoap.org/soap/envelope/",
101
'ns':"http://www.buzonfiscal.com/ns/xsd/bf/bfcorp/2"},)
103
DOC = E.RequestReporteMensual
104
reporte = DOC({'rfcEmisor':rfc, 'mes':str(mes), 'anio':str(ano)})
105
reporte_xml = etree.tostring(reporte)
106
reporte_xml = '<?xml version="1.0" encoding="UTF-8"?>' + reporte_xml
107
util = SOAPpy.WSDL.Proxy("CorporativoWS2.2.wsdl")
108
reporte = util.GeneraReporteMensual(reporte_xml)
111
def _get_defaults(self, cr, uid, data, context):
112
pool = pooler.get_pool(cr.dbname)
113
fiscalyear_obj = pool.get('account.fiscalyear')
114
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
115
user = pool.get('res.users').browse(cr, uid, uid, context=context)
117
company_id = user.company_id.id
119
company_id = pool.get('res.company').search(cr, uid,
120
[('parent_id', '=', False)])[0]
121
data['form']['company_id'] = company_id
126
'actions': [_get_defaults],
127
'result': {'type':'form',
129
'fields':dates_fields,
130
'state':[('end','Cancel'),('export','Export')]}
133
'actions' : [_get_report],
134
'result' : {'type' : 'form',
135
'arch' : export_form,
136
'fields' : export_fields,
137
'state' : [('close', 'Ok','gtk-ok') ]}
141
'result': {'type': 'state', 'state':'end'}
145
wizard_electronic_report_invoice('account.invoice.electronic.report')