From 00c58d9b41d3acfaf9060603567ec689ccb245f3 Mon Sep 17 00:00:00 2001 From: El Mau Date: Mon, 10 Jan 2022 13:39:35 -0600 Subject: [PATCH] =?UTF-8?q?Nuevo=20m=C3=A9todo=20para=20subir=20las=20plan?= =?UTF-8?q?tillas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/app/controllers/utils.py | 34 ++++++++++++++++++-- source/app/models/main.py | 3 +- source/static/js/controller/admin.js | 47 ++++++++++++++++++++++++++++ source/static/js/ui/admin.js | 4 +-- source/static/js/ui/invoices.js | 47 +++++++++++++++------------- 5 files changed, 108 insertions(+), 27 deletions(-) diff --git a/source/app/controllers/utils.py b/source/app/controllers/utils.py index 0b4a6a4..8ec80f6 100644 --- a/source/app/controllers/utils.py +++ b/source/app/controllers/utils.py @@ -824,12 +824,40 @@ def _products_from_xml(rfc, data): return result -def upload_file(rfc, opt, file_obj): - if opt == 'productsadd': - result = _products_from_xml(rfc, file_obj.file.read()) +def save_file(path, data, modo='wb'): + try: + with open(path, modo) as f: + f.write(data) + return True + except: + return False + + +def _save_template(rfc, name, file_obj): + result = {'status': 'server', 'ok': False} + + ext1 = name[-3:] + ext2 = file_obj.filename.split('.')[-1].lower() + if ext1 != ext2: + msg = f'Extensión incorrecta del archivo: {ext2}' + result['error'] = msg + return result + + rfc = rfc.lower() + path = _join(PATHS['USER'], f'{rfc}{name}') + if save_file(path, file_obj.file.read()): + result['ok'] = True + return result +def upload_file(rfc, name, file_obj): + if name == 'productsadd': + return _products_from_xml(rfc, file_obj.file.read()) + + return _save_template(rfc, name, file_obj) + + def get_qr(data, kind='svg', in_base64=False): buffer = io.BytesIO() segno.make(data).save(buffer, kind=kind, scale=8, border=2) diff --git a/source/app/models/main.py b/source/app/models/main.py index 95b0ccf..76e07aa 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -129,6 +129,7 @@ class UploadFile(object): method = f'_read_{opt}' if hasattr(cls, method): return getattr(cls, method)(cls, result) + return result @@ -146,7 +147,7 @@ def upload_file(rfc, opt, file_obj): return Emisor.save_logo(file_obj) # ~ v2 - names = ('productsadd',) + names = ('productsadd', '_3.3_cp_2.0.ods') if opt in names: result = UploadFile.read(rfc, opt, file_obj) return result diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 22b348c..c7b3a62 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -86,6 +86,7 @@ var controllers = { $$('txt_plantilla_nomina1233').attachEvent('onItemClick', txt_plantilla_nomina1233_click) $$('txt_plantilla_pagos10').attachEvent('onItemClick', txt_plantilla_pagos10_click) $$('make_pdf_from').attachEvent('onChange', opt_make_pdf_from_on_change) + $$('cmd_template_upload').attachEvent('onItemClick', cmd_template_upload_click) //~ Partners $$('chk_config_change_balance_partner').attachEvent('onItemClick', chk_config_item_click) @@ -3292,3 +3293,49 @@ function grid_carta_unidades_peso_on_check(row, column, state){ } }) } + + +function cmd_template_upload_click(e){ + + var template = $$('lst_templates_cfdi') + + if(!template.getValue()){ + msg = 'Selecciona una plantilla' + msg_error(msg) + return + } + + var body_elements = [ + {cols: [{width: 100}, {view: 'uploader', id: 'up_templates', autosend: true, link: 'lst_files', + value: 'Seleccionar archivo', upload: '/files/' + template.getValue(), + width: 200}, {width: 100}]}, + {view: 'list', id: 'lst_files', type: 'uploader', autoheight:true, + borderless: true}, + {}, + {cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true, + click:("$$('win_templates').close();")}, {}]} + ] + + var w = webix.ui({ + view: 'window', + id: 'win_templates', + modal: true, + position: 'center', + head: template.getText(), + body: { + view: 'form', + elements: body_elements, + } + }) + + w.show() + + $$('up_templates').attachEvent('onUploadComplete', function(response){ + if(response.ok){ + msg_ok('Plantilla cargada correctamente') + }else{ + $$("lst_files").clearAll() + msg_error(response.error) + } + }) +} diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index d178033..74422d4 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -595,7 +595,7 @@ var type_make_pdf = [ var opt_templates_cfdi = [ - {id: 'template_3.3_cp_2.0', value: 'CFDI v3.3 - Carta Porte 2.0'}, + {id: '_3.3_cp_2.0.ods', value: 'CFDI v3.3 - Carta Porte 2.0'}, ] @@ -607,7 +607,7 @@ var options_templates = [ {view: 'button', id: 'cmd_template_upload', type: 'iconButton', icon: 'file', width: 35}, {}, {maxWidth: 20} ]}, - {maxHeight: 25}, + {maxHeight: 50}, {cols: [{maxWidth: 20}, {view: 'search', id: 'txt_plantilla_factura_32', name: 'plantilla_factura_32', label: 'Plantilla Factura v3.2 (ODS): ', labelPosition: 'top', diff --git a/source/static/js/ui/invoices.js b/source/static/js/ui/invoices.js index d16b1b5..69c961f 100644 --- a/source/static/js/ui/invoices.js +++ b/source/static/js/ui/invoices.js @@ -859,14 +859,31 @@ var date_suggest = { } +var opt_countries = [ + {id: 'MXN', value: 'México'}, +] + + var grid_cols_carta_ubicaciones = [ {id: 'id', header: 'ID', hidden: true}, {id: 'delete', header: '', hidden: true, width: 30, css: 'delete'}, {id: 'TipoUbicacion', header: 'Tipo de Ubicación', editor: 'select', options: opt_origen_destino, fillspace: 1}, {id: 'RFCRemitenteDestinatario', header: 'RFC Rem/Des', editor: 'text', fillspace: 1}, + {id: 'NombreRemitenteDestinatario', header: 'Nombre Rem/Des', editor: 'text', fillspace: 1}, {id: 'FechaHoraSalidaLlegada', header: 'Fecha/Hora', editor: 'date', suggest: date_suggest, format: webix.Date.dateToStr("%D, %d-%M-%Y %h:%i"), footer: 'Total distancia:', fillspace: 1}, {id: 'DistanciaRecorrida', header: 'Distancia (KM)', editor: 'text', css: 'right', footer: {content: 'summColumn', css: 'right'}, fillspace: 1}, + {id: 'Municipio', headerd: 'Municipio', editor: 'text', fillspace: 1}, + {id: 'Estado', headerd: 'Estado', editor: 'text', fillspace: 1}, + {id: 'Pais', headerd: 'Pais', editor: 'select', options: opt_countries, fillspace: 1}, + {id: 'CodigoPostal', headerd: 'C.P.', editor: 'text', fillspace: 1}, ] +//~ Calle +//~ NumeroExterior +//~ NumeroInterior +//~ Colonia +//~ Localidad +//~ Referencia + var grid_cols_carta_mercancias = [ @@ -919,18 +936,6 @@ var grid_cols_carta_tipos_figuras = [ ] -var data_tmp1 = [ - {delete: '-', TipoUbicacion: 'Origen', RFCRemitenteDestinatario: 'XIQB891116QE4', FechaHoraSalidaLlegada: new Date(2022, 1, 10, 12, 00)}, - {delete: '-', TipoUbicacion: 'Destino', RFCRemitenteDestinatario: 'XIQB891116QE4', FechaHoraSalidaLlegada: new Date(2022, 1, 11, 12, 00)}, -] -var data_tmp2 = [ - {id: 0, PermSCT: 'TPAF03', NumPermisoSCT: 'Transporte privado de carga', ConfigVehicular: 'C3', PlacaVM: 'YYY1234', AnioModeloVM: '2020', AseguraRespCivil: 'Compañia Aseguradora', PolizaRespCivil: '1234567890'}, -] -var data_tmp3 = [ - {id: 0, TipoFigura: '01', RFCFigura: 'XIQB891116QE4', NombreFigura: 'Homero Simpson', NumLicencia: '1234567890'}, -] - - var grid_carta_ubicaciones = { view: 'datatable', id: 'grid_carta_ubicaciones', @@ -941,11 +946,11 @@ var grid_carta_ubicaciones = { editable: true, footer: true, columns: grid_cols_carta_ubicaciones, - data: data_tmp1, - //~ data: [ - //~ {delete: '-', TipoUbicacion: 'Origen', }, - //~ {delete: '-', TipoUbicacion: 'Destino'}, - //~ ] + //~ data: data_tmp1, + data: [ + {delete: '-', TipoUbicacion: 'Origen', Pais: 'MXN'}, + {delete: '-', TipoUbicacion: 'Destino', Pais: 'MXN'}, + ] } @@ -971,8 +976,8 @@ var grid_carta_autotransporte = { headermenu: true, editable: true, columns: grid_cols_carta_autotransporte, - //~ data: [{id: 0}], - data: data_tmp2, + data: [{id: 0}], + //~ data: data_tmp2, } @@ -985,8 +990,8 @@ var grid_carta_tipos_figuras = { headermenu: true, editable: true, columns: grid_cols_carta_tipos_figuras, - //~ data: [{id: 0}], - data: data_tmp3, + data: [{id: 0}], + //~ data: data_tmp3, }