~eduardo-bayardo-bias/bias-trunk/bias_trunk

« back to all changes in this revision

Viewing changes to bias_electronic_invoice_bf/invoice.py

  • Committer: Jose Patricio
  • Date: 2010-09-10 00:15:14 UTC
  • Revision ID: josepato@ramona-20100910001514-pyvq1qhrwdui8h22
bias electronic invoice

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
5
#
 
6
# $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $
 
7
#
 
8
# WARNING: This program as such is intended to be used by professional
 
9
# programmers who take the whole responsability of assessing all potential
 
10
# consequences resulting from its eventual inadequacies and bugs
 
11
# End users who are looking for a ready-to-use solution with commercial
 
12
# garantees and support are strongly adviced to contract a Free Software
 
13
# Service Company
 
14
#
 
15
# This program is Free Software; you can redistribute it and/or
 
16
# modify it under the terms of the GNU General Public License
 
17
# as published by the Free Software Foundation; either version 2
 
18
# of the License, or (at your option) any later version.
 
19
#
 
20
# This program is distributed in the hope that it will be useful,
 
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
# GNU General Public License for more details.
 
24
#
 
25
# You should have received a copy of the GNU General Public License
 
26
# along with this program; if not, write to the Free Software
 
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
28
#
 
29
##############################################################################
 
30
 
 
31
from osv import fields, osv
 
32
import time
 
33
from mx.DateTime import *
 
34
import tools
 
35
import SOAPpy
 
36
import re
 
37
import StringIO
 
38
from lxml import etree
 
39
 
 
40
#import text
 
41
 
 
42
class account_invoice(osv.osv):
 
43
        _name = "account.invoice"
 
44
        _inherit = 'account.invoice'
 
45
        _description = 'Invoice'
 
46
 
 
47
 
 
48
        _columns = {
 
49
                'sign_date':fields.datetime('Sing Date'),
 
50
                'approve_year':fields.integer('Approve Year'),
 
51
                'approve_number':fields.integer('Approve Number'),
 
52
                'certificate': fields.text('Certificate'),
 
53
                'digital_signature': fields.text('Signature'),
 
54
                'provider_signature':  fields.text('Signature Provider'),
 
55
                #'invoice_xml':fields.text('Invoice_Xml'),
 
56
                }
 
57
 
 
58
        def action_number(self, cr, uid, ids, *args):
 
59
                super(account_invoice, self).action_number( cr, uid, ids, *args)
 
60
                self.create_xml(cr, uid, ids, *args)
 
61
 
 
62
 
 
63
 
 
64
                return True
 
65
 
 
66
        def create_xml(self,cr, uid, ids, *args):
 
67
                for inv_brw in self.browse(cr, uid, ids):
 
68
                        cfe = etree.Element('Comprobante'))
 
69
                        set_cfe_defaults(self, cfe)
 
70
                        emisor = self.get_emisor(cr, uid, inv_brw)
 
71
                
 
72
 
 
73
        def get_emisor(self, cr, uid, inv_brw, cfe):
 
74
                partner_obj = self.pool.get('res.partner')
 
75
                address_obj = self.pool.get('res.partner.address')
 
76
                partner_brw = inb_brw.company_id.partner_id
 
77
                partner_id = inb_brw.company_id.partner_id.id
 
78
                inovice_addres_id = partner_obj.address_get(cr, uid, partner_id, 'invoice')
 
79
                print 'inovice_addres_id',inovice_addres_id
 
80
                address_brw = address_obj.browse(cr, uid, inovice_addres_id)
 
81
                address = address_brw.street + '\n' 
 
82
                address += address_brw.street2 '\n' 
 
83
                address += address_brw.city '\n' 
 
84
                address += address_brw.state_id.name '\n'
 
85
                address += address_brw.country_id.name '\n'
 
86
                address += address_brw.zip '\n' 
 
87
                emisior = etree.Element('Emisor'))
 
88
                emisor.set('DomicilioFiscal',address)
 
89
                emisor.set('rfc',re.sub('-','',partner_brw.vat))
 
90
                emisor.set('nombre',inv_brw.company_id.name)
 
91
                
 
92
 
 
93
 
 
94
                if inv_brw.journal_id.invoice_sequence_id:
 
95
                        prefix = inv_brw.journal_id.invoice_sequence_id.prefix
 
96
                else:
 
97
                        prefix = inv_brw.journal_id.sequence_id.prefix
 
98
                if prefix:
 
99
                        number = int(inv_brw.number[len(prefix):])
 
100
                        cfe.set('serie',inv_brw.prefix)
 
101
                else:
 
102
                        number = int(inv_brw.number)
 
103
                cfe.set('folio',number)
 
104
                cfe.set('fecha',inv_brw.date_invoice)#aaaa-mm-ddThh:mm:ss
 
105
                cfe.set('sello',inv_brw.singature)
 
106
                cfe.set('anoAprobacion',inv_brw.approve_year)
 
107
                cfe.set('formaDePago','Pago en una sola exhibicion')###ahy que poner una forma de pago valida
 
108
                cfe.set('noAprobacion',inv_brw.approve_number)
 
109
                cfe.set('condicionesDePago',inv_brw.payment_term.name)
 
110
                cfe.set('noCertificado','00001000000000749743') ### hay que hacer el campo
 
111
                cfe.set('subTotal',inv_brw.amount_untaxed)
 
112
                cfe.set('subTotal',inv_brw.amount_untaxed)
 
113
                cfe.set('total',inv_brw.amount_total)
 
114
                if inv_brw.type == 'out_invoice':
 
115
                        cfe.set('tipoDeComprobante','ingreso')
 
116
                elif  inv_brw.type == 'out_refund':
 
117
                        cfe.set('tipoDeComprobante','egreso')
 
118
                else:
 
119
                        cfe.set('tipoDeComprobante','traslado')
 
120
                        discount = self.get_discount(cr, uid, inv_brw)
 
121
                #Optinal Stuff
 
122
                if discount:
 
123
                        cfe.set('descuento',discount)
 
124
                payment_form = self.get_payment_form(cr, uid, inv_brw)
 
125
                if payment_form:
 
126
                        cfe.set('metodoDePago',payment_form)
 
127
                return cfe
 
128
 
 
129
 
 
130
 
 
131
 
 
132
        <Emisor rfc="'''+e_rfc+'''" nombre="'''+e_nombre+'''">
 
133
                <DomicilioFiscal calle="'''+e_calle+'''" noExterior="'''+e_noExterior+'''" colonia="'''+e_colonia+'''" municipio="'''+e_municipio+'''" estado="'''+e_estado+'''" pais="'''+e_pais+'''" codigoPostal="'''+e_codigoPostal+'''"/>
 
134
        </Emisor>
 
135
        <Receptor rfc="'''+r_rfc+'''" nombre="'''+r_nombre+'''">
 
136
                <Domicilio calle="'''+r_calle+'''" noExterior="'''+r_noExterior+'''" colonia="'''+r_colonia+'''" municipio="'''+r_municipio+'''" estado="'''+r_estado+'''" pais="'''+r_pais+'''" codigoPostal="'''+r_codigoPostal+'''"/>
 
137
        </Receptor>
 
138
        <Conceptos>
 
139
'''+concepto+'''
 
140
        </Conceptos>
 
141
        <Impuestos totalImpuestosTrasladados="'''+totalImpuestosTrasladados+'''">
 
142
                <Traslados>'''+xml_taexs+'''
 
143
                </Traslados>
 
144
        </Impuestos>
 
145
</Comprobante>
 
146
 
 
147
 
 
148
 
 
149
 
 
150
def set_cfe_defaults(self, cfe):
 
151
        cfe.set('xmlns', "http://www.sat.gob.mx/cfd/2")
 
152
        cfe.set('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance")
 
153
        cfe.set('xsi:schemaLocation', "http://www.sat.gob.mx/cfd/2 http://www.sat.gob.mx/sitio_internet/cfd/2/cfdv2.xsd")
 
154
        cfe.set('version','2.0')
 
155
        return cfe
 
156
 
 
157
 
 
158
 
 
159
def get_discount(self, cr, uid, inv_brw):
 
160
        return 0
 
161
 
 
162
def get_payment_form(self, cr, uid, inv_brw):
 
163
        return False
 
164
 
 
165
def get_datos_comprobante(self, cr, uid, inv_brw, cfe):
 
166
        if inv_brw.journal_id.invoice_sequence_id:
 
167
                prefix = inv_brw.journal_id.invoice_sequence_id.prefix
 
168
        else:
 
169
                prefix = inv_brw.journal_id.sequence_id.prefix
 
170
        if prefix:
 
171
                number = int(inv_brw.number[len(prefix):])
 
172
                cfe.set('serie',inv_brw.prefix)
 
173
        else:
 
174
                number = int(inv_brw.number)
 
175
        cfe.set('folio',number)
 
176
        cfe.set('fecha',inv_brw.date_invoice)#aaaa-mm-ddThh:mm:ss
 
177
        cfe.set('sello',inv_brw.singature)
 
178
        cfe.set('anoAprobacion',inv_brw.approve_year)
 
179
        cfe.set('formaDePago','Pago en una sola exhibicion')###ahy que poner una forma de pago valida
 
180
        cfe.set('noAprobacion',inv_brw.approve_number)
 
181
        cfe.set('condicionesDePago',inv_brw.payment_term.name)
 
182
        cfe.set('noCertificado','00001000000000749743') ### hay que hacer el campo
 
183
        cfe.set('subTotal',inv_brw.amount_untaxed)
 
184
        cfe.set('subTotal',inv_brw.amount_untaxed)
 
185
        cfe.set('total',inv_brw.amount_total)
 
186
        if inv_brw.type == 'out_invoice':
 
187
                cfe.set('tipoDeComprobante','ingreso')
 
188
        elif  inv_brw.type == 'out_refund':
 
189
                cfe.set('tipoDeComprobante','egreso')
 
190
        else:
 
191
                cfe.set('tipoDeComprobante','traslado')
 
192
                discount = self.get_discount(cr, uid, inv_brw)
 
193
        #Optinal Stuff
 
194
        if discount:
 
195
                cfe.set('descuento',discount)
 
196
        payment_form = self.get_payment_form(cr, uid, inv_brw)
 
197
        if payment_form:
 
198
                cfe.set('metodoDePago',payment_form)
 
199
        return cfe
 
200
 
 
201
 
 
202
 
 
203
account_invoice()
 
204
 
 
205