diff --git a/app/db/db_connection.py b/app/db/db_connection.py index f4fc1c6..437adaf 100644 --- a/app/db/db_connection.py +++ b/app/db/db_connection.py @@ -17,7 +17,7 @@ def get_factuges_connection(config) -> fdb.Connection: database=config['FACTUGES_DATABASE'], user=config['FACTUGES_USER'], password=config['FACTUGES_PASSWORD'], - charset='UTF8', + charset='ISO8859_1' ) logger.info( "Conexión a la base de datos FactuGES establecida: %s with database:%s - using user:%s", diff --git a/app/db/normalizations.py b/app/db/normalizations.py index cd5315c..b9f4c7f 100644 --- a/app/db/normalizations.py +++ b/app/db/normalizations.py @@ -17,6 +17,7 @@ from app.utils import ( normalizar_telefono_con_plus, normalizar_url_para_insert, tax_fraction_from_code, + text_converter, unscale_to_decimal, ) @@ -46,7 +47,7 @@ def normalize_customer_fields(fd: Dict[str, Any]) -> Dict[str, Any]: "is_company": config["CTE_IS_COMPANY"], "tin": clean_tin(str(fd.get("NIF_CIF"))), "name": fd.get("NOMBRE"), - "street": fd.get("CALLE"), + "street": text_converter(fd.get("CALLE")), "city": fd.get("POBLACION"), "province": fd.get("PROVINCIA"), "postal_code": fd.get("CODIGO_POSTAL"), diff --git a/app/utils/text_converter.py b/app/utils/text_converter.py index 7321cc5..79da02b 100644 --- a/app/utils/text_converter.py +++ b/app/utils/text_converter.py @@ -1,4 +1,5 @@ import re + from app.config import logger @@ -20,7 +21,7 @@ def text_converter(texto, charset_destino='ISO8859_1', longitud_maxima=None): try: # Convertir el texto al charset especificado texto_convertido = texto.encode( - charset_destino, 'ignore').decode(charset_destino) + charset_destino, 'ignore').decode("cp1252") # Si se especifica una longitud máxima, truncar el texto if longitud_maxima and len(texto_convertido) > longitud_maxima: