Nuevo método para subir las plantillas

This commit is contained in:
El Mau 2022-01-10 13:39:35 -06:00
parent a3d291c893
commit 00c58d9b41
5 changed files with 108 additions and 27 deletions

View File

@ -824,12 +824,40 @@ def _products_from_xml(rfc, data):
return result return result
def upload_file(rfc, opt, file_obj): def save_file(path, data, modo='wb'):
if opt == 'productsadd': try:
result = _products_from_xml(rfc, file_obj.file.read()) 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 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): def get_qr(data, kind='svg', in_base64=False):
buffer = io.BytesIO() buffer = io.BytesIO()
segno.make(data).save(buffer, kind=kind, scale=8, border=2) segno.make(data).save(buffer, kind=kind, scale=8, border=2)

View File

@ -129,6 +129,7 @@ class UploadFile(object):
method = f'_read_{opt}' method = f'_read_{opt}'
if hasattr(cls, method): if hasattr(cls, method):
return getattr(cls, method)(cls, result) return getattr(cls, method)(cls, result)
return result return result
@ -146,7 +147,7 @@ def upload_file(rfc, opt, file_obj):
return Emisor.save_logo(file_obj) return Emisor.save_logo(file_obj)
# ~ v2 # ~ v2
names = ('productsadd',) names = ('productsadd', '_3.3_cp_2.0.ods')
if opt in names: if opt in names:
result = UploadFile.read(rfc, opt, file_obj) result = UploadFile.read(rfc, opt, file_obj)
return result return result

View File

@ -86,6 +86,7 @@ var controllers = {
$$('txt_plantilla_nomina1233').attachEvent('onItemClick', txt_plantilla_nomina1233_click) $$('txt_plantilla_nomina1233').attachEvent('onItemClick', txt_plantilla_nomina1233_click)
$$('txt_plantilla_pagos10').attachEvent('onItemClick', txt_plantilla_pagos10_click) $$('txt_plantilla_pagos10').attachEvent('onItemClick', txt_plantilla_pagos10_click)
$$('make_pdf_from').attachEvent('onChange', opt_make_pdf_from_on_change) $$('make_pdf_from').attachEvent('onChange', opt_make_pdf_from_on_change)
$$('cmd_template_upload').attachEvent('onItemClick', cmd_template_upload_click)
//~ Partners //~ Partners
$$('chk_config_change_balance_partner').attachEvent('onItemClick', chk_config_item_click) $$('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)
}
})
}

View File

@ -595,7 +595,7 @@ var type_make_pdf = [
var opt_templates_cfdi = [ 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}, {view: 'button', id: 'cmd_template_upload', type: 'iconButton', icon: 'file', width: 35},
{}, {},
{maxWidth: 20} ]}, {maxWidth: 20} ]},
{maxHeight: 25}, {maxHeight: 50},
{cols: [{maxWidth: 20}, {cols: [{maxWidth: 20},
{view: 'search', id: 'txt_plantilla_factura_32', name: 'plantilla_factura_32', {view: 'search', id: 'txt_plantilla_factura_32', name: 'plantilla_factura_32',
label: 'Plantilla Factura v3.2 (ODS): ', labelPosition: 'top', label: 'Plantilla Factura v3.2 (ODS): ', labelPosition: 'top',

View File

@ -859,14 +859,31 @@ var date_suggest = {
} }
var opt_countries = [
{id: 'MXN', value: 'México'},
]
var grid_cols_carta_ubicaciones = [ var grid_cols_carta_ubicaciones = [
{id: 'id', header: 'ID', hidden: true}, {id: 'id', header: 'ID', hidden: true},
{id: 'delete', header: '', hidden: true, width: 30, css: 'delete'}, {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: '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: '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: '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: '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 = [ 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 = { var grid_carta_ubicaciones = {
view: 'datatable', view: 'datatable',
id: 'grid_carta_ubicaciones', id: 'grid_carta_ubicaciones',
@ -941,11 +946,11 @@ var grid_carta_ubicaciones = {
editable: true, editable: true,
footer: true, footer: true,
columns: grid_cols_carta_ubicaciones, columns: grid_cols_carta_ubicaciones,
data: data_tmp1, //~ data: data_tmp1,
//~ data: [ data: [
//~ {delete: '-', TipoUbicacion: 'Origen', }, {delete: '-', TipoUbicacion: 'Origen', Pais: 'MXN'},
//~ {delete: '-', TipoUbicacion: 'Destino'}, {delete: '-', TipoUbicacion: 'Destino', Pais: 'MXN'},
//~ ] ]
} }
@ -971,8 +976,8 @@ var grid_carta_autotransporte = {
headermenu: true, headermenu: true,
editable: true, editable: true,
columns: grid_cols_carta_autotransporte, columns: grid_cols_carta_autotransporte,
//~ data: [{id: 0}], data: [{id: 0}],
data: data_tmp2, //~ data: data_tmp2,
} }
@ -985,8 +990,8 @@ var grid_carta_tipos_figuras = {
headermenu: true, headermenu: true,
editable: true, editable: true,
columns: grid_cols_carta_tipos_figuras, columns: grid_cols_carta_tipos_figuras,
//~ data: [{id: 0}], data: [{id: 0}],
data: data_tmp3, //~ data: data_tmp3,
} }