Soporte para diferentes emisores
This commit is contained in:
parent
e57001db56
commit
a8133a15e4
|
@ -81,3 +81,20 @@ def clean(values):
|
|||
return values
|
||||
|
||||
|
||||
def parse_con(values):
|
||||
data = values.split('|')
|
||||
try:
|
||||
con = {'type': data[0]}
|
||||
if con['type'] == 'sqlite':
|
||||
con['name'] = data[1]
|
||||
else:
|
||||
if data[1]:
|
||||
con['host'] = data[1]
|
||||
if data[2]:
|
||||
con['port'] = data[2]
|
||||
con['name'] = data[3]
|
||||
con['user'] = data[4]
|
||||
con['password'] = data[5]
|
||||
return con
|
||||
except IndexError:
|
||||
return {}
|
||||
|
|
|
@ -13,21 +13,37 @@ if __name__ == '__main__':
|
|||
|
||||
|
||||
from controllers import util
|
||||
from conf import DATABASE, __version__
|
||||
from settings import log, PATH_CP
|
||||
from settings import log, VERSION, PATH_CP, COMPANIES
|
||||
|
||||
|
||||
database = DATABASE
|
||||
database_proxy = Proxy()
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
database = database
|
||||
database = database_proxy
|
||||
|
||||
|
||||
def conectar():
|
||||
global database
|
||||
database.connect()
|
||||
log.info('Conectado a la BD...')
|
||||
return
|
||||
def conectar(opt):
|
||||
db = {
|
||||
'sqlite': SqliteDatabase,
|
||||
'postgres': PostgresqlDatabase,
|
||||
'mysql': MySQLDatabase,
|
||||
}
|
||||
db_type = opt.pop('type')
|
||||
db_name = opt.pop('name')
|
||||
if not db_type in db:
|
||||
log.error('Tipo de base de datos no soportado')
|
||||
return False
|
||||
|
||||
database = db[db_type](db_name, **opt)
|
||||
try:
|
||||
database_proxy.initialize(database)
|
||||
database_proxy.connect()
|
||||
log.info('Conectado a la BD...')
|
||||
return True
|
||||
except OperationalError as e:
|
||||
log.error('Error al intentar conectar a la base de datos')
|
||||
log.error(e)
|
||||
return False
|
||||
|
||||
|
||||
class Configuracion(BaseModel):
|
||||
|
@ -464,7 +480,7 @@ def get_cp(cp):
|
|||
|
||||
def _init_values():
|
||||
data = (
|
||||
{'key': 'version', 'value': __version__},
|
||||
{'key': 'version', 'value': VERSION},
|
||||
{'key': 'rfc_publico', 'value': 'XAXX010101000'},
|
||||
{'key': 'rfc_extranjero', 'value': 'XEXX010101000'},
|
||||
)
|
||||
|
@ -478,7 +494,16 @@ def _init_values():
|
|||
|
||||
|
||||
def _crear_tablas():
|
||||
conectar()
|
||||
rfc = input('Introduce el RFC: ').strip().upper()
|
||||
if not rfc:
|
||||
msg = 'El RFC es requerido'
|
||||
log.error(msg)
|
||||
return
|
||||
|
||||
opt = _get_con(rfc)
|
||||
if not conectar(opt):
|
||||
return
|
||||
|
||||
tablas = [Addendas, Categorias, Certificado, CondicionesPago, Configuracion,
|
||||
Emisor, Facturas, FacturasDetalle, FacturasImpuestos, Folios, Productos,
|
||||
SATAduanas, SATFormaPago, SATImpuestos, SATMonedas, SATRegimenes,
|
||||
|
@ -488,7 +513,7 @@ def _crear_tablas():
|
|||
Productos.impuestos.get_through_model(),
|
||||
Productos.tags.get_through_model(),
|
||||
]
|
||||
database.create_tables(tablas, True)
|
||||
database_proxy.create_tables(tablas, True)
|
||||
log.info('Tablas creadas correctamente...')
|
||||
return
|
||||
|
||||
|
@ -549,11 +574,37 @@ def _cambiar_contraseña():
|
|||
return
|
||||
|
||||
|
||||
def _agregar_rfc():
|
||||
rfc = input('Introduce el nuevo RFC: ').strip().upper()
|
||||
if not rfc:
|
||||
msg = 'El RFC es requerido'
|
||||
log.error(msg)
|
||||
return
|
||||
|
||||
datos = input('Introduce los datos de conexión: ').strip()
|
||||
if not datos:
|
||||
msg = 'Los datos de conexión son requeridos'
|
||||
log.error(msg)
|
||||
return
|
||||
|
||||
opt = util.parse_con(datos)
|
||||
if not opt:
|
||||
log.error('Datos de conexión incompletos')
|
||||
return
|
||||
|
||||
if conectar(opt):
|
||||
log.info('RFC agregado correctamente...')
|
||||
else:
|
||||
log.error('No se pudo agregar el RFC')
|
||||
return
|
||||
|
||||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
||||
help_create_tables = 'Crea las tablas en la base de datos'
|
||||
help_migrate_db = 'Migra las tables en la base de datos'
|
||||
help_migrate_db = 'Migra las tablas en la base de datos'
|
||||
help_superuser = 'Crea un nuevo super usuario'
|
||||
help_change_pass = 'Cambia la contraseña a un usuario'
|
||||
help_rfc = 'Agrega un nuevo RFC'
|
||||
|
||||
@click.command(context_settings=CONTEXT_SETTINGS)
|
||||
@click.option('-bd', '--iniciar-bd',help=help_create_tables,
|
||||
|
@ -564,7 +615,8 @@ help_change_pass = 'Cambia la contraseña a un usuario'
|
|||
is_flag=True, default=False)
|
||||
@click.option('-cc', '--cambiar-contraseña', help=help_change_pass,
|
||||
is_flag=True, default=False)
|
||||
def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña):
|
||||
@click.option('-rfc', '--rfc', help=help_rfc, is_flag=True, default=False)
|
||||
def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña, rfc):
|
||||
opt = locals()
|
||||
|
||||
if opt['iniciar_bd']:
|
||||
|
@ -581,6 +633,12 @@ def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña):
|
|||
|
||||
if opt['cambiar_contraseña']:
|
||||
_cambiar_contraseña()
|
||||
sys.exit(0)
|
||||
|
||||
if opt['rfc']:
|
||||
_agregar_rfc()
|
||||
sys.exit(0)
|
||||
|
||||
return
|
||||
|
||||
|
||||
|
|
|
@ -7,18 +7,17 @@ from mako.lookup import TemplateLookup
|
|||
from logbook import Logger, StreamHandler, RotatingFileHandler
|
||||
logbook.set_datetime_format('local')
|
||||
|
||||
from conf import DEBUG
|
||||
|
||||
DEBUG = True
|
||||
VERSION = '0.1.0'
|
||||
EMAIL_SUPPORT = ('soporte@empresalibre.net',)
|
||||
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
PATH_STATIC = os.path.abspath(os.path.join(BASE_DIR, '..'))
|
||||
PATH_TEMPLATES = os.path.abspath(os.path.join(BASE_DIR, '..', 'templates'))
|
||||
|
||||
EMAIL_SUPPORT = ('soporte@empresalibre.net',)
|
||||
#~ WITH_LOGIN = True
|
||||
|
||||
DB_CP = 'cp.db'
|
||||
PATH_CP = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', DB_CP))
|
||||
PATH_CP = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'cp.db'))
|
||||
COMPANIES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'rfc.db'))
|
||||
|
||||
template_lookup = TemplateLookup(directories=[PATH_TEMPLATES],
|
||||
input_encoding='utf-8',
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue