~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to bias_electronic_invoice/report/invoice.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
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
 
10
# Service Company
 
11
#
 
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.
 
16
#
 
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.
 
21
#
 
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.
 
25
#
 
26
##############################################################################
 
27
 
 
28
import time
 
29
from report  import report_sxw
 
30
import text
 
31
import pooler
 
32
from lxml import etree
 
33
 
 
34
class account_invoice(report_sxw.rml_parse):
 
35
        def __init__(self, cr, uid, name, context):
 
36
                super(account_invoice, self).__init__(cr, uid, name, context)
 
37
                user = self.pool.get('res.users').browse(cr, uid, uid)
 
38
                self.localcontext.update({
 
39
                        'time': time,
 
40
                        'date_sp': text.date_sp,
 
41
                        'moneyfmt': text.moneyfmt,
 
42
                        'texto': self._get_text,
 
43
                        #'fix_space': text.fix_space,
 
44
                        'user': user,
 
45
                        'get_impuestos':self._get_impuestos,
 
46
                        'tipoDeComprobante': self._get_tipoDeComprobante,
 
47
                        'leyendaTipoDeCambio': self._get_leyendaTipoDeCambio,
 
48
                        'leyenda':self._get_leyenda_UDS,
 
49
                        'leyenda_pitex':self._get_leyenda_pitex,
 
50
                        'cadena':self._get_cadena,
 
51
                        #'give_me_space':self._give_me_space,
 
52
                })
 
53
 
 
54
        def _get_lines(self, txt):
 
55
                res = txt[:len(txt)/2] + ' ' + txt[len(txt)/2:]
 
56
                return res
 
57
 
 
58
        def _get_text(self, amount):
 
59
                return text.text(int(amount))
 
60
 
 
61
        def _get_cadena(self, cadena):
 
62
                rows = len(cadena)/120
 
63
                res = ''
 
64
                for rn in range(rows):
 
65
                        res += cadena[200*rn:(200*(rn+1))] + '\n'
 
66
                return res
 
67
 
 
68
        def _get_leyenda_UDS(self, obj):
 
69
                if obj.currency_id.code == 'USD':
 
70
                        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'
 
71
                else:
 
72
                        return ''
 
73
 
 
74
        def _get_leyenda_pitex(self, obj):
 
75
                if obj.partner_id.property_account_position.name == 'RETENEDOR DEL IVA':
 
76
                        return 'Impuesto retenido de conformidad con la Ley del Impuesto al Valor Agregado'
 
77
                else:
 
78
                        return ''
 
79
 
 
80
 
 
81
        def _get_tipoDeComprobante(self, inv_brw):
 
82
                if inv_brw.type == 'out_invoice':
 
83
                        return 'Ingreso'
 
84
                elif  inv_brw.type == 'out_refund':
 
85
                        return 'Egreso'
 
86
                elif inv_brw.company_id.partner_id.vat == inv_brw.partner_id.vat:
 
87
                        return 'Traslado'
 
88
                return ''
 
89
 
 
90
 
 
91
 
 
92
        def _get_leyendaTipoDeCambio(self, inv_brw):
 
93
                if inv_brw.currency_id.code == 'USD':
 
94
                        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'
 
95
                else:
 
96
                        return 'abc'
 
97
 
 
98
 
 
99
        
 
100
        def _get_impuestos(self, invoice_obj):
 
101
                tax_obj = pooler.get_pool(self.cr.dbname).get('account.invoice')
 
102
                tax_xml = tax_obj.get_impuestos(self.cr, self.uid, invoice_obj.tax_line)
 
103
                res = []
 
104
                for tax_type in tax_xml:
 
105
                        for tax in tax_type:
 
106
                                res_dir = {}
 
107
                                tax.values()
 
108
                                if tax.get('impuesto'):
 
109
                                        res_dir['impuesto'] =  tax_type[0].tag + ' ' + tax.get('impuesto')
 
110
                                else:
 
111
                                        res_dir['impuesto'] = ''
 
112
                                if tax.get('importe'):
 
113
                                        res_dir['importe'] =  '$ ' +  tax.get('importe')
 
114
                                else:
 
115
                                        res_dir['importe'] =  ''
 
116
                                if tax.get('tasa'):
 
117
                                        res_dir['tasa'] =  tax.get('tasa') + '%'
 
118
                                else:
 
119
                                        res_dir['tasa'] = ''
 
120
                                res.append(res_dir)
 
121
                if not res:
 
122
                        res_dir ={'impuesto':'', 'importe':'', 'tasa':''}
 
123
                        res.append(res_dir)
 
124
                return res
 
125
 
 
126
##      def _get_impuestos(self, invoice_obj):
 
127
##              tax_obj = pooler.get_pool(self.cr.dbname).get('account.invoice')
 
128
##              tax_xml = tax_obj.get_impuestos(self.cr, self.uid, invoice_obj.tax_line)
 
129
##              res = []
 
130
##              for tax_type in tax_xml:
 
131
##                      for tax in tax_type:
 
132
##                              res_dir = {}
 
133
##                              if tax.get('impuesto'):
 
134
##                                      res_dir['impuesto'] =  tax_type[0].tag + ' ' + tax.get('impuesto')
 
135
##                              else:
 
136
##                                      res_dir['impuesto'] = ''
 
137
##                              if tax.get('importe'):
 
138
##                                      res_dir['importe'] =  tax.get('importe')
 
139
##                              else:
 
140
##                                      res_dir['importe'] =  ''
 
141
##                              if tax.get('tasa'):
 
142
##                                      res_dir['tasa'] =  tax.get('tasa') + '%'
 
143
##                              else:
 
144
##                                      res_dir['tasa'] = ''
 
145
##                              res.append(res_dir)
 
146
##              return res
 
147
        
 
148
 
 
149
report_sxw.report_sxw('report.account.invoice.electronic', 'account.invoice', 'addons/bias_electronic_invoice/report/invoice_b.rml', parser=account_invoice, header=False)
 
150