Convertir caracteres no válidos a ISO8859_1 al leer desde FactuGES
This commit is contained in:
parent
ef315b1479
commit
fbd294098d
@ -17,7 +17,7 @@ def get_factuges_connection(config) -> fdb.Connection:
|
|||||||
database=config['FACTUGES_DATABASE'],
|
database=config['FACTUGES_DATABASE'],
|
||||||
user=config['FACTUGES_USER'],
|
user=config['FACTUGES_USER'],
|
||||||
password=config['FACTUGES_PASSWORD'],
|
password=config['FACTUGES_PASSWORD'],
|
||||||
charset='UTF8',
|
charset='ISO8859_1'
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Conexión a la base de datos FactuGES establecida: %s with database:%s - using user:%s",
|
"Conexión a la base de datos FactuGES establecida: %s with database:%s - using user:%s",
|
||||||
|
|||||||
@ -17,6 +17,7 @@ from app.utils import (
|
|||||||
normalizar_telefono_con_plus,
|
normalizar_telefono_con_plus,
|
||||||
normalizar_url_para_insert,
|
normalizar_url_para_insert,
|
||||||
tax_fraction_from_code,
|
tax_fraction_from_code,
|
||||||
|
text_converter,
|
||||||
unscale_to_decimal,
|
unscale_to_decimal,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ def normalize_customer_fields(fd: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
"is_company": config["CTE_IS_COMPANY"],
|
"is_company": config["CTE_IS_COMPANY"],
|
||||||
"tin": clean_tin(str(fd.get("NIF_CIF"))),
|
"tin": clean_tin(str(fd.get("NIF_CIF"))),
|
||||||
"name": fd.get("NOMBRE"),
|
"name": fd.get("NOMBRE"),
|
||||||
"street": fd.get("CALLE"),
|
"street": text_converter(fd.get("CALLE")),
|
||||||
"city": fd.get("POBLACION"),
|
"city": fd.get("POBLACION"),
|
||||||
"province": fd.get("PROVINCIA"),
|
"province": fd.get("PROVINCIA"),
|
||||||
"postal_code": fd.get("CODIGO_POSTAL"),
|
"postal_code": fd.get("CODIGO_POSTAL"),
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from app.config import logger
|
from app.config import logger
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ def text_converter(texto, charset_destino='ISO8859_1', longitud_maxima=None):
|
|||||||
try:
|
try:
|
||||||
# Convertir el texto al charset especificado
|
# Convertir el texto al charset especificado
|
||||||
texto_convertido = texto.encode(
|
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
|
# Si se especifica una longitud máxima, truncar el texto
|
||||||
if longitud_maxima and len(texto_convertido) > longitud_maxima:
|
if longitud_maxima and len(texto_convertido) > longitud_maxima:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user