From 05c540495e43a84597399e3e72098a997cc6ed37 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Mon, 1 Jan 2018 11:54:37 -0600 Subject: [PATCH] =?UTF-8?q?Mostrar=20plantillas=20de=20acuerdo=20a=20confi?= =?UTF-8?q?guraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/app/controllers/util.py | 9 +++++ source/app/models/main.py | 19 ++++++++++ source/static/js/controller/admin.js | 57 +++++++++++++++++++++++++++- source/static/js/ui/admin.js | 12 ++++-- 4 files changed, 93 insertions(+), 4 deletions(-) diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 8ae6395..56dcd6f 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -1307,6 +1307,15 @@ def upload_file(rfc, opt, file_obj): name = '{}_3.3.json'.format(rfc.lower()) path = _join(PATH_MEDIA, 'templates', name) + elif opt == 'txt_plantilla_ticket': + tmp = file_obj.filename.split('.') + ext = tmp[-1].lower() + if ext != 'ods': + msg = 'Extensión de archivo incorrecta, selecciona un archivo ODS' + return {'status': 'server', 'name': msg, 'ok': False} + + name = '{}_ticket.ods'.format(rfc.lower()) + path = _join(PATH_MEDIA, 'templates', name) elif opt == 'txt_plantilla_donataria': tmp = file_obj.filename.split('.') ext = tmp[-1].lower() diff --git a/source/app/models/main.py b/source/app/models/main.py index b36e9a8..e4faaff 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -211,6 +211,24 @@ class Configuracion(BaseModel): values['default_unidad'] = SATUnidades.get_default() return values + if keys['fields'] == 'configtemplates': + try: + emisor = Emisor.select()[0] + is_ong = emisor.es_ong + except IndexError: + is_ong = False + + values = {'txt_plantilla_donataria': is_ong} + fields = ( + ('chk_usar_punto_de_venta', 'txt_plantilla_ticket'), + ) + + for s, key in fields: + value = util.get_bool(Configuracion.get_(s)) + values[key] = value + + return values + if keys['fields'] == 'correo': fields = ('correo_servidor', 'correo_puerto', 'correo_ssl', 'correo_usuario', 'correo_contra', 'correo_copia', @@ -231,6 +249,7 @@ class Configuracion(BaseModel): 'txt_plantilla_factura_32', 'txt_plantilla_factura_33', 'txt_plantilla_factura_33j', + 'txt_plantilla_ticket', 'txt_plantilla_donataria', ) data = (Configuracion diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 2cfe14c..b87ca2c 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -49,6 +49,7 @@ var controllers = { $$('txt_plantilla_factura_32').attachEvent('onItemClick', txt_plantilla_factura_32_click) $$('txt_plantilla_factura_33').attachEvent('onItemClick', txt_plantilla_factura_33_click) $$('txt_plantilla_factura_33j').attachEvent('onItemClick', txt_plantilla_factura_33j_click) + $$('txt_plantilla_ticket').attachEvent('onItemClick', txt_plantilla_ticket_click) $$('txt_plantilla_donataria').attachEvent('onItemClick', txt_plantilla_donataria_click) $$('chk_config_ocultar_metodo_pago').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_ocultar_condiciones_pago').attachEvent('onItemClick', chk_config_item_click) @@ -330,13 +331,29 @@ function get_admin_usuarios(){ } +function set_config_templates(){ + webix.ajax().get('/config', {'fields': 'configtemplates'}, { + error: function(text, data, xhr) { + msg = 'Error al consultar' + msg_error(msg) + }, + success: function(text, data, xhr) { + var values = data.json() + Object.keys(values).forEach(function(key){ + show(key, values[key]) + }) + } + }) +} + + function get_config_values(opt){ if(opt == undefined){ return } if(opt == 'templates'){ - show('txt_plantilla_donataria', $$('chk_ong').getValue()) + set_config_templates() } webix.ajax().get('/config', {'fields': opt}, { @@ -822,6 +839,44 @@ function txt_plantilla_factura_33_click(e){ } +function txt_plantilla_ticket_click(e){ + + var body_elements = [ + {cols: [{width: 100}, {view: 'uploader', id: 'up_template', autosend: true, link: 'lst_files', + value: 'Seleccionar archivo', upload: '/files/txt_plantilla_ticket', + width: 200}, {width: 100}]}, + {view: 'list', id: 'lst_files', type: 'uploader', autoheight:true, + borderless: true}, + {}, + {cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true, + click:("$$('win_template').close();")}, {}]} + ] + + var w = webix.ui({ + view: 'window', + id: 'win_template', + modal: true, + position: 'center', + head: 'Subir Plantilla Ticket ODT', + body: { + view: 'form', + elements: body_elements, + } + }) + + w.show() + + $$('up_template').attachEvent('onUploadComplete', function(response){ + if(response.ok){ + $$('txt_plantilla_ticket').setValue(response.name) + msg_ok('Plantilla cargada correctamente') + }else{ + msg_error(response.name) + } + }) +} + + function txt_plantilla_factura_32_click(e){ var body_elements = [ diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index b56e370..191e870 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -27,6 +27,7 @@ var form_editar_usuario_elementos = [ ]} ] + var admin_ui_windows = { init: function(){ webix.ui({ @@ -470,12 +471,12 @@ var options_templates = [ {maxHeight: 15}, {cols: [{maxWidth: 15}, {view: 'search', id: 'txt_plantilla_factura_32', name: 'plantilla_factura_32', - label: 'Plantilla Factura v3.2 (ODT): ', labelPosition: 'top', + label: 'Plantilla Factura v3.2 (ODS): ', labelPosition: 'top', icon: 'file'}, {}]}, {maxHeight: 20}, {cols: [{maxWidth: 15}, {view: 'search', id: 'txt_plantilla_factura_33', labelPosition: 'top', - label: 'Plantilla Factura v3.3 (ODT): ', icon: 'file'}, {}]}, + label: 'Plantilla Factura v3.3 (ODS): ', icon: 'file'}, {}]}, {maxHeight: 20}, {cols: [{maxWidth: 15}, {view: 'search', id: 'txt_plantilla_factura_33j', name: 'plantilla_factura_33j', @@ -483,9 +484,14 @@ var options_templates = [ icon: 'file'}, {}]}, {maxHeight: 20}, {cols: [{maxWidth: 15}, + {view: 'search', id: 'txt_plantilla_ticket', name: 'plantilla_ticket', + label: 'Plantilla para Tickets (ODS): ', labelPosition: 'top', + icon: 'file'}, {view: 'search', id: 'txt_plantilla_donataria', name: 'plantilla_donataria', label: 'Plantilla Donataria (solo ONGs): ', labelPosition: 'top', - icon: 'file'}, {}]}, + icon: 'file'}, + {}]}, + {maxHeight: 20}, {}]