From a641024a86efb83a5b76983dee79e01f9a53425d Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Wed, 22 Jan 2020 12:48:15 -0600 Subject: [PATCH] Select Pac in admin --- CHANGELOG.md | 7 ++- .../app/controllers/comercio/conf.py.example | 40 ++++++++++++++++ source/app/models/main.py | 30 +++++++----- source/static/js/controller/admin.js | 36 +++++++++++++- source/static/js/controller/util.js | 9 ++++ source/static/js/ui/admin.js | 47 +++++++++++++------ 6 files changed, 141 insertions(+), 28 deletions(-) create mode 100644 source/app/controllers/comercio/conf.py.example diff --git a/CHANGELOG.md b/CHANGELOG.md index b3de097..f2c5570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,17 @@ v 1.33.0 [22-ene-2020] - Mejora: Cambio del mensaje para cuando se intenta dar de alta un cliente ya existente. - Mejora: Solo los admins pueden ver la nómina. - Se agrega un segundo PAC - - Se actualizan los catalogos del SAT + - Se actualizan los catálogos del SAT * IMPORTANTE: -Es necesario actualizar los catalogos del SAT +Es necesario actualizar los catálogos del SAT ``` git pull origin master + cd source/app/models + python main.py -bk + python main.py -us ``` diff --git a/source/app/controllers/comercio/conf.py.example b/source/app/controllers/comercio/conf.py.example new file mode 100644 index 0000000..4e89d68 --- /dev/null +++ b/source/app/controllers/comercio/conf.py.example @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# ~ +# ~ PAC +# ~ Copyright (C) 2018-2019 Mauricio Baeza Servin - public [AT] elmau [DOT] net +# ~ +# ~ This program is free software: you can redistribute it and/or modify +# ~ it under the terms of the GNU General Public License as published by +# ~ the Free Software Foundation, either version 3 of the License, or +# ~ (at your option) any later version. +# ~ +# ~ This program is distributed in the hope that it will be useful, +# ~ but WITHOUT ANY WARRANTY; without even the implied warranty of +# ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# ~ GNU General Public License for more details. +# ~ +# ~ You should have received a copy of the GNU General Public License +# ~ along with this program. If not, see . + + +# ~ Siempre consulta la documentación de Finkok +# ~ AUTH = Puedes usar credenciales genericas para timbrar, o exclusivas para +# ~ cada emisor +# ~ RESELLER = Algunos procesos como agregar emisores, solo pueden ser usadas +# ~ con una cuenta de reseller + + +DEBUG = True + + +AUTH = { + 'user': '', + 'pass': '', +} + + +if DEBUG: + AUTH = { + 'user': 'AAA010101AAA', + 'pass': 'PWD', + } diff --git a/source/app/models/main.py b/source/app/models/main.py index 1d43452..7555088 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -19,7 +19,6 @@ import argparse from decimal import Decimal import sqlite3 -# ~ import click from peewee import * from playhouse.fields import PasswordField, ManyToManyField from playhouse.shortcuts import case, SQL, cast @@ -432,6 +431,7 @@ class Configuracion(BaseModel): 'chk_config_pagos', 'chk_config_divisas', 'chk_cfg_pays_data_bank', + 'chk_usar_nomina', ) data = (Configuracion .select() @@ -440,6 +440,9 @@ class Configuracion(BaseModel): values = {r.clave: util.get_bool(r.valor) for r in data} fields = ( + 'txt_ticket_printer', + 'txt_config_nomina_serie', + 'txt_config_nomina_folio', 'txt_config_cfdipay_serie', 'txt_config_cfdipay_folio', ) @@ -481,6 +484,17 @@ class Configuracion(BaseModel): values = {r.clave: util.get_bool(r.valor) for r in data} return values + @classmethod + def get_value(cls, key, default=''): + value = default + data = (Configuracion + .select(Configuracion.valor) + .where(Configuracion.clave == key) + ) + if data: + value = data[0].valor + return value + @classmethod def get_(cls, keys): if isinstance(keys, str): @@ -541,7 +555,6 @@ class Configuracion(BaseModel): 'chk_ticket_direct_print', 'chk_ticket_edit_cant', 'chk_ticket_total_up', - 'chk_usar_nomina', ) data = (Configuracion .select() @@ -549,15 +562,10 @@ class Configuracion(BaseModel): ) values = {r.clave: util.get_bool(r.valor) for r in data} fields = ( - 'txt_ticket_printer', - 'txt_config_nomina_serie', - 'txt_config_nomina_folio', - 'txt_config_cfdipay_serie', - 'txt_config_cfdipay_folio', + ('lst_pac', 'default'), ) - # ~ tp = 'txt_ticket_printer' - for f in fields: - values[f] = Configuracion.get_(f) + for k, d in fields: + values[k] = Configuracion.get_value(k, d) return values if keys['fields'] == 'path_cer': @@ -5000,7 +5008,7 @@ class Facturas(BaseModel): obj.save() enviar_correo = util.get_bool(Configuracion.get_('correo_directo')) - pac = Configuracion.get_('pac').lower() + pac = Configuracion.get_('lst_pac').lower() anticipo = False msg = 'Factura timbrada correctamente' diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 650b713..73597a4 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -120,6 +120,7 @@ var controllers = { $$('txt_config_cfdipay_serie').attachEvent('onKeyPress', txt_config_cfdipay_serie_press) $$('txt_config_cfdipay_folio').attachEvent('onKeyPress', txt_config_cfdipay_folio_press) $$('chk_usar_nomina').attachEvent('onItemClick', chk_config_item_click) + $$('lst_pac').attachEvent('onChange', lst_pac_on_change) $$('cmd_subir_bdfl').attachEvent('onItemClick', cmd_subir_bdfl_click) $$('cmd_subir_cfdixml').attachEvent('onItemClick', cmd_subir_cfdixml_click) @@ -464,7 +465,11 @@ function get_config_values(opt){ success: function(text, data, xhr) { var values = data.json() Object.keys(values).forEach(function(key){ - $$(key).setValue(values[key]) + if(key=='lst_pac'){ + set_value(key, values[key]) + }else{ + $$(key).setValue(values[key]) + } }) } }) @@ -2534,3 +2539,32 @@ 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) + } + } + }) + } +} diff --git a/source/static/js/controller/util.js b/source/static/js/controller/util.js index e74b00e..9150608 100644 --- a/source/static/js/controller/util.js +++ b/source/static/js/controller/util.js @@ -579,3 +579,12 @@ function lst_clear(lst){ function lst_parse(lst, values){ lst.getList().parse(values) } + + +function set_value(control, value){ + obj = $$(control) + obj.blockEvent() + obj.setValue(value) + obj.unblockEvent() +} + diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index da12a80..4affa44 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -643,6 +643,12 @@ var options_templates = [ {}] +var options_pac = [ + {id: 'default', value: 'Predeterminado'}, + {id: 'comercio', value: 'Comercio Digital'}, +] + + var options_admin_otros = [ {maxHeight: 15}, {template: 'Facturación', type: 'section'}, @@ -674,6 +680,13 @@ var options_admin_otros = [ {view: 'checkbox', id: 'chk_config_decimales_precios', labelWidth: 0, labelRight: 'Precios con 4 decimales'}, {}, ]}, + {maxHeight: 15}, + {cols: [{maxWidth: 15}, + {view: 'richselect', id: 'lst_pac', name: 'lst_pac', width: 300, + label: 'PAC: ', value: 'default', required: false, + options: options_pac}, + {}, + ]}, {maxHeight: 20}, {template: 'Ayudas varias', type: 'section'}, {cols: [{maxWidth: 15}, @@ -700,15 +713,6 @@ var options_admin_otros = [ labelRight: 'Mostrar total arriba'}, {}]}, {maxHeight: 20}, - {template: 'Nómina', type: 'section'}, - {cols: [{maxWidth: 15}, - {view: 'checkbox', id: 'chk_usar_nomina', labelWidth: 0, - labelRight: 'Usar timbrado de Nómina'}, - {view: 'text', id: 'txt_config_nomina_serie', name: 'config_nomina_serie', - label: 'Serie', labelWidth: 50, labelAlign: 'right'}, - {view: 'text', id: 'txt_config_nomina_folio', name: 'config_nomina_folio', - label: 'Folio', labelWidth: 50, labelAlign: 'right'}, - {}]}, {}] @@ -738,12 +742,15 @@ var options_admin_products = [ var options_admin_complements = [ {maxHeight: 20}, + {template: 'Complemento de Nómina', type: 'section'}, {cols: [{maxWidth: 15}, - {view: 'checkbox', id: 'chk_config_ine', labelWidth: 0, - labelRight: 'Usar el complemento INE'}, - {view: 'checkbox', id: 'chk_config_edu', labelWidth: 0, - labelRight: 'Usar el complemento EDU'}, - {}]}, + {view: 'checkbox', id: 'chk_usar_nomina', labelWidth: 0, + labelRight: 'Usar complemento de Nómina'}, + {view: 'text', id: 'txt_config_nomina_serie', name: 'config_nomina_serie', + label: 'Serie', labelWidth: 50, labelAlign: 'right'}, + {view: 'text', id: 'txt_config_nomina_folio', name: 'config_nomina_folio', + label: 'Folio', labelWidth: 50, labelAlign: 'right'}, + {maxWidth: 15}]}, {maxHeight: 20}, {template: 'Complemento de Pagos', type: 'section'}, {cols: [{maxWidth: 15}, @@ -762,6 +769,18 @@ var options_admin_complements = [ {view: 'checkbox', id: 'chk_config_divisas', labelWidth: 0, labelRight: 'Usar complemento de divisas'}, {maxWidth: 15}]}, + {maxHeight: 20}, + {template: 'Complemento INE', type: 'section'}, + {cols: [{maxWidth: 15}, + {view: 'checkbox', id: 'chk_config_ine', labelWidth: 0, + labelRight: 'Usar el complemento INE'}, + {maxWidth: 15}]}, + {maxHeight: 20}, + {template: 'Complemento para escuelas EDU', type: 'section'}, + {cols: [{maxWidth: 15}, + {view: 'checkbox', id: 'chk_config_edu', labelWidth: 0, + labelRight: 'Usar el complemento EDU'}, + {maxWidth: 15}]}, ]