This commit is contained in:
David Arranz 2025-11-28 10:30:52 +01:00
parent 634d04dc10
commit a6545cbb2b
5 changed files with 16 additions and 21 deletions

View File

@ -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'),

View File

@ -1,6 +1,7 @@
from __future__ import print_function
import brevo_python
def setup_brevo(config):
# Configure API key authorization: api-key

View File

@ -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

View File

@ -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:

View File

@ -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}