diff --git a/CHANGELOG.md b/CHANGELOG.md index d015638..115142f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +v 1.2.0 [18-Dic-2017] +--------------------- +* IMPORTANTE: Es necesario actualizar la base de datos, despues de actualizar la rama principal. + +``` +git pull origin master + +cd source/app/models + +python main.py -bd +``` + + v 0.1.0 [26-Oct-2017] --------------------- - Generar y timbrar con CFDI 3.3 diff --git a/source/app/controllers/main.py b/source/app/controllers/main.py index 5300200..6cca2f6 100644 --- a/source/app/controllers/main.py +++ b/source/app/controllers/main.py @@ -125,6 +125,8 @@ class AppValues(object): req.context['result'] = self._db.send_email(values, session) elif table == 'enviarprefac': req.context['result'] = self._db.enviar_prefac(values) + elif table == 'addmoneda': + req.context['result'] = self._db.add_moneda(values) elif table == 'addunidad': req.context['result'] = self._db.add_unidad(values) elif table == 'addimpuesto': diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 2440e98..035e88f 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -173,6 +173,25 @@ def get_sat_key(table, key): return {'ok': True, 'text': data[1]} +def get_sat_monedas(key): + con = sqlite3.connect(DB_SAT) + con.row_factory = sqlite3.Row + cursor = con.cursor() + + filtro = '%{}%'.format(key) + sql = "SELECT * FROM monedas WHERE key LIKE ? OR name LIKE ?" + + cursor.execute(sql, [filtro, filtro]) + data = cursor.fetchall() + cursor.close() + con.close() + if data is None: + return () + + data = [dict(r) for r in data] + return tuple(data) + + def get_sat_unidades(key): con = sqlite3.connect(DB_SAT) con.row_factory = sqlite3.Row diff --git a/source/app/main.py b/source/app/main.py index 3063849..7398382 100644 --- a/source/app/main.py +++ b/source/app/main.py @@ -56,7 +56,7 @@ api.add_route('/movbanco', AppMovimientosBanco(db)) session_options = { 'session.type': 'file', - 'session.cookie_expires': 3600, + 'session.cookie_expires': True, 'session.data_dir': '/tmp/cache/data', 'session.lock_dir': '/tmp/cache/lock', } diff --git a/source/app/models/db.py b/source/app/models/db.py index c2b74f2..303ca61 100644 --- a/source/app/models/db.py +++ b/source/app/models/db.py @@ -104,6 +104,9 @@ class StorageEngine(object): def _get_unidades(self, values): return main.SATUnidades.get_activos() + def add_moneda(self, values): + return main.SATMonedas.add(values) + def add_unidad(self, values): return main.SATUnidades.add(values) @@ -161,6 +164,9 @@ class StorageEngine(object): def _get_satkey(self, values): return main.get_sat_key(values['key']) + def _get_satmonedas(self, values): + return main.get_sat_monedas(values['key']) + def _get_satunidades(self, values): return main.get_sat_unidades(values['key']) diff --git a/source/app/models/main.py b/source/app/models/main.py index 3015961..7ff1479 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -940,6 +940,14 @@ class SATMonedas(BaseModel): def __str__(self): return 'Moneda: ({}) {}'.format(self.key, self.name) + @classmethod + def add(self, values): + try: + SATMonedas.create(**values) + return {'ok': True} + except: + return {'ok': False} + @classmethod def get_(self): rows = SATMonedas.select().dicts() @@ -3901,9 +3909,14 @@ def get_sat_key(key): return util.get_sat_key('productos', key) +def get_sat_monedas(key): + return util.get_sat_monedas(key) + + def get_sat_unidades(key): return util.get_sat_unidades(key) + def get_sat_productos(key): return util.get_sat_productos(key) diff --git a/source/db/sat.db b/source/db/sat.db index 8bc71a8..3ee5899 100644 Binary files a/source/db/sat.db and b/source/db/sat.db differ diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 27a9f75..52bd83a 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -34,6 +34,7 @@ var controllers = { $$('grid_admin_unidades').attachEvent('onCheck', grid_admin_unidades_on_check) $$('grid_admin_formasdepago').attachEvent('onCheck', grid_admin_formasdepago_on_check) $$('grid_unidad_found').attachEvent('onValueSuggest', grid_unidad_found_click) + $$('grid_moneda_found').attachEvent('onValueSuggest', grid_moneda_found_click) $$('cmd_agregar_impuesto').attachEvent('onItemClick', cmd_agregar_impuesto_click) //~ Usuarios $$('cmd_usuario_agregar').attachEvent('onItemClick', cmd_usuario_agregar_click) @@ -1131,6 +1132,44 @@ function cmd_emisor_agregar_cuenta_click(){ } +function agregar_nueva_moneda(obj){ + var grid = $$('grid_admin_monedas') + var values = {key: obj.key, name: obj.name} + + webix.ajax().post('/values/addmoneda', values, { + error: function(text, data, xhr) { + webix.message({type: 'error', text: 'Error al agregar'}) + }, + success: function(text, data, xhr){ + var values = data.json() + if (values.ok){ + grid.add(obj) + } + } + }) +} + + +function grid_moneda_found_click(obj){ + msg = '¿Estás seguro de agregar la siguiente moneda?

' + msg += '(' + obj.key + ') ' + obj.name + + webix.confirm({ + title: 'Agregar Moneda', + ok: 'Si', + cancel: 'No', + type: 'confirm-error', + text: msg, + callback:function(result){ + if(result){ + agregar_nueva_moneda(obj) + } + } + }) + $$('buscar_nueva_moneda').setValue('') +} + + function agregar_nueva_unidad(obj){ var grid = $$('grid_admin_unidades') var values = {key: obj.key, name: obj.name} diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index 20a2a77..3578bb3 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -695,11 +695,49 @@ var sat_impuestos = [ {}] +var suggest_sat_moneda = { + view: 'gridsuggest', + id: 'grid_moneda_found', + name: 'grid_moneda_found', + body: { + autoConfig: false, + scroll:true, + autoheight:false, + header: true, + yCount: 10, + columns: [ + {id: 'id', hidden: true}, + {id: 'key', adjust: 'data', header: 'Clave'}, + {id: 'name', adjust: 'data', header: 'Moneda'}, + ], + dataFeed:function(text){ + if (text.length > 2){ + this.load('/values/satmonedas?key=' + text) + }else{ + this.hide() + } + } + }, +} + + +var buscar_nueva_moneda = { + view: 'search', + id: 'buscar_nueva_moneda', + label: 'Buscar Moneda en el catálogo del SAT', + labelPosition: 'top', + suggest: suggest_sat_moneda, + placeholder: 'Por clave o moneda. Captura al menos tres letras', +} + + var msg_moneda = 'Activa las monedas que uses. La predeterminada se muestra primero' var sat_monedas = [ {maxHeight: 20}, {cols: [{maxWidth: 15}, {view: 'label', label: msg_moneda}, {}]}, {maxHeight: 20}, + {cols: [{maxWidth: 15}, buscar_nueva_moneda, {}]}, + {maxHeight: 20}, {cols: [{maxWidth: 15}, grid_admin_monedas, {}]}, {}]