Move configuration for PACs

This commit is contained in:
Mauricio Baeza 2020-12-28 22:14:30 -06:00
parent bd7508fe6b
commit f02b6782be
3 changed files with 126 additions and 43 deletions

View File

@ -501,6 +501,21 @@ class Configuracion(BaseModel):
value = data[0].valor
return value
def _get_pac(cls, pac):
user_field = f'user_timbrado_{pac}'
token_field = f'token_timbrado_{pac}'
fields = (user_field, token_field)
data = (Configuracion
.select()
.where(Configuracion.clave.in_(fields))
)
data = {r.clave: r.valor for r in data}
values = {
'user_timbrado': data.get(user_field, ''),
'token_timbrado': data.get(token_field, ''),
}
return values
@classmethod
def get_(cls, keys):
if isinstance(keys, str):
@ -524,6 +539,9 @@ class Configuracion(BaseModel):
if opt in options:
return getattr(cls, '_get_{}'.format(opt))(cls)
if opt == 'pac':
return cls._get_pac(cls, keys['pac'])
if keys['fields'] == 'configtemplates':
try:
emisor = Emisor.select()[0]
@ -572,7 +590,7 @@ class Configuracion(BaseModel):
)
values = {r.clave: util.get_bool(r.valor) for r in data}
fields = (
('lst_pac', 'default'),
('lst_pac', 'comercio'),
)
for k, d in fields:
values[k] = Configuracion.get_value(k, d)
@ -617,6 +635,24 @@ class Configuracion(BaseModel):
values = {r.clave: r.valor for r in data}
return values
def _save_pac(cls, values):
pac = values['lst_pac']
user = values['user_timbrado']
token = values['token_timbrado']
data = {
'lst_pac': pac,
f'user_timbrado_{pac}': user,
f'token_timbrado_{pac}': token,
}
for k, v in data.items():
obj, _ = Configuracion.get_or_create(clave=k)
obj.valor = v
obj.save()
return {'ok': True}
@classmethod
def add(cls, values):
opt = values.pop('opt', '')
@ -1004,8 +1040,8 @@ class Emisor(BaseModel):
'ong_autorizacion': obj.autorizacion,
'ong_fecha': obj.fecha_autorizacion,
'ong_fecha_dof': obj.fecha_dof,
'correo_timbrado': obj.correo_timbrado,
'token_timbrado': obj.token_timbrado,
# ~ 'correo_timbrado': obj.correo_timbrado,
# ~ 'token_timbrado': obj.token_timbrado,
'token_soporte': obj.token_soporte,
'emisor_registro_patronal': obj.registro_patronal,
'regimenes': [row.id for row in obj.regimenes]

View File

@ -135,6 +135,7 @@ var controllers = {
$$('chk_ticket_user_show_doc').attachEvent('onItemClick', chk_config_item_click)
$$('txt_ticket_printer').attachEvent('onKeyPress', txt_ticket_printer_key_press)
$$('lst_pac').attachEvent('onChange', lst_pac_on_change)
$$('cmd_save_pac').attachEvent('onItemClick', cmd_save_pac_click)
$$('cmd_subir_bdfl').attachEvent('onItemClick', cmd_subir_bdfl_click)
$$('cmd_subir_cfdixml').attachEvent('onItemClick', cmd_subir_cfdixml_click)
@ -480,7 +481,7 @@ function get_config_values(opt){
var values = data.json()
Object.keys(values).forEach(function(key){
if(key=='lst_pac'){
set_value(key, values[key])
$$('lst_pac').setValue(values[key])
}else{
$$(key).setValue(values[key])
if(key=='chk_config_leyendas_fiscales'){
@ -2558,37 +2559,6 @@ function opt_make_pdf_from_on_change(new_value, old_value){
}
function lst_pac_on_change(nv, ov){
if(nv=='default'){
webix.ajax().del('/config', {id: 'lst_pac'}, function(text, xml, xhr){
var msg = 'PAC predeterminado establecido correctamente'
if(xhr.status == 200){
msg_ok(msg)
}else{
msg = 'No se pudo eliminar'
msg_error(msg)
}
})
}else{
webix.ajax().post('/config', {'lst_pac': nv}, {
error: function(text, data, xhr) {
msg = 'Error al guardar la configuración'
msg_error(msg)
},
success: function(text, data, xhr) {
var values = data.json();
if (values.ok){
msg = 'PAC establecido correctamente'
msg_ok(msg)
}else{
msg_error(values.msg)
}
}
})
}
}
function admin_config_other_options(id){
if(id=='chk_config_leyendas_fiscales'){
var value = Boolean($$(id).getValue())
@ -2693,3 +2663,66 @@ function delete_leyenda_fiscal(id){
}
})
}
function lst_pac_on_change(nv, ov){
webix.ajax().get('/config', {'fields': 'pac', 'pac': nv}, {
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){
set_value(key, values[key])
})
}
})
}
function cmd_save_pac_click(){
var pac = $$('lst_pac').getValue()
var user = $$('user_timbrado').getValue()
var token = $$('token_timbrado').getValue()
if(!pac.trim()){
msg = 'Selecciona un PAC'
msg_error(msg)
return
}
if(!user.trim()){
msg = 'El Usuario es requerido'
msg_error(msg)
return
}
if(!token.trim()){
msg = 'El Token es requerido'
msg_error(msg)
return
}
var values = {
opt: 'save_pac',
lst_pac: pac,
user_timbrado: user,
token_timbrado: token,
}
webix.ajax().post('/config', values, {
error: function(text, data, xhr) {
msg = 'Error al guardar el PAC'
msg_error(msg)
},
success: function(text, data, xhr) {
var values = data.json();
if (values.ok){
msg = 'PAC guardado correctamente'
msg_ok(msg)
}else{
msg_error(values.msg)
}
}
})
}

View File

@ -238,11 +238,11 @@ var emisor_otros_datos= [
{cols: [{view: 'datepicker', id: 'ong_fecha_dof', name: 'ong_fecha_dof',
label: 'Fecha de DOF: ', disabled: true, format: '%d-%M-%Y',
placeholder: 'Fecha de publicación en el DOF'}, {}]},
{template: 'Timbrado y Soporte', type: 'section'},
{view: 'text', id: 'correo_timbrado',
name: 'correo_timbrado', label: 'Usuario para Timbrado: '},
{view: 'text', id: 'token_timbrado',
name: 'token_timbrado', label: 'Token de Timbrado: '},
{template: 'Soporte', type: 'section'},
//~ {view: 'text', id: 'correo_timbrado',
//~ name: 'correo_timbrado', label: 'Usuario para Timbrado: '},
//~ {view: 'text', id: 'token_timbrado',
//~ name: 'token_timbrado', label: 'Token de Timbrado: '},
{view: 'text', id: 'token_soporte',
name: 'token_soporte', label: 'Token de Soporte: '},
]
@ -644,7 +644,7 @@ var options_templates = [
var options_pac = [
{id: 'default', value: 'Predeterminado'},
{id: 'finkok', value: 'Finkok'},
{id: 'comercio', value: 'Comercio Digital'},
]
@ -690,12 +690,26 @@ var options_admin_otros = [
{},
]},
{maxHeight: 15},
{template: 'Timbrado', type: 'section'},
{cols: [{maxWidth: 15},
{view: 'richselect', id: 'lst_pac', name: 'lst_pac', width: 300,
label: 'PAC: ', value: 'default', required: false,
options: options_pac}, {view: 'label', label: 'NO cambies este valor, a menos que se te haya indicado'},
label: 'PAC: ', value: '', required: true,
labelAlign: 'right', options: options_pac}, {view: 'label',
label: ' NO cambies este valor, a menos que se te haya indicado'},
]},
{cols: [{maxWidth: 15},
{view: 'text', id: 'user_timbrado', name: 'user_timbrado',
label: 'Usuario: ', labelAlign: 'right', required: true},
{view: 'text', id: 'token_timbrado', name: 'token_timbrado',
label: 'Token: ', labelAlign: 'right', required: true},
]},
{cols: [{maxWidth: 15}, {},
{view: 'button', id: 'cmd_save_pac', label: 'Guardar',
autowidth: true, type: 'form'}, {},
]},
{maxHeight: 20},
{template: 'Ayudas varias', type: 'section'},
{cols: [{maxWidth: 15},
{view: 'checkbox', id: 'chk_config_anticipo', labelWidth: 0,