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

View File

@ -431,11 +431,19 @@ def make_xml(data, certificado):
return cfdi.add_sello(sello) return cfdi.add_sello(sello)
def timbra_xml(xml): def timbra_xml(xml, auth):
from .pac import Finkok as PAC 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': ''} result = {'ok': True, 'error': ''}
pac = PAC() pac = PAC(auth)
xml = pac.timbra_xml(xml) xml = pac.timbra_xml(xml)
if not xml: if not xml:
result['ok'] = False result['ok'] = False

View File

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

View File

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