Agregar datos para timbrado en emisor

This commit is contained in:
Mauricio Baeza 2017-10-25 22:26:18 -05:00
parent a37875d063
commit 54d925c8b1
4 changed files with 60 additions and 19 deletions

View File

@ -20,7 +20,10 @@ from zeep.cache import SqliteCache
from zeep.transports import Transport
from zeep.exceptions import Fault, TransportError
from .configpac import DEBUG, TIMEOUT, AUTH, URL
if __name__ == '__main__':
from configpac import DEBUG, TIMEOUT, AUTH, URL
else:
from .configpac import DEBUG, TIMEOUT, AUTH, URL
log = Logger('PAC')
@ -147,7 +150,7 @@ class Ecodex(object):
class Finkok(object):
def __init__(self):
def __init__(self, auth={}):
self.codes = URL['codes']
self.error = ''
self.message = ''
@ -159,6 +162,9 @@ class Finkok(object):
if DEBUG:
self._history = HistoryPlugin()
self._plugins = [self._history]
self._auth = AUTH
else:
self._auth = auth
def _debug(self):
if not DEBUG:
@ -225,6 +231,11 @@ class Finkok(object):
def timbra_xml(self, file_xml):
self.error = ''
if not DEBUG and not self._auth:
self.error = 'Sin datos para timbrar'
return
method = 'timbra'
ok, xml = self._validate_xml(file_xml)
if not ok:
@ -233,8 +244,8 @@ class Finkok(object):
URL[method], transport=self._transport, plugins=self._plugins)
args = {
'username': AUTH['USER'],
'password': AUTH['PASS'],
'username': self._auth['user'],
'password': self._auth['pass'],
'xml': xml,
}
if URL['quick_stamp']:
@ -261,8 +272,8 @@ class Finkok(object):
URL[method], transport=self._transport, plugins=self._plugins)
args = {
'username': AUTH['USER'],
'password': AUTH['PASS'],
'username': self._auth['user'],
'password': self._auth['pass'],
'uuid': uuid,
'taxpayer_id': self.rfc,
'invoice_type': 'I',
@ -296,7 +307,8 @@ class Finkok(object):
client = Client(
URL[method], transport=self._transport, plugins=self._plugins)
try:
result = client.service.stamped(xml, AUTH['USER'], AUTH['PASS'])
result = client.service.stamped(
xml, self._auth['user'], self._auth['pass'])
except Fault as e:
self.error = str(e)
return ''
@ -310,7 +322,8 @@ class Finkok(object):
client = Client(
URL[method], transport=self._transport, plugins=self._plugins)
try:
result = client.service.query_pending(AUTH['USER'], AUTH['PASS'], uuid)
result = client.service.query_pending(
self._auth['user'], self._auth['pass'], uuid)
#~ print (result.date)
#~ tree = parseString(unescape(result.xml))
#~ response = tree.toprettyxml(encoding='utf-8').decode('utf-8')
@ -334,8 +347,8 @@ class Finkok(object):
args = {
'UUIDS': uuid_type(uuids=sa(string=uuids)),
'username': AUTH['USER'],
'password': AUTH['PASS'],
'username': self._auth['user'],
'password': self._auth['pass'],
'taxpayer_id': rfc,
'cer': cer,
'key': key,
@ -366,8 +379,8 @@ class Finkok(object):
URL[method], transport=self._transport, plugins=self._plugins)
args = {
'username': AUTH['USER'],
'password': AUTH['PASS'],
'username': self._auth['user'],
'password': self._auth['pass'],
'xml': xml,
'store_pending': True,
}
@ -385,8 +398,8 @@ class Finkok(object):
URL[method], transport=self._transport, plugins=self._plugins)
args = {
'username': AUTH['USER'],
'password': AUTH['PASS'],
'username': self._auth['user'],
'password': self._auth['pass'],
'taxpayer_id': rfc,
'uuid': '',
'type': type_acuse,
@ -413,8 +426,8 @@ class Finkok(object):
URL[method], transport=self._transport, plugins=self._plugins)
args = {
'username': AUTH['USER'],
'password': AUTH['PASS'],
'username': self._auth['user'],
'password': self._auth['pass'],
'uuid': '',
}
try:

View File

@ -431,11 +431,19 @@ def make_xml(data, certificado):
return cfdi.add_sello(sello)
def timbra_xml(xml):
def timbra_xml(xml, auth):
from .pac import Finkok as PAC
if DEBUG:
auth = {}
else:
if not auth:
msg = 'Sin datos para timbrar'
result = {'ok': True, 'error': msg}
return result
result = {'ok': True, 'error': ''}
pac = PAC()
pac = PAC(auth)
xml = pac.timbra_xml(xml)
if not xml:
result['ok'] = False

View File

@ -184,6 +184,7 @@ class Emisor(BaseModel):
correo = TextField(default='')
web = TextField(default='')
curp = TextField(default='')
correo_timbrado = TextField(default='')
token_timbrado = TextField(default='')
token_soporte = TextField(default='')
logo = TextField(default='')
@ -216,6 +217,7 @@ class Emisor(BaseModel):
'emisor_municipio': obj.municipio,
'emisor_estado': obj.estado,
'emisor_pais': obj.pais,
'emisor_logo': obj.logo,
'emisor_nombre_comercial': obj.nombre_comercial,
'emisor_telefono': obj.telefono,
'emisor_correo': obj.correo,
@ -225,6 +227,9 @@ class Emisor(BaseModel):
'ong_autorizacion': obj.autorizacion,
'ong_fecha': obj.fecha_autorizacion,
'ong_fecha_dof': obj.fecha_dof,
'correo_timbrado': obj.correo_timbrado,
'token_timbrado': obj.token_timbrado,
'token_soporte': obj.token_soporte,
'regimenes': [row.id for row in obj.regimenes]
}
else:
@ -232,6 +237,14 @@ class Emisor(BaseModel):
return {'ok': True, 'row': row}
@classmethod
def get_auth(cls):
try:
obj = Emisor.select()[0]
return {'user': obj.correo_timbrado, 'pass': obj.token_timbrado}
except:
return {}
@classmethod
def get_regimenes(cls):
obj = Emisor.select()[0]
@ -248,6 +261,7 @@ class Emisor(BaseModel):
fields['municipio'] = fields.pop('emisor_municipio', '')
fields['estado'] = fields.pop('emisor_estado', '')
fields['pais'] = fields.pop('emisor_pais', 'México')
fields['logo'] = fields.pop('emisor_logo', '')
fields['nombre_comercial'] = fields.pop('emisor_nombre_comercial', '')
fields['telefono'] = fields.pop('emisor_telefono', '')
fields['correo'] = fields.pop('emisor_correo', '')
@ -1429,9 +1443,11 @@ class Facturas(BaseModel):
obj.estatus = 'Generada'
obj.save()
auth = Emisor.get_auth()
error = False
msg = 'Factura timbrada correctamente'
result = util.timbra_xml(obj.xml)
result = util.timbra_xml(obj.xml, auth)
if result['ok']:
obj.xml = result['xml']
obj.uuid = result['uuid']

View File

@ -62,6 +62,8 @@ var emisor_datos_fiscales = [
var emisor_otros_datos= [
{template: 'Generales', type: 'section'},
{view: 'search', id: 'emisor_logo', icon: 'file-image-o',
name: 'emisor_logo', label: 'Logotipo: '},
{view: 'text', id: 'emisor_nombre_comercial',
name: 'emisor_nombre_comercial', label: 'Nombre comercial: '},
{view: 'text', id: 'emisor_telefono', name: 'emisor_telefono',
@ -88,6 +90,8 @@ var emisor_otros_datos= [
label: 'Fecha de DOF: ', disabled: true, format: '%d-%M-%Y',
placeholder: 'Fecha de publicación en el DOF'}, {}]},
{template: 'Timbrado y Soporte', type: 'section'},
{view: 'text', id: 'correo_timbrado',
name: 'correo_timbrado', label: 'Usuario para Timbrado: '},
{view: 'text', id: 'token_timbrado',
name: 'token_timbrado', label: 'Token de Timbrado: '},
{view: 'text', id: 'token_soporte',