Agregar RFC desde script
This commit is contained in:
parent
9376fee407
commit
3e323678d7
|
@ -13,7 +13,7 @@ class AppEmpresas(object):
|
|||
@falcon.after(get_template)
|
||||
def on_get(self, req, resp):
|
||||
values = req.params
|
||||
print ('V', values)
|
||||
# ~ print ('V', values)
|
||||
resp.status = falcon.HTTP_200
|
||||
|
||||
def on_post(self, req, resp):
|
||||
|
|
|
@ -1541,6 +1541,27 @@ def _backup_and_sync(rfc, data):
|
|||
return
|
||||
|
||||
|
||||
@run_in_thread
|
||||
def _backup_companies():
|
||||
_, filename = os.path.split(COMPANIES)
|
||||
if SEAFILE_SERVER:
|
||||
msg = '\tSincronizando backup RFCs...'
|
||||
log.info(msg)
|
||||
seafile = SeaFileAPI(
|
||||
SEAFILE_SERVER['URL'],
|
||||
SEAFILE_SERVER['USER'],
|
||||
SEAFILE_SERVER['PASS'])
|
||||
|
||||
if seafile.is_connect:
|
||||
msg = '\tSincronizando: {} '.format(filename)
|
||||
log.info(msg)
|
||||
seafile.update_file(
|
||||
COMPANIES, SEAFILE_SERVER['REPO'], '/', SEAFILE_SERVER['PASS'])
|
||||
msg = '\tRespaldo general de {} sincronizado'.format(filename)
|
||||
log.info(msg)
|
||||
return
|
||||
|
||||
|
||||
def backup_dbs():
|
||||
con = sqlite3.connect(COMPANIES)
|
||||
cursor = con.cursor()
|
||||
|
@ -1556,6 +1577,7 @@ def backup_dbs():
|
|||
args = loads(data)
|
||||
_backup_and_sync(rfc, args)
|
||||
|
||||
_backup_companies()
|
||||
return
|
||||
|
||||
|
||||
|
@ -1683,12 +1705,12 @@ class ImportFacturaLibreGambas(object):
|
|||
('cfdifacturas', 'Facturas'),
|
||||
('categorias', 'Categorias'),
|
||||
('productos', 'Productos'),
|
||||
('tickets', 'Tickets'),
|
||||
# ~ ('tickets', 'Tickets'),
|
||||
)
|
||||
for source, target in tables:
|
||||
data[target] = self._get_table(source)
|
||||
|
||||
data['Socios'] += self._clientes
|
||||
# ~ data['Socios'] += self._clientes
|
||||
|
||||
return data
|
||||
|
||||
|
@ -1714,7 +1736,11 @@ class ImportFacturaLibreGambas(object):
|
|||
('vendedor', 'vendedor'),
|
||||
)
|
||||
data = []
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tImportando ticket {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
|
||||
new = {t: row[s] for s, t in fields}
|
||||
|
||||
new['notas'] = ''
|
||||
|
@ -1799,13 +1825,24 @@ class ImportFacturaLibreGambas(object):
|
|||
|
||||
def _productos(self):
|
||||
UNIDADES = {
|
||||
'k': 'KGM',
|
||||
'kg': 'KGM',
|
||||
'kg.': 'KGM',
|
||||
'pieza': 'H87',
|
||||
'pza': 'H87',
|
||||
'pz': 'H87',
|
||||
'bulto': 'H87',
|
||||
'b': 'H87',
|
||||
'exb': 'H87',
|
||||
'ex': 'H87',
|
||||
'caja': 'XBX',
|
||||
'c': 'XBX',
|
||||
'rollo': 'XRO',
|
||||
'tira': 'SR',
|
||||
't': 'SR',
|
||||
'cono': 'XAJ',
|
||||
'paquete': 'XPK',
|
||||
'pq': 'XPK',
|
||||
}
|
||||
sql = "SELECT * FROM productos"
|
||||
self._cursor.execute(sql)
|
||||
|
@ -1831,13 +1868,25 @@ class ImportFacturaLibreGambas(object):
|
|||
FROM impuestos
|
||||
WHERE id=%s
|
||||
"""
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tImportando producto {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
|
||||
new = {t: row[s] for s, t in fields}
|
||||
|
||||
u = new['unidad'].lower().strip()
|
||||
if u in ('sin',):
|
||||
continue
|
||||
if not u:
|
||||
u = 'pieza'
|
||||
|
||||
if not new['categoria']:
|
||||
new['categoria'] = None
|
||||
new['descripcion'] = ' '.join(new['descripcion'].split())
|
||||
new['clave_sat'] = DEFAULT_SAT_PRODUCTO
|
||||
new['unidad'] = UNIDADES.get(new['unidad'].lower(), new['unidad'])
|
||||
|
||||
new['unidad'] = UNIDADES.get(u, new['unidad'])
|
||||
self._cursor.execute(sql, [row['id_impuesto1']])
|
||||
impuestos = self._cursor.fetchall()
|
||||
new['impuestos'] = tuple(impuestos)
|
||||
|
@ -2003,7 +2052,11 @@ class ImportFacturaLibreGambas(object):
|
|||
('cancelada', 'cancelada'),
|
||||
)
|
||||
data = []
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tImportando factura {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
|
||||
new = {t: row[s] for s, t in fields}
|
||||
|
||||
for _, f in fields:
|
||||
|
@ -2063,7 +2116,10 @@ class ImportFacturaLibreGambas(object):
|
|||
|
||||
sql1 = "SELECT correo FROM correos WHERE id_padre=%s"
|
||||
sql2 = "SELECT telefono FROM telefonos WHERE id_padre=%s"
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tImportando cliente {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
new = {t: row[s] for s, t in fields}
|
||||
new['slug'] = to_slug(new['nombre'])
|
||||
new['es_cliente'] = True
|
||||
|
|
|
@ -4721,7 +4721,7 @@ def _iniciar_bd():
|
|||
return
|
||||
|
||||
|
||||
def _agregar_rfc():
|
||||
def _agregar_rfc(no_bd):
|
||||
rfc = input('Introduce el nuevo RFC: ').strip().upper()
|
||||
if not rfc:
|
||||
msg = 'El RFC es requerido'
|
||||
|
@ -4741,7 +4741,11 @@ def _agregar_rfc():
|
|||
|
||||
args = opt.copy()
|
||||
if conectar(args):
|
||||
if _add_emisor(rfc, util.dumps(opt)) and _crear_tablas(rfc):
|
||||
if _add_emisor(rfc, util.dumps(opt)):
|
||||
if no_bd:
|
||||
log.info('RFC agregado correctamente...')
|
||||
return
|
||||
_crear_tablas(rfc)
|
||||
log.info('RFC agregado correctamente...')
|
||||
return
|
||||
|
||||
|
@ -4860,7 +4864,10 @@ def _importar_valores(archivo='', rfc=''):
|
|||
|
||||
def _importar_socios(rows):
|
||||
log.info('\tImportando Clientes...')
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tGuardando cliente {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
try:
|
||||
with database_proxy.atomic() as txn:
|
||||
Socios.create(**row)
|
||||
|
@ -4883,7 +4890,11 @@ def _existe_factura(row):
|
|||
|
||||
def _importar_facturas(rows):
|
||||
log.info('\tImportando Facturas...')
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tGuardando factura {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
|
||||
try:
|
||||
detalles = row.pop('detalles')
|
||||
impuestos = row.pop('impuestos')
|
||||
|
@ -5171,7 +5182,11 @@ def _importar_productos_gambas(rows):
|
|||
'IVA': '002',
|
||||
}
|
||||
|
||||
for row in rows:
|
||||
totals = len(rows)
|
||||
for i, row in enumerate(rows):
|
||||
msg = '\tGuardando producto {} de {}'.format(i+1, totals)
|
||||
log.info(msg)
|
||||
|
||||
source_taxes = row.pop('impuestos')
|
||||
row['unidad'] = SATUnidades.get(SATUnidades.key==row['unidad'])
|
||||
taxes = []
|
||||
|
@ -5307,7 +5322,7 @@ help_lr = 'Listar RFCs'
|
|||
is_flag=True, default=False)
|
||||
@click.option('-cc', '--cambiar-contraseña', help=help_change_pass,
|
||||
is_flag=True, default=False)
|
||||
@click.option('-rfc', '--rfc', help=help_rfc, is_flag=True, default=False)
|
||||
@click.option('-ar', '--agregar-rfc', help=help_rfc, is_flag=True, default=False)
|
||||
@click.option('-br', '--borrar-rfc', help=help_br, is_flag=True, default=False)
|
||||
@click.option('-lr', '--listar-rfc', help=help_lr, is_flag=True, default=False)
|
||||
@click.option('-i', '--importar-valores', is_flag=True, default=False)
|
||||
|
@ -5319,10 +5334,13 @@ help_lr = 'Listar RFCs'
|
|||
@click.option('-gap', '--generar-archivo-productos', is_flag=True, default=False)
|
||||
@click.option('-ip', '--importar-productos', is_flag=True, default=False)
|
||||
@click.option('-bk', '--backup-dbs', is_flag=True, default=False)
|
||||
def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña, rfc,
|
||||
borrar_rfc, listar_rfc, importar_valores, archivo, conexion, factura_libre,
|
||||
factura_libre_gambas, test, generar_archivo_productos, importar_productos,
|
||||
backup_dbs):
|
||||
@click.option('-n', '--no-bd', is_flag=True, default=False)
|
||||
@click.option('-a', '--alta', is_flag=True, default=False)
|
||||
@click.option('-r', '--rfc')
|
||||
def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña,
|
||||
agregar_rfc, borrar_rfc, listar_rfc, importar_valores, archivo, conexion,
|
||||
factura_libre, factura_libre_gambas, test, generar_archivo_productos,
|
||||
importar_productos, backup_dbs, no_bd, alta, rfc):
|
||||
|
||||
opt = locals()
|
||||
|
||||
|
@ -5330,6 +5348,13 @@ def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña, rfc,
|
|||
_test()
|
||||
sys.exit(0)
|
||||
|
||||
if opt['alta']:
|
||||
if not opt['rfc']:
|
||||
msg = 'Falta el RFC'
|
||||
raise click.ClickException(msg)
|
||||
empresa_agregar(opt['rfc'])
|
||||
sys.exit(0)
|
||||
|
||||
if opt['iniciar_bd']:
|
||||
_iniciar_bd()
|
||||
sys.exit(0)
|
||||
|
@ -5346,8 +5371,8 @@ def main(iniciar_bd, migrar_bd, nuevo_superusuario, cambiar_contraseña, rfc,
|
|||
_cambiar_contraseña()
|
||||
sys.exit(0)
|
||||
|
||||
if opt['rfc']:
|
||||
_agregar_rfc()
|
||||
if opt['agregar_rfc']:
|
||||
_agregar_rfc(no_bd)
|
||||
sys.exit(0)
|
||||
|
||||
if opt['borrar_rfc']:
|
||||
|
|
BIN
source/db/cp.db
BIN
source/db/cp.db
Binary file not shown.
|
@ -20,15 +20,18 @@
|
|||
{
|
||||
"tabla": "SATUnidades",
|
||||
"datos": [
|
||||
{"key": "HUR", "name": "Hora", "activo": true},
|
||||
{"key": "H87", "name": "Pieza", "activo": true},
|
||||
{"key": "E48", "name": "Servicio", "activo": true},
|
||||
{"key": "E51", "name": "Trabajo", "activo": false},
|
||||
{"key": "ACT", "name": "Actividad", "activo": false},
|
||||
{"key": "KGM", "name": "Kilogramo", "activo": false},
|
||||
{"key": "XBX", "name": "Caja", "activo": false},
|
||||
{"key": "XAJ", "name": "Cono", "activo": false},
|
||||
{"key": "HUR", "name": "Hora", "activo": true},
|
||||
{"key": "KGM", "name": "Kilogramo", "activo": false},
|
||||
{"key": "MTR", "name": "Metro", "activo": false},
|
||||
{"key": "XPK", "name": "Paquete", "activo": false},
|
||||
{"key": "H87", "name": "Pieza", "activo": true},
|
||||
{"key": "XRO", "name": "Rollo", "activo": false},
|
||||
{"key": "MTR", "name": "Metro", "activo": false}
|
||||
{"key": "E48", "name": "Servicio", "activo": true},
|
||||
{"key": "SR", "name": "Tira", "activo": false},
|
||||
{"key": "E51", "name": "Trabajo", "activo": false}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@ var products_controllers = {
|
|||
}
|
||||
|
||||
|
||||
function configurar_productos(){
|
||||
function configurar_productos(is_new){
|
||||
webix.ajax().get('/config', {'fields': 'productos'}, {
|
||||
error: function(text, data, xhr) {
|
||||
msg = 'Error al consultar'
|
||||
|
@ -29,7 +29,9 @@ function configurar_productos(){
|
|||
show('codigo_barras', values.chk_config_codigo_barras)
|
||||
show('precio_con_impuestos', values.chk_config_precio_con_impuestos)
|
||||
$$('unidad').setValue(values.default_unidad)
|
||||
$$('grid_product_taxes').select(values.default_tax)
|
||||
if(is_new){
|
||||
$$('grid_product_taxes').select(values.default_tax)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -44,12 +46,12 @@ function get_categorias(){
|
|||
|
||||
|
||||
function cmd_new_product_click(id, e, node){
|
||||
configurar_productos()
|
||||
get_taxes()
|
||||
configurar_productos(true)
|
||||
$$('form_product').setValues({
|
||||
id: 0, es_activo_producto: true})
|
||||
add_config({'key': 'id_product', 'value': ''})
|
||||
get_new_key()
|
||||
get_taxes()
|
||||
get_categorias()
|
||||
$$('grid_products').clearSelection()
|
||||
$$('unidad').getList().load('/values/unidades')
|
||||
|
@ -58,7 +60,8 @@ function cmd_new_product_click(id, e, node){
|
|||
|
||||
|
||||
function cmd_edit_product_click(){
|
||||
configurar_productos()
|
||||
get_taxes()
|
||||
configurar_productos(false)
|
||||
var grid = $$('grid_products')
|
||||
var row = grid.getSelectedItem()
|
||||
if(row == undefined){
|
||||
|
@ -66,7 +69,6 @@ function cmd_edit_product_click(){
|
|||
return
|
||||
}
|
||||
|
||||
get_taxes()
|
||||
$$('categoria').getList().load('/values/categorias')
|
||||
$$('unidad').getList().load('/values/unidades')
|
||||
|
||||
|
|
Loading…
Reference in New Issue