Compare commits
2 Commits
e298b1a3f0
...
ff71328bd3
| Author | SHA1 | Date | |
|---|---|---|---|
| ff71328bd3 | |||
| 9bd6cc785e |
61
app/db/sync_invoices_deleted_factuges.py
Normal file
61
app/db/sync_invoices_deleted_factuges.py
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
from app.config import load_config, logger
|
||||
|
||||
from . import sql_sentences as SQL
|
||||
|
||||
|
||||
def sync_invoices_deleted_factuges(conn_factuges, conn_mysql, last_execution_date):
|
||||
config = load_config()
|
||||
|
||||
# LIMPIAMOS LAS FACTURAS DE FACTUGES QUE HAYAN SIDO ELIMINADAS DEL PROGRAMA NUEVO DE FACTURACION, PARA QUE PUEDAN SER MODIFICADAS
|
||||
# Crear un cursor para ejecutar consultas SQL
|
||||
cursor_mysql = None
|
||||
try:
|
||||
cursor_mysql = conn_mysql.cursor()
|
||||
cursor_mysql.execute(SQL.SELECT_INVOICES_DELETED)
|
||||
filas = cursor_mysql.fetchall()
|
||||
cursor_mysql.close()
|
||||
|
||||
# Crear un conjunto con los IDs [0] de los customer_inovices que debo liberar en FactuGES, porque han sido eliminadas en programa de facturación nuevo
|
||||
ids_verifactu_deleted = {str(fila[0]) for fila in filas}
|
||||
# logger.info(f"Customer invoices rows to be deleted: {len(ids_verifactu_deleted)}")
|
||||
# Verificar si hay filas en el resultado
|
||||
if ids_verifactu_deleted:
|
||||
sync_delete_invoices(conn_factuges, ids_verifactu_deleted, config)
|
||||
else:
|
||||
logger.info("There are NOT customer invoices deleted since the last run")
|
||||
|
||||
except Exception as e:
|
||||
if cursor_mysql is not None:
|
||||
cursor_mysql.close()
|
||||
logger.error(
|
||||
f"(ERROR) Failed to fetch from database:{config['FWEB_MYSQL_DATABASE']} - using user:{config['FWEB_MYSQL_USER']}"
|
||||
)
|
||||
logger.error(e)
|
||||
raise e
|
||||
|
||||
|
||||
def sync_delete_invoices(conn_factuges, ids_verifactu_deleted, config):
|
||||
# Eliminamos todos los IDs asociados en FactuGES que han sido eliminados así liberaremos la factura borrador y podermos modificarla de nuevo, para volverla a subir una vez hechos los cambios.
|
||||
# VERIFACTU = 0 and ID_VERIFACTU = NULL
|
||||
cursor_FactuGES = None
|
||||
try:
|
||||
cursor_FactuGES = conn_factuges.cursor()
|
||||
if ids_verifactu_deleted:
|
||||
logger.info(f"Liberate factuGES: {ids_verifactu_deleted}")
|
||||
cursor_FactuGES.executemany(
|
||||
SQL.LIMPIAR_FACTUGES_LINK,
|
||||
[(id_verifactu,) for id_verifactu in ids_verifactu_deleted],
|
||||
)
|
||||
else:
|
||||
logger.info("No articles to delete.")
|
||||
|
||||
except Exception as e:
|
||||
# Escribir el error en el archivo de errores
|
||||
logger.error(str(e))
|
||||
raise e # Re-lanzar la excepción para detener el procesamiento
|
||||
finally:
|
||||
# Cerrar la conexión
|
||||
if cursor_FactuGES is not None:
|
||||
cursor_FactuGES.close()
|
||||
@ -5,7 +5,12 @@ from pathlib import Path
|
||||
from dateutil import tz
|
||||
|
||||
from app.config import create_logger, get_package_version, load_config, log_config
|
||||
from app.db import get_factuges_connection, get_mysql_connection, sync_invoices_factuges
|
||||
from app.db import (
|
||||
get_factuges_connection,
|
||||
get_mysql_connection,
|
||||
sync_invoices_deleted_factuges,
|
||||
sync_invoices_factuges,
|
||||
)
|
||||
from app.utils import actualizar_fecha_ultima_ejecucion, obtener_fecha_ultima_ejecucion
|
||||
|
||||
|
||||
@ -57,6 +62,7 @@ def main():
|
||||
# Sincronizamos
|
||||
logger.info(
|
||||
">>>>>>>>>>> INI Sync invoices FactuGES escritorio to FactuGES web")
|
||||
sync_invoices_deleted_factuges(conn_factuges, conn_mysql, last_execution_date_local_tz)
|
||||
sync_invoices_factuges(conn_factuges, conn_mysql, last_execution_date_local_tz)
|
||||
|
||||
# Confirmar los cambios
|
||||
|
||||
Loading…
Reference in New Issue
Block a user