fix: filtrar lineas de IVA (%) que se colaban como productos
This commit is contained in:
parent
385828a5db
commit
ebb634445c
|
|
@ -22,9 +22,22 @@ os.makedirs(output_dir, exist_ok=True)
|
|||
exclude_keywords = [
|
||||
"TARJETA BANCARIA", "IVA BASE IMPONIBLE", "CUOTA", "TOTAL",
|
||||
"SE ADMITEN DEVOLUCIONES CON TICKET", "N.C", "AUT", "AID",
|
||||
"Verificado por dispositivo", "Visa Credit", "IMPORTE", "TARJ. BANCARIA"
|
||||
"Verificado por dispositivo", "Visa Credit", "IMPORTE", "TARJ. BANCARIA",
|
||||
"BASES IMPONIBLES", "BASE IMPONIBLE", "BASE CUOTA", "SUMA",
|
||||
"EFECTIVO", "CAMBIO", "MASTERCARD", "MERCADONA", "TICKET",
|
||||
]
|
||||
|
||||
# Nombre de producto que indica línea de IVA (p.ej. "%", "% 125,30")
|
||||
def _es_producto_invalido(nombre: str) -> bool:
|
||||
n = nombre.strip()
|
||||
return (
|
||||
not n
|
||||
or n.startswith("%")
|
||||
or n == "%"
|
||||
or re.match(r'^%', n)
|
||||
or len(n) < 2
|
||||
)
|
||||
|
||||
def extract_data_from_pdf(file_path):
|
||||
reader = PdfReader(file_path)
|
||||
text = ""
|
||||
|
|
@ -56,6 +69,7 @@ def extract_data_from_pdf(file_path):
|
|||
if name_m:
|
||||
cantidad = int(name_m.group(1))
|
||||
producto = name_m.group(2).strip().upper()
|
||||
if not _es_producto_invalido(producto):
|
||||
precio_total = float(weight_m.group(1).replace(",", "."))
|
||||
products.append((fecha, cantidad, producto,
|
||||
round(precio_total / cantidad, 2), precio_total))
|
||||
|
|
@ -70,6 +84,7 @@ def extract_data_from_pdf(file_path):
|
|||
producto = m.group(2).strip().upper()
|
||||
precio_unitario = float(m.group(3).replace(",", "."))
|
||||
precio_total = float(m.group(4).replace(",", "."))
|
||||
if not _es_producto_invalido(producto):
|
||||
products.append((fecha, cantidad, producto, precio_unitario, precio_total))
|
||||
i += 1
|
||||
continue
|
||||
|
|
@ -83,6 +98,7 @@ def extract_data_from_pdf(file_path):
|
|||
cantidad = int(m.group(1))
|
||||
producto = m.group(2).strip().upper()
|
||||
precio_total = float(m.group(3).replace(",", "."))
|
||||
if not _es_producto_invalido(producto):
|
||||
products.append((fecha, cantidad, producto,
|
||||
round(precio_total / cantidad, 2), precio_total))
|
||||
i += 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue