1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6
# $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $
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
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.
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.
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.
29
##############################################################################
31
from osv import fields, osv
33
from mx.DateTime import *
38
from lxml import etree
42
class account_invoice(osv.osv):
43
_name = "account.invoice"
44
_inherit = 'account.invoice'
45
_description = 'Invoice'
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'),
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)
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)
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)
94
if inv_brw.journal_id.invoice_sequence_id:
95
prefix = inv_brw.journal_id.invoice_sequence_id.prefix
97
prefix = inv_brw.journal_id.sequence_id.prefix
99
number = int(inv_brw.number[len(prefix):])
100
cfe.set('serie',inv_brw.prefix)
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')
119
cfe.set('tipoDeComprobante','traslado')
120
discount = self.get_discount(cr, uid, inv_brw)
123
cfe.set('descuento',discount)
124
payment_form = self.get_payment_form(cr, uid, inv_brw)
126
cfe.set('metodoDePago',payment_form)
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+'''"/>
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+'''"/>
141
<Impuestos totalImpuestosTrasladados="'''+totalImpuestosTrasladados+'''">
142
<Traslados>'''+xml_taexs+'''
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')
159
def get_discount(self, cr, uid, inv_brw):
162
def get_payment_form(self, cr, uid, inv_brw):
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
169
prefix = inv_brw.journal_id.sequence_id.prefix
171
number = int(inv_brw.number[len(prefix):])
172
cfe.set('serie',inv_brw.prefix)
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')
191
cfe.set('tipoDeComprobante','traslado')
192
discount = self.get_discount(cr, uid, inv_brw)
195
cfe.set('descuento',discount)
196
payment_form = self.get_payment_form(cr, uid, inv_brw)
198
cfe.set('metodoDePago',payment_form)