Merge branch 'develop'

Timbrar XML grandes con Ecodex
This commit is contained in:
Mauricio Baeza 2018-02-22 15:12:19 -06:00
commit dc68b54f08
3 changed files with 52 additions and 15 deletions

View File

@ -33,8 +33,10 @@ log = Logger('PAC')
class Ecodex(object):
def __init__(self):
self.codes = URL['codes']
def __init__(self, auth, url):
self.auth = auth
self.url = url
self.codes = self.url['codes']
self.error = ''
self.message = ''
self._transport = Transport(cache=SqliteCache(), timeout=TIMEOUT)
@ -45,7 +47,7 @@ class Ecodex(object):
self._plugins = [self._history]
def _get_token(self, rfc):
client = Client(URL['seguridad'],
client = Client(self.url['seguridad'],
transport=self._transport, plugins=self._plugins)
try:
result = client.service.ObtenerToken(rfc, self._get_epoch())
@ -54,7 +56,7 @@ class Ecodex(object):
log.error(self.error)
return ''
s = '{}|{}'.format(AUTH['ID'], result.Token)
s = '{}|{}'.format(self.auth['ID'], result.Token)
return hashlib.sha1(s.encode()).hexdigest()
def _get_token_rest(self, rfc):
@ -99,7 +101,7 @@ class Ecodex(object):
def timbra_xml(self, xml):
data = self._validate_xml(xml)
client = Client(URL['timbra'],
client = Client(self.url['timbra'],
transport=self._transport, plugins=self._plugins)
try:
result = client.service.TimbraXML(**data)
@ -260,6 +262,12 @@ class Finkok(object):
except Fault as e:
self.error = str(e)
return
except TransportError as e:
if '413' in str(e):
self.error = '413<BR><BR><b>Documento muy grande para timbrar</b>'
else:
self.error = str(e)
return
return self._check_result(method, result)

View File

@ -42,7 +42,7 @@ from settings import DEBUG, MV, log, template_lookup, COMPANIES, DB_SAT, \
PATH_XSLT, PATH_XSLTPROC, PATH_OPENSSL, PATH_TEMPLATES, PATH_MEDIA, PRE, \
PATH_XMLSEC, TEMPLATE_CANCEL, DEFAULT_SAT_PRODUCTO, DECIMALES, DIR_FACTURAS
from settings import SEAFILE_SERVER, USAR_TOKEN, API
from settings import DEBUG, SEAFILE_SERVER, USAR_TOKEN, API
from .configpac import AUTH
@ -554,18 +554,49 @@ def timbra_xml(xml, auth):
result = {'ok': True, 'error': ''}
pac = PAC(auth)
xml = pac.timbra_xml(xml)
if not xml:
new_xml = pac.timbra_xml(xml)
if not new_xml:
result['ok'] = False
result['error'] = pac.error
return result
if pac.error.startswith('413'):
return _ecodex_timbra_xml(xml)
else:
return result
result['xml'] = xml
result['xml'] = new_xml
result['uuid'] = pac.uuid
result['fecha'] = pac.fecha
return result
def _get_uuid_fecha(xml):
doc = parse_xml(xml)
version = doc.attrib['Version']
node = doc.find('{}Complemento/{}TimbreFiscalDigital'.format(
PRE[version], PRE['TIMBRE']))
return node.attrib['UUID'], node.attrib['FechaTimbrado']
def _ecodex_timbra_xml(xml):
from .pac import Ecodex as PAC
from .configpac import ecodex
auth, url = ecodex(DEBUG)
pac = PAC(auth, url)
xml = pac.timbra_xml(xml)
if xml:
data = {'ok': True, 'error': ''}
data['xml'] = xml
uuid, fecha = _get_uuid_fecha(xml)
data['uuid'] = uuid
data['fecha'] = fecha
return data
msg = pac.error
return {'ok': False, 'error': msg}
def get_sat(xml):
from .pac import get_status_sat
return get_status_sat(xml)
@ -1078,6 +1109,7 @@ class LIBO(object):
def pdf(self, path, data, ods=False):
options = {'AsTemplate': True, 'Hidden': True}
log.info('Abrir plantilla...')
self._template = self._doc_open(path, options)
if self._template is None:
return b''
@ -1092,13 +1124,10 @@ class LIBO(object):
_kill(path_ods)
return data
doc = self._doc_open(path_ods, {'Hidden': True})
options = {'FilterName': 'calc_pdf_Export'}
path_pdf = get_path_temp('.pdf')
doc.storeToURL(self._path_url(path_pdf), self._set_properties(options))
doc.close(True)
self._template.storeToURL(self._path_url(path_pdf), self._set_properties(options))
self._template.close(True)
data = self._read(path_pdf)
_kill(path_ods)
_kill(path_pdf)

View File

@ -8,4 +8,4 @@ threads = 4
py-autoreload = 1
thunder-lock = true
static-map = /static=../static
http-timeout = 180
http-timeout = 300