Descargar ODS

This commit is contained in:
Mauricio Baeza 2018-01-18 00:15:14 -06:00
parent 3f835d4d5c
commit 1cc7d1f1b8
5 changed files with 30 additions and 4 deletions

View File

@ -891,7 +891,7 @@ class LIBO(object):
self._clean()
return
def pdf(self, path, data):
def pdf(self, path, data, ods=False):
options = {'AsTemplate': True, 'Hidden': True}
self._template = self._doc_open(path, options)
if self._template is None:
@ -902,8 +902,10 @@ class LIBO(object):
path = '{}.ods'.format(tempfile.mkstemp()[1])
self._template.storeToURL(self._path_url(path), ())
doc = self._doc_open(path, {'Hidden': True})
if ods:
return self._read(path)
doc = self._doc_open(path, {'Hidden': True})
options = {'FilterName': 'calc_pdf_Export'}
path = tempfile.mkstemp()[1]
doc.storeToURL(self._path_url(path), self._set_properties(options))
@ -913,7 +915,7 @@ class LIBO(object):
return self._read(path)
def to_pdf(data, emisor_rfc):
def to_pdf(data, emisor_rfc, ods=False):
rfc = data['emisor']['rfc']
if DEBUG:
rfc = emisor_rfc
@ -928,7 +930,7 @@ def to_pdf(data, emisor_rfc):
name = '{}_{}{}.ods'.format(rfc.lower(), version, donativo)
path = get_template_ods(name)
if path:
return app.pdf(path, data)
return app.pdf(path, data, ods)
name = '{}_{}.json'.format(rfc, version)
custom_styles = get_custom_styles(name)

View File

@ -107,6 +107,7 @@ def validar_timbrar():
def get_doc(type_doc, id, rfc):
types = {
'xml': 'application/xml',
'ods': 'application/octet-stream',
'zip': 'application/octet-stream',
}
content_type = types.get(type_doc, 'application/pdf')
@ -114,6 +115,8 @@ def get_doc(type_doc, id, rfc):
data, file_name = Facturas.get_xml(id)
elif type_doc == 'pdf':
data, file_name = Facturas.get_pdf(id, rfc)
elif type_doc == 'ods':
data, file_name = Facturas.get_ods(id, rfc)
elif type_doc == 'zip':
data, file_name = Facturas.get_zip(id, rfc)
elif type_doc == 'pre':
@ -2594,6 +2597,23 @@ class Facturas(BaseModel):
return doc, name
@classmethod
def get_ods(cls, id, rfc):
try:
emisor = Emisor.select()[0]
except IndexError:
return b'', 'sin_datos_de_emisor.pdf'
obj = Facturas.get(Facturas.id==id)
name = '{}{}_{}.ods'.format(obj.serie, obj.folio, obj.cliente.rfc)
if obj.uuid is None:
return b'', name
values = cls._get_not_in_xml(cls, obj, emisor)
data = util.get_data_from_xml(obj, values)
doc = util.to_pdf(data, emisor.rfc, True)
return doc, name
@classmethod
def get_zip(cls, id, rfc):
obj = Facturas.get(Facturas.id==id)

View File

@ -1131,6 +1131,8 @@ function grid_invoices_click(id, e, node){
location = '/doc/xml/' + row.id
}else if(id.column == 'pdf'){
get_pdf(row.id)
}else if(id.column == 'ods'){
location = '/doc/ods/' + row.id
}else if(id.column == 'zip'){
location = '/doc/zip/' + row.id
}else if(id.column == 'email'){

View File

@ -40,6 +40,7 @@ function get_icon(tipo){
zip: 'fa-file-zip-o',
email: 'fa-envelope-o',
print: 'fa-print',
table: 'fa-table',
}
return "<span class='webix_icon " + icons[tipo] + "'></span>"
}

View File

@ -241,6 +241,7 @@ var grid_invoices_cols = [
fillspace: true, sort: 'string', footer: '$ 0.00'},
{id: 'xml', header: 'XML', adjust: 'data', template: get_icon('xml')},
{id: 'pdf', header: 'PDF', adjust: 'data', template: get_icon('pdf')},
{id: 'ods', header: 'ODS', adjust: 'data', template: get_icon('table')},
{id: 'zip', header: 'ZIP', adjust: 'data', template: get_icon('zip')},
{id: 'email', header: '', adjust: 'data', template: get_icon('email')}
]