From a6545cbb2b09a727e3eb2e0f5b303e5d56624980 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 28 Nov 2025 10:30:52 +0100 Subject: [PATCH] . --- app/config/settings.py | 3 ++- app/config/setup_brevo.py | 3 ++- app/db/sync_invoices_factuges.py | 17 +++++++++-------- app/db/sync_invoices_verifactu.py | 12 ++---------- app/utils/send_rest_api.py | 2 +- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/config/settings.py b/app/config/settings.py index 73045d1..59a8179 100644 --- a/app/config/settings.py +++ b/app/config/settings.py @@ -33,7 +33,8 @@ def load_config(): 'CTE_LANGUAGE_CODE': os.getenv('CTE_LANGUAGE_CODE'), 'CTE_COUNTRY_CODE': os.getenv('CTE_COUNTRY_CODE'), 'CTE_IS_COMPANY': os.getenv('CTE_IS_COMPANY'), - + 'CTE_SYNC_RESULT_OK': os.getenv('CTE_SYNC_RESULT_OK'), + 'CTE_SYNC_RESULT_FAIL': os.getenv('CTE_SYNC_RESULT_FAIL'), 'VERIFACTU_BASE_URL': os.getenv('VERIFACTU_BASE_URL'), 'VERIFACTU_API_KEY': os.getenv('VERIFACTU_API_KEY'), diff --git a/app/config/setup_brevo.py b/app/config/setup_brevo.py index d9d2db0..fe48f4e 100644 --- a/app/config/setup_brevo.py +++ b/app/config/setup_brevo.py @@ -1,10 +1,11 @@ from __future__ import print_function import brevo_python + def setup_brevo(config): # Configure API key authorization: api-key configuration = brevo_python.Configuration() - configuration.api_key['api-key'] = config['BREVO_API_KEY'] + configuration.api_key['api-key'] = config['BREVO_API_KEY'] return configuration diff --git a/app/db/sync_invoices_factuges.py b/app/db/sync_invoices_factuges.py index 0043208..4b6865b 100644 --- a/app/db/sync_invoices_factuges.py +++ b/app/db/sync_invoices_factuges.py @@ -124,7 +124,8 @@ def sync_invoices_from_FACTUGES(conn_mysql, filas, conn_factuges, config): if factuges_id_anterior is None or factuges_id_anterior != factuges_id: # Validamos que el cif de la factura exista en la AEAT si no es así no se hace la sincro de la factura - sync_result = 1 + sync_result = int(config['CTE_SYNC_RESULT_OK']) + sync_notes = None customer_valid = validar_nif(customer_fields["tin"], customer_fields["name"], config) if customer_valid: # Comprobamos si existe el cliente del primer item de la factura @@ -158,16 +159,16 @@ def sync_invoices_from_FACTUGES(conn_mysql, filas, conn_factuges, config): cursorMySQL, header_invoice_fields, invoice_id, config) else: - sync_result = 2 - cadena = (f">>> Factura {header_invoice_fields['reference']} no cumple requisitos para ser mandada a Verifactu: " - f">>>>>> El NIF/NOMBRE ({customer_fields['tin']}/{customer_fields['name']}) no está registrado en la AEAT. " - f"El NIF/CIF debe estar registrado en la AEAT y el nombre debe ser suficientemente parecido al nombre registrado en la AEAT") - logging.info(cadena) + sync_result = int(config['CTE_SYNC_RESULT_FAIL']) + sync_notes = (f">>> Factura {header_invoice_fields['reference']} no cumple requisitos para ser mandada a Verifactu: " + f">>>>>> El NIF/NOMBRE ({customer_fields['tin']}/{customer_fields['name']}) no está registrado en la AEAT. " + f"El NIF/CIF debe estar registrado en la AEAT y el nombre debe ser suficientemente parecido al nombre registrado en la AEAT") + logging.info(sync_notes) # Guardamos en Factuges el id de la customer_invoice logging.info( - f"Updating FACTURAS_CLIENTE {sync_result} {invoice_id} {factuges_id} {cadena}") - cursor_FactuGES.execute(SQL.UPDATE_FACTUGES_LINK, (sync_result, invoice_id, cadena, factuges_id)) + f"Updating FACTURAS_CLIENTE {sync_result} {invoice_id} {factuges_id} {sync_notes}") + cursor_FactuGES.execute(SQL.UPDATE_FACTUGES_LINK, (sync_result, invoice_id, sync_notes, factuges_id)) num_fac_procesed += 1 # Insertamos detalles y taxes correspondientes siempre que hayamos insertado cabecera diff --git a/app/db/sync_invoices_verifactu.py b/app/db/sync_invoices_verifactu.py index 19fe09c..5d69be3 100644 --- a/app/db/sync_invoices_verifactu.py +++ b/app/db/sync_invoices_verifactu.py @@ -63,25 +63,17 @@ def enviar_datos(invoices_to_verifactu, cursor_mysql, config): ok, respuesta = preparar_factura(fila) if not ok: logging.info( - f">>> Factura {fila['reference']} no cumple requisitos para ser mandada a Verifactu:") + f"ERROR >>>>>> Factura {fila['reference']} no cumple requisitos para ser mandada a Verifactu:") logging.info( f">>>>>> Faltan campos requeridos: {respuesta}") factura = None continue - factura = respuesta - # Validamos que el cif de la factura exista en la AEAT si no es así no se hace el envío - if not validar_nif(factura.get('nif'), factura.get('nombre'), config): - logging.info( - f">>> Factura {factura.get('reference')} no cumple requisitos para ser mandada a Verifactu:") - logging.info( - f">>>>>> El cif de la factura no existe en AEAT: {factura.get('nif')}") - continue ok, linea = preparar_linea(fila) if not ok: logging.info( - f">>> Factura {factura.get('reference')} no cumple requisitos para ser mandada a Verifactu:") + f"ERROR >>>>>> Factura {factura.get('reference')} no cumple requisitos para ser mandada a Verifactu:") logging.info(f">>>>>> Faltan campos requeridos: {linea}") factura = None else: diff --git a/app/utils/send_rest_api.py b/app/utils/send_rest_api.py index 2bc5775..be3165f 100644 --- a/app/utils/send_rest_api.py +++ b/app/utils/send_rest_api.py @@ -83,7 +83,7 @@ def crear_factura(payload, if resp.status_code == 200: try: data = resp.json() - logging.info(data) + # logging.info(data) except ValueError: return {"ok": False, "status": 200, "error": "Respuesta 200 sin JSON válido", "raw": resp.text} return {"ok": True, "status": 200, "data": data}