From 1227e5895617015ad476fd2e3e1cf5484cc9c9cd Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Fri, 3 Nov 2017 22:23:15 -0600 Subject: [PATCH] Administrar impuestos --- source/app/models/db.py | 6 ++++ source/app/models/main.py | 28 ++++++++++++++- source/static/js/controller/admin.js | 32 +++++++++++++++++ source/static/js/ui/admin.js | 54 +++++++++++++++++++++++++++- 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/source/app/models/db.py b/source/app/models/db.py index 83fd200..dc4138e 100644 --- a/source/app/models/db.py +++ b/source/app/models/db.py @@ -71,6 +71,12 @@ class StorageEngine(object): def _get_taxes(self, values): return main.SATImpuestos.get_activos() + def _get_alltaxes(self, values): + return main.SATImpuestos.get_() + + def _get_taxupdate(self, values): + return main.SATImpuestos.actualizar(values) + def _get_satkey(self, values): return main.get_sat_key(values['key']) diff --git a/source/app/models/main.py b/source/app/models/main.py index aa434aa..b4039f2 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -617,11 +617,37 @@ class SATImpuestos(BaseModel): (('key', 'factor', 'tipo', 'tasa'), True), ) + @classmethod + def get_(self): + rows = SATImpuestos.select().dicts() + return tuple(rows) + @classmethod def get_activos(self): rows = SATImpuestos.select().where(SATImpuestos.activo==True).dicts() return tuple(rows) + @classmethod + def actualizar(self, values): + id = int(values['id']) + if values['field'] == 'activo': + v = {'0': False, '1': True} + q = (SATImpuestos + .update(**{'activo': v[values['value']]}) + .where(SATImpuestos.id==id)) + result = bool(q.execute()) + elif values['field'] == 'default': + q = SATImpuestos.update(**{'default': False}) + q.execute() + + v = {'false': False, 'true': True} + q = (SATImpuestos + .update(**{'default': v[values['value']]}) + .where(SATImpuestos.id==id)) + result = bool(q.execute()) + + return {'ok': result} + class SATTipoRelacion(BaseModel): key = TextField(index=True, unique=True) @@ -816,7 +842,7 @@ class Socios(BaseModel): def actualizar(cls, values, id): fields = cls._clean(cls, values) try: - print (fields) + #~ print (fields) q = Socios.update(**fields).where(Socios.id==id) q.execute() except IntegrityError: diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 7c2933b..1f6036f 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -20,6 +20,8 @@ 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) + //~ SAT + $$('grid_admin_taxes').attachEvent('onCheck', grid_admin_taxes_on_check) //~ Opciones tb_options = $$('tab_options').getTabbar() tb_options.attachEvent('onChange', tab_options_change) @@ -202,6 +204,15 @@ function get_config_correo(){ } +function get_admin_impuestos(){ + webix.ajax().sync().get('/values/alltaxes', function(text, data){ + var values = data.json() + $$("grid_admin_taxes").clearAll() + $$("grid_admin_taxes").parse(values, 'json') + }) +} + + function get_config_values(opt){ if(opt == undefined){ return @@ -241,6 +252,11 @@ function multi_admin_change(prevID, nextID){ return } + if(nextID == 'app_sat'){ + get_admin_impuestos() + return + } + if(nextID == 'app_options'){ get_config_values('templates') return @@ -684,3 +700,19 @@ function tab_options_change(nv, ov){ } get_config_values(cv[nv]) } + + +function grid_admin_taxes_on_check(row, column, state){ + + var values = { + id: row, + field: column, + value: state, + } + webix.ajax().get('/values/taxupdate', values, { + error: function(text, data, xhr) { + }, + success: function(text, data, xhr) { + } + }) +} diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index ca4610f..18afdee 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -365,6 +365,57 @@ var tab_options = { } +var grid_admin_taxes_cols = [ + {id: 'id', header: 'ID', hidden: true}, + {id: 'name', header: 'Nombre'}, + {id: 'tipo', header: 'Tipo'}, + {id: 'tasa', header: 'Tasa'}, + {id: 'activo', header: 'Activo', template: '{common.checkbox()}', + editor: 'checkbox'}, + {id: 'default', header: 'Predeterminado', template: '{common.radio()}', + adjust: 'header'}, +] + + +var grid_admin_taxes = { + view: 'datatable', + id: 'grid_admin_taxes', + select: 'cell', + multiselect: true, + adjust: true, + autoheight: true, + autowidth: true, + headermenu: true, + columns: grid_admin_taxes_cols, +} + + +var msg_tax = 'Activa los impuestos que uses. El predeterminado se muestra primero' + +var sat_impuestos = [ + {maxHeight: 20}, + {cols: [{maxWidth: 15}, {view: 'label', label: msg_tax}, {}]}, + {maxHeight: 20}, + {cols: [{maxWidth: 15}, grid_admin_taxes, {}]}, +{}] + + +var tab_sat = { + view: 'tabview', + id: 'tab_sat', + multiview: true, + tabbar: {options: [ + 'Impuestos', + 'Unidades']}, + animate: true, + cells: [ + {id: 'Impuestos', rows: sat_impuestos}, + {id: 'Unidades', rows: [{}]}, + {}, + ] +} + + var app_emisor = { id: 'app_emisor', rows:[ @@ -409,7 +460,7 @@ var app_sat = { rows:[ {view: 'template', id: 'th_sat', type: 'header', template: 'Catálogos del SAT'}, - {}, + tab_sat, ] } @@ -492,3 +543,4 @@ var body_win_emisor_logo = [ {cols: [{}, {view: 'button', label: 'Cerrar', autowidth: true, click:("$$('win_emisor_logo').close();")}, {}]} ] +