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
##############################################################################
29
from report import report_sxw
32
from lxml import etree
36
class account_invoice(report_sxw.rml_parse):
37
def __init__(self, cr, uid, name, context):
38
super(account_invoice, self).__init__(cr, uid, name, context)
39
user = self.pool.get('res.users').browse(cr, uid, uid)
40
self.localcontext.update({
42
'date_sp': text.date_sp,
43
'moneyfmt': text.moneyfmt,
44
'texto': self._get_text,
45
'get_money_name': text.get_money_name,
46
#'fix_space': text.fix_space,
48
'get_impuestos':self._get_impuestos,
49
'tipoDeComprobante': self._get_tipoDeComprobante,
50
'leyendaTipoDeCambio': self._get_leyendaTipoDeCambio,
51
'leyenda':self._get_leyenda_UDS,
52
'leyenda_pitex':self._get_leyenda_pitex,
53
'cadena':self._get_cadena,
54
'get_nopartidas': self._get_nopartidas,
55
'get_lineas_partidas': self._get_lineas_partidas,
56
'get_total_products': self._get_total_products,
57
'convert_value': self._convert_value,
58
#'give_me_space':self._give_me_space,
61
def _get_lines(self, txt):
62
res = txt[:len(txt)/2] + ' ' + txt[len(txt)/2:]
65
def _get_text(self, amount):
66
return text.text(int(amount))
68
def _get_cadena(self, cadena):
69
rows = len(cadena)/120
71
for rn in range(rows):
72
res += cadena[200*rn:(200*(rn+1))] + '\n'
75
def _get_leyenda_UDS(self, obj):
76
if obj.currency_id.code == 'USD':
77
return 'LA PRESENTE FACTURA SE SOLVENTARA ENTREGADO EL EQUIVALENTE EN MONEDA NACIONAL, AL TIPO DE CAMBIO QUE EL BANCO DE MEXICO PUBLIQUE EN EL DIARIO OFICIAL DE LA FEDERACION, EL DIA HABIL BANCARIO INMEDIATO ANTERIOR A AQUEL EN QUE SE EFECTUE EL PAGO'
81
def _get_leyenda_pitex(self, obj):
82
if obj.partner_id.property_account_position.name == 'RETENEDOR DEL IVA':
83
return 'Impuesto retenido de conformidad con la Ley del Impuesto al Valor Agregado'
88
def _get_tipoDeComprobante(self, inv_brw):
89
if inv_brw.type == 'out_invoice':
91
elif inv_brw.type == 'out_refund':
93
elif inv_brw.company_id.partner_id.vat == inv_brw.partner_id.vat:
99
def _get_leyendaTipoDeCambio(self, inv_brw):
100
if inv_brw.currency_id.code == 'USD':
101
return 'La presente factura se solventara entregado el equivalente en moneda nacional, al tipo de cambio que el Banco de Mexico publique en el Diario Oficial de la Federacion, el dia habil bancario inmediato anterior a aquel en que se efectue el pago'
107
def _get_impuestos(self, invoice_obj):
108
tax_obj = pooler.get_pool(self.cr.dbname).get('account.invoice')
109
tax_xml = tax_obj.get_impuestos(self.cr, self.uid, invoice_obj.tax_line)
111
for tax_type in tax_xml:
115
if tax.get('impuesto'):
116
res_dir['impuesto'] = tax_type[0].tag + ' ' + tax.get('impuesto')
118
res_dir['impuesto'] = ''
119
if tax.get('importe'):
120
res_dir['importe'] = '$ ' + text.moneyfmt('%.2f' % float(tax.get('importe')))
122
res_dir['importe'] = ''
124
res_dir['tasa'] = tax.get('tasa') + '%'
129
res_dir ={'impuesto':'', 'importe':'', 'tasa':''}
133
## def _get_impuestos(self, invoice_obj):
134
## tax_obj = pooler.get_pool(self.cr.dbname).get('account.invoice')
135
## tax_xml = tax_obj.get_impuestos(self.cr, self.uid, invoice_obj.tax_line)
137
## for tax_type in tax_xml:
138
## for tax in tax_type:
140
## if tax.get('impuesto'):
141
## res_dir['impuesto'] = tax_type[0].tag + ' ' + tax.get('impuesto')
143
## res_dir['impuesto'] = ''
144
## if tax.get('importe'):
145
## res_dir['importe'] = tax.get('importe')
147
## res_dir['importe'] = ''
148
## if tax.get('tasa'):
149
## res_dir['tasa'] = tax.get('tasa') + '%'
151
## res_dir['tasa'] = ''
152
## res.append(res_dir)
155
def _get_nopartidas(self, invoice_obj):
156
query = "SELECT count(id) FROM account_invoice_line WHERE invoice_id=%s"%(invoice_obj.id)
157
self.cr.execute(query)
158
res = self.cr.fetchone()
164
def _get_lineas_partidas(self, invoice_obj):
165
query2 = "SELECT a.quantity, a.name, a.price_unit, a.discount, a.price_subtotal, p.default_code, a.note FROM account_invoice_line a, product_product p WHERE invoice_id=%s and a.product_id = p.id order by name"%(invoice_obj.id)
166
self.cr.execute(query2)
167
res = self.cr.dictfetchall()
172
rr.update({'renglon':count})
174
rr.update({'discount':str(rr['discount']) +'%'})
178
def _get_total_products(self, invoice_obj):
179
totales = "SELECT SUM(quantity) FROM account_invoice_line WHERE invoice_id=%s"%(invoice_obj.id)
180
self.cr.execute(totales)
181
res = self.cr.fetchone()
184
return text.moneyfmt( '%.2f' % float(res))
186
def _convert_value(self, value, context={}):
189
if context.get('strip', False) and context.get('model', False):
190
quitar=len(context['model'])+3
191
value = value[quitar:]
193
if context.get('currency', False):
195
return 'EL VALOR DE ESTA FACTURA ESTA EN USD'
198
if context.get('money_format', False):
199
return '$ ' + text.moneyfmt( '%.2f' % float(value))
200
if context.get('re', False):
201
return re.sub(',',"",str(value))
202
if context.get('vat_fmt', False):
203
return re.sub('[-. |*]',"",str(value)).upper()
208
report_sxw.report_sxw('report.account.invoice.electronic', 'account.invoice', 'addons/bias_electronic_invoice_v6/report/invoice_b.rml', parser=account_invoice, header=False)