forked from elmau/empresa-libre
Descargar XML
This commit is contained in:
parent
55190c5faa
commit
4410326efb
|
@ -196,3 +196,18 @@ class AppFolios(object):
|
||||||
resp.status = falcon.HTTP_200
|
resp.status = falcon.HTTP_200
|
||||||
else:
|
else:
|
||||||
resp.status = falcon.HTTP_204
|
resp.status = falcon.HTTP_204
|
||||||
|
|
||||||
|
|
||||||
|
class AppDocumentos(object):
|
||||||
|
|
||||||
|
def __init__(self, db):
|
||||||
|
self._db = db
|
||||||
|
#~ self._not_json = True
|
||||||
|
|
||||||
|
def on_get(self, req, resp, type_doc, id_doc):
|
||||||
|
req.context['result'], file_name, content_type = \
|
||||||
|
self._db.get_doc(type_doc, id_doc)
|
||||||
|
resp.append_header('Content-Disposition',
|
||||||
|
'attachment; filename={}'.format(file_name))
|
||||||
|
resp.content_type = content_type
|
||||||
|
resp.status = falcon.HTTP_200
|
||||||
|
|
|
@ -14,7 +14,8 @@ from middleware import (
|
||||||
from models.db import StorageEngine
|
from models.db import StorageEngine
|
||||||
from controllers.main import (
|
from controllers.main import (
|
||||||
AppLogin, AppLogout, AppAdmin, AppEmisor,
|
AppLogin, AppLogout, AppAdmin, AppEmisor,
|
||||||
AppMain, AppValues, AppPartners, AppProducts, AppInvoices, AppFolios
|
AppMain, AppValues, AppPartners, AppProducts, AppInvoices, AppFolios,
|
||||||
|
AppDocumentos
|
||||||
)
|
)
|
||||||
from settings import DEBUG
|
from settings import DEBUG
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ api.add_route('/emisor', AppEmisor(db))
|
||||||
api.add_route('/folios', AppFolios(db))
|
api.add_route('/folios', AppFolios(db))
|
||||||
api.add_route('/main', AppMain(db))
|
api.add_route('/main', AppMain(db))
|
||||||
api.add_route('/values/{table}', AppValues(db))
|
api.add_route('/values/{table}', AppValues(db))
|
||||||
|
api.add_route('/doc/{type_doc}/{id_doc}', AppDocumentos(db))
|
||||||
api.add_route('/partners', AppPartners(db))
|
api.add_route('/partners', AppPartners(db))
|
||||||
api.add_route('/products', AppProducts(db))
|
api.add_route('/products', AppProducts(db))
|
||||||
api.add_route('/invoices', AppInvoices(db))
|
api.add_route('/invoices', AppInvoices(db))
|
||||||
|
|
|
@ -46,6 +46,9 @@ class JSONTranslator(object):
|
||||||
def process_response(self, req, resp, resource):
|
def process_response(self, req, resp, resource):
|
||||||
if 'result' not in req.context:
|
if 'result' not in req.context:
|
||||||
return
|
return
|
||||||
|
if '/doc/' in req.path:
|
||||||
|
resp.body = req.context['result']
|
||||||
|
return
|
||||||
resp.body = util.dumps(req.context['result'])
|
resp.body = util.dumps(req.context['result'])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -115,3 +115,9 @@ class StorageEngine(object):
|
||||||
def add_folios(self, values):
|
def add_folios(self, values):
|
||||||
return main.Folios.add(values)
|
return main.Folios.add(values)
|
||||||
|
|
||||||
|
def get_doc(self, type_doc, id):
|
||||||
|
if type_doc == 'xml':
|
||||||
|
data, file_name = main.Facturas.get_xml(id)
|
||||||
|
content_type = 'application.xml'
|
||||||
|
return data, file_name, content_type
|
||||||
|
|
||||||
|
|
|
@ -933,6 +933,12 @@ class Facturas(BaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
order_by = ('fecha',)
|
order_by = ('fecha',)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_xml(cls, id):
|
||||||
|
obj = Facturas.get(Facturas.id==id)
|
||||||
|
name = '{}{}_{}.xml'.format(obj.serie, obj.folio, obj.cliente.rfc)
|
||||||
|
return obj.xml, name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_(cls, values):
|
def get_(cls, values):
|
||||||
rows = tuple(Facturas
|
rows = tuple(Facturas
|
||||||
|
|
|
@ -640,3 +640,12 @@ function cmd_invoice_timbrar_click(){
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function grid_invoices_click(id, e, node){
|
||||||
|
var row = this.getItem(id)
|
||||||
|
if(id.column == 'xml'){
|
||||||
|
location = '/doc/xml/' + row.id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ var controllers = {
|
||||||
$$('grid_details').attachEvent('onBeforeEditStart', grid_details_before_edit_start)
|
$$('grid_details').attachEvent('onBeforeEditStart', grid_details_before_edit_start)
|
||||||
$$('grid_details').attachEvent('onBeforeEditStop', grid_details_before_edit_stop)
|
$$('grid_details').attachEvent('onBeforeEditStop', grid_details_before_edit_stop)
|
||||||
$$('cmd_invoice_timbrar').attachEvent('onItemClick', cmd_invoice_timbrar_click)
|
$$('cmd_invoice_timbrar').attachEvent('onItemClick', cmd_invoice_timbrar_click)
|
||||||
|
$$('grid_invoices').attachEvent('onItemClick', grid_invoices_click)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,18 +17,6 @@ var toolbar_invoices_util = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
function doc_xml(obj){
|
|
||||||
var node = "<img src='/static/img/file-xml.png' height='20' width='20' style='margin: 5px 0px'/>"
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function doc_pdf(obj){
|
|
||||||
var node = "<img src='/static/img/file-pdf.png' height='20' width='20' style='margin: 5px 0px'/>"
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_icon(tipo){
|
function get_icon(tipo){
|
||||||
var node = "<img src='/static/img/file-" + tipo + ".png' height='20' width='20' style='margin: 5px 0px'/>"
|
var node = "<img src='/static/img/file-" + tipo + ".png' height='20' width='20' style='margin: 5px 0px'/>"
|
||||||
return node
|
return node
|
||||||
|
|
Loading…
Reference in New Issue