.
This commit is contained in:
parent
634d04dc10
commit
a6545cbb2b
@ -33,7 +33,8 @@ def load_config():
|
|||||||
'CTE_LANGUAGE_CODE': os.getenv('CTE_LANGUAGE_CODE'),
|
'CTE_LANGUAGE_CODE': os.getenv('CTE_LANGUAGE_CODE'),
|
||||||
'CTE_COUNTRY_CODE': os.getenv('CTE_COUNTRY_CODE'),
|
'CTE_COUNTRY_CODE': os.getenv('CTE_COUNTRY_CODE'),
|
||||||
'CTE_IS_COMPANY': os.getenv('CTE_IS_COMPANY'),
|
'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_BASE_URL': os.getenv('VERIFACTU_BASE_URL'),
|
||||||
'VERIFACTU_API_KEY': os.getenv('VERIFACTU_API_KEY'),
|
'VERIFACTU_API_KEY': os.getenv('VERIFACTU_API_KEY'),
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import brevo_python
|
import brevo_python
|
||||||
|
|
||||||
|
|
||||||
def setup_brevo(config):
|
def setup_brevo(config):
|
||||||
|
|
||||||
# Configure API key authorization: api-key
|
# Configure API key authorization: api-key
|
||||||
configuration = brevo_python.Configuration()
|
configuration = brevo_python.Configuration()
|
||||||
configuration.api_key['api-key'] = config['BREVO_API_KEY']
|
configuration.api_key['api-key'] = config['BREVO_API_KEY']
|
||||||
|
|
||||||
return configuration
|
return configuration
|
||||||
|
|||||||
@ -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:
|
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
|
# 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)
|
customer_valid = validar_nif(customer_fields["tin"], customer_fields["name"], config)
|
||||||
if customer_valid:
|
if customer_valid:
|
||||||
# Comprobamos si existe el cliente del primer item de la factura
|
# 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)
|
cursorMySQL, header_invoice_fields, invoice_id, config)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sync_result = 2
|
sync_result = int(config['CTE_SYNC_RESULT_FAIL'])
|
||||||
cadena = (f">>> Factura {header_invoice_fields['reference']} no cumple requisitos para ser mandada a Verifactu: "
|
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/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")
|
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)
|
logging.info(sync_notes)
|
||||||
|
|
||||||
# Guardamos en Factuges el id de la customer_invoice
|
# Guardamos en Factuges el id de la customer_invoice
|
||||||
logging.info(
|
logging.info(
|
||||||
f"Updating FACTURAS_CLIENTE {sync_result} {invoice_id} {factuges_id} {cadena}")
|
f"Updating FACTURAS_CLIENTE {sync_result} {invoice_id} {factuges_id} {sync_notes}")
|
||||||
cursor_FactuGES.execute(SQL.UPDATE_FACTUGES_LINK, (sync_result, invoice_id, cadena, factuges_id))
|
cursor_FactuGES.execute(SQL.UPDATE_FACTUGES_LINK, (sync_result, invoice_id, sync_notes, factuges_id))
|
||||||
num_fac_procesed += 1
|
num_fac_procesed += 1
|
||||||
|
|
||||||
# Insertamos detalles y taxes correspondientes siempre que hayamos insertado cabecera
|
# Insertamos detalles y taxes correspondientes siempre que hayamos insertado cabecera
|
||||||
|
|||||||
@ -63,25 +63,17 @@ def enviar_datos(invoices_to_verifactu, cursor_mysql, config):
|
|||||||
ok, respuesta = preparar_factura(fila)
|
ok, respuesta = preparar_factura(fila)
|
||||||
if not ok:
|
if not ok:
|
||||||
logging.info(
|
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(
|
logging.info(
|
||||||
f">>>>>> Faltan campos requeridos: {respuesta}")
|
f">>>>>> Faltan campos requeridos: {respuesta}")
|
||||||
factura = None
|
factura = None
|
||||||
continue
|
continue
|
||||||
|
|
||||||
factura = respuesta
|
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)
|
ok, linea = preparar_linea(fila)
|
||||||
if not ok:
|
if not ok:
|
||||||
logging.info(
|
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}")
|
logging.info(f">>>>>> Faltan campos requeridos: {linea}")
|
||||||
factura = None
|
factura = None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -83,7 +83,7 @@ def crear_factura(payload,
|
|||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
try:
|
try:
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
logging.info(data)
|
# logging.info(data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return {"ok": False, "status": 200, "error": "Respuesta 200 sin JSON válido", "raw": resp.text}
|
return {"ok": False, "status": 200, "error": "Respuesta 200 sin JSON válido", "raw": resp.text}
|
||||||
return {"ok": True, "status": 200, "data": data}
|
return {"ok": True, "status": 200, "data": data}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user