From 7fc1d42381f2cbfeff2a4f26f5a37dbfb2121c72 Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Sun, 8 Aug 2021 21:51:12 -0500 Subject: [PATCH] Set branch by user --- source/app/models/main.py | 22 ++++++++++++++++++++++ source/static/js/controller/admin.js | 26 +++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/source/app/models/main.py b/source/app/models/main.py index b0c3291..aab1d25 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -3482,6 +3482,15 @@ class Sucursales(BaseModel): ) return tuple(rows) + @classmethod + def _get_for_select(cls, args): + fields = ( + Sucursales.id, + Sucursales.nombre.alias('value') + ) + rows = Sucursales.select(*fields).dicts() + return tuple(rows) + @classmethod def _get_there_are_branchs(cls, args): result = bool(Sucursales.select().count()) @@ -3573,6 +3582,19 @@ class Usuarios(BaseModel): response = {'ok': result} return response + @classmethod + def _set_branch(cls, args, user): + id = args['id_user'] + values = {'sucursal': args['id_branch']} + where = (Usuarios.id == id) + q = (Usuarios + .update(**values) + .where(where) + ) + result = bool(q.execute()) + response = {'ok': result} + return response + @classmethod def post(cls, values, user): opt = values['opt'] diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 34f3b7c..774eb0d 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -2061,7 +2061,10 @@ function set_user_branch(id, state){ if(state){ win_set_branch_user.init() $$('txt_user_id').setValue(id) - //~ $$('txt_user_name').setValue(id) + webix.ajax().get('/sucursales?opt=for_select', function(text, data){ + var values = data.json() + $$('lst_branchs').getList().parse(values) + }) $$('win_set_branch_user').show() }else{ var args = { @@ -2088,7 +2091,28 @@ function set_user_branch(id, state){ function cmd_set_branch_user_save_click(){ + var id_user = $$('txt_user_id').getValue() + var id_branch = $$('lst_branchs').getValue() + $$('win_set_branch_user').hide() + var args = { + opt: 'set_branch', + values: {id_user: id_user, id_branch: id_branch} + } + webix.ajax().post('/users', args, { + error:function(text, data, XmlHttpRequest){ + msg = 'Ocurrio un error, consulta a soporte técnico' + msg_error(msg) + }, + success:function(text, data, XmlHttpRequest){ + var values = data.json() + if(values.ok){ + msg_ok('Asignación de Sucursal establecida correctamente') + }else{ + msg_error(values.msg) + } + } + }) }