Cargar plantilla 3.3

This commit is contained in:
Mauricio Baeza 2017-11-03 20:05:19 -06:00
parent 3d7fb900bf
commit 4e323bd135
6 changed files with 175 additions and 12 deletions

View File

@ -61,9 +61,12 @@ def save_temp(data, modo='wb'):
def save_file(path, data, modo='wb'):
with open(path, modo) as f:
f.write(data)
return
try:
with open(path, modo) as f:
f.write(data)
return True
except:
return False
def _join(*paths):
@ -1092,9 +1095,18 @@ def upload_file(rfc, opt, file_obj):
tmp = file_obj.filename.split('.')
name = '{}.{}'.format(rfc.lower(), tmp[-1].lower())
path = _join(PATH_MEDIA, 'logos', name)
print (path)
save_file(path, file_obj.file.read())
return {'status': 'server', 'name': file_obj.filename}
elif opt == 'txt_plantilla_factura_33':
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 = '{}_3.3.ods'.format(rfc.lower())
path = _join(PATH_MEDIA, 'templates', name)
if save_file(path, file_obj.file.read()):
return {'status': 'server', 'name': file_obj.filename, 'ok': True}
return {'status': 'error'}

View File

@ -61,7 +61,10 @@ def desconectar():
def upload_file(rfc, opt, file_obj):
return util.upload_file(rfc, opt, file_obj)
result = util.upload_file(rfc, opt, file_obj)
if result['ok']:
Configuracion.add({opt: file_obj.filename})
return result
class Configuracion(BaseModel):
@ -87,6 +90,15 @@ class Configuracion(BaseModel):
.select()
.where(Configuracion.clave.in_(fields))
)
elif keys['fields'] == 'templates':
fields = (
'txt_plantilla_factura_32',
'txt_plantilla_factura_33',
'txt_plantilla_factura_33j')
data = (Configuracion
.select()
.where(Configuracion.clave.in_(fields))
)
values = {r.clave: r.valor for r in data}
return values

View File

@ -1,4 +1,5 @@
var msg = ''
var tb_options = null
var controllers = {
@ -19,6 +20,10 @@ var controllers = {
$$('cmd_probar_correo').attachEvent('onItemClick', cmd_probar_correo_click)
$$('cmd_guardar_correo').attachEvent('onItemClick', cmd_guardar_correo_click)
$$('emisor_logo').attachEvent('onItemClick', emisor_logo_click)
//~ Opciones
tb_options = $$('tab_options').getTabbar()
tb_options.attachEvent('onChange', tab_options_change)
$$('txt_plantilla_factura_33').attachEvent('onItemClick', txt_plantilla_factura_33_click)
}
}
@ -194,7 +199,26 @@ function get_config_correo(){
form.setValues(values)
}
})
}
function get_config_values(opt){
if(opt == undefined){
return
}
webix.ajax().get('/config', {'fields': opt}, {
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){
$$(key).setValue(values[key])
})
}
})
}
@ -216,6 +240,11 @@ function multi_admin_change(prevID, nextID){
get_config_correo()
return
}
if(nextID == 'app_options'){
get_config_values('templates')
return
}
}
@ -592,7 +621,7 @@ function emisor_logo_click(id, e){
var w = webix.ui({
view: 'window',
id: 'win_emisor_logo',
modal:true,
modal: true,
position: 'center',
head: 'Subir logotipo',
body: {
@ -611,3 +640,47 @@ function emisor_logo_click(id, e){
}
function txt_plantilla_factura_33_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_factura_33',
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',
body: {
view: 'form',
elements: body_elements,
}
})
w.show()
$$('up_template').attachEvent('onUploadComplete', function(response){
if(response.ok){
$$('txt_plantilla_factura_33').setValue(response.name)
msg_sucess('Plantilla cargada correctamente')
}else{
msg_error(response.name)
}
})
}
function tab_options_change(nv, ov){
var cv = {
Plantillas: 'templates',
}
get_config_values(cv[nv])
}

View File

@ -29,6 +29,7 @@ var controllers = {
$$("cmd_cancel_product").attachEvent("onItemClick", cmd_cancel_product_click)
$$("chk_automatica").attachEvent("onChange", chk_automatica_change)
$$("valor_unitario").attachEvent("onChange", valor_unitario_change)
$$("clave_sat").attachEvent('onSearchIconClick', clave_sat_icon_click)
//~ Invoices
$$('cmd_new_invoice').attachEvent("onItemClick", cmd_new_invoice_click)
$$('cmd_refacturar').attachEvent("onItemClick", cmd_refacturar_click)

View File

@ -201,3 +201,8 @@ function valor_unitario_change(new_value, old_value){
this.refresh()
}
}
function clave_sat_icon_click(){
show('Buscar SAT')
}

View File

@ -4,11 +4,14 @@ var menu_data = [
{id: 'app_emisor', icon: 'user-circle', value: 'Emisor'},
{id: 'app_folios', icon: 'sort-numeric-asc', value: 'Folios'},
{id: 'app_correo', icon: 'envelope-o', value: 'Correo'},
{id: 'app_sat', icon: 'table', value: 'Catalogos SAT'},
{id: 'app_options', icon: 'cog', value: 'Opciones'},
]
var sidebar = {
var sidebar_admin = {
view: 'sidebar',
id: 'sidebar_admin',
data: menu_data,
ready: function(){
this.select('app_home');
@ -328,6 +331,40 @@ var form_correo = {
}
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',
icon: 'file'}, {}]},
{maxHeight: 20},
{cols: [{maxWidth: 15},
{view: 'search', id: 'txt_plantilla_factura_33', labelPosition: 'top',
label: 'Plantilla Factura v3.3 (ODT): ', icon: 'file'}, {}]},
{maxHeight: 20},
{cols: [{maxWidth: 15},
{view: 'search', id: 'txt_plantilla_factura_33j', name: 'plantilla_factura_33j',
label: 'Plantilla Factura v3.3 (JSON): ', labelPosition: 'top',
icon: 'file'}, {}]},
{}]
var tab_options = {
view: 'tabview',
id: 'tab_options',
multiview: true,
tabbar: {options: [
'Plantillas',
'Otros']},
animate: true,
cells: [
{id: 'Plantillas', rows: options_templates},
{id: 'Otros', rows: [{}]},
{},
]
}
var app_emisor = {
id: 'app_emisor',
rows:[
@ -367,6 +404,26 @@ var app_correo = {
}
var app_sat = {
id: 'app_sat',
rows:[
{view: 'template', id: 'th_sat', type: 'header',
template: 'Catálogos del SAT'},
{},
]
}
var app_options = {
id: 'app_options',
rows:[
{view: 'template', id: 'th_options', type: 'header',
template: 'Opciones'},
tab_options,
]
}
var multi_admin = {
id: 'multi_admin',
animate: true,
@ -374,11 +431,13 @@ var multi_admin = {
{
id: 'app_admin_home',
view: 'template',
template: 'HOME'
template: 'Admin Inicio'
},
app_emisor,
app_folios,
app_correo,
app_sat,
app_options,
]
}
@ -402,7 +461,8 @@ var ui_admin = {
{view: 'toolbar', padding: 3, elements: [
{view: 'button', type: 'icon', icon: 'bars',
width: 37, align: 'left', css: 'app_button', click: function(){
$$('$sidebar1').toggle()
//~ $$('$sidebar1').toggle()
$$('sidebar_admin').toggle()
}
},
{view: 'label', label: 'Empresa Libre - Configuración'},
@ -413,7 +473,7 @@ var ui_admin = {
]},
{
cols:[
sidebar,
sidebar_admin,
multi_admin,
]
}