[FIX] account_statement_import_sheet_file_bg: handle OpenPyXL Cell values in sheet header parsing#395
[FIX] account_statement_import_sheet_file_bg: handle OpenPyXL Cell values in sheet header parsing#395rov-adhoc wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Este PR evita un crash al importar XLSX cuando el parser de encabezados recibe objetos openpyxl.cell.Cell (sin .strip()), normalizando los valores del header y de las filas para que el flujo sea consistente con CSV/XLS.
Changes:
- Normaliza las filas leídas desde OpenPyXL a valores “plain” (
cell.value) durante el split de XLSX. - Ajusta el filtrado de filas por fecha para soportar tanto valores directos como objetos con atributo
.value. - Añade un override de
parse_header()enaccount.statement.import.sheet.parserpara convertir valores/celdas a string de forma segura antes de aplicarstrip().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| account_statement_import_sheet_file_bg/models/account_statement_import.py | Normaliza filas XLSX a valores y evita accesos directos a .value en filtrado. |
| account_statement_import_sheet_file_bg/models/account_statement_import_sheet_parser.py | Override de parse_header() para tolerar celdas OpenPyXL y valores no-string. |
| account_statement_import_sheet_file_bg/models/init.py | Carga el nuevo modelo parser override. |
| [next(csv_or_xlsx) for _i in range(header_line)] | ||
| header = [] | ||
| for value in next(csv_or_xlsx): | ||
| raw_value = value.value if hasattr(value, "value") else value | ||
| header.append(str(raw_value).strip() if raw_value is not None else "") |
There was a problem hiding this comment.
En parse_header(), el salto de líneas usa una list comprehension solo por efectos laterales, creando una lista innecesaria. Además, si header_lines_skip_count excede las filas disponibles, next(csv_or_xlsx) va a lanzar StopIteration y romper el import; conviene iterar con un for y capturar StopIteration para devolver un error de usuario más claro (o [] si corresponde).
| all_rows = list(input_worksheet.rows) | ||
| # Normalize rows to plain values to keep parser/output logic | ||
| # consistent with CSV/xls flows. | ||
| all_rows = [[cell.value for cell in row] for row in input_worksheet.rows] |
There was a problem hiding this comment.
Para XLSX, en vez de iterar input_worksheet.rows y extraer cell.value manualmente, se puede usar input_worksheet.iter_rows(values_only=True) (y opcionalmente filtrar filas totalmente vacías como en CSV) para reducir overhead/memoria en archivos grandes y mantener el comportamiento más consistente.
| all_rows = [[cell.value for cell in row] for row in input_worksheet.rows] | |
| all_rows = [list(row) for row in input_worksheet.iter_rows(values_only=True)] |
|
@roboadhoc nobump |
…lues in sheet header parsing Prevent crash when importing XLSX files where header rows are iterated as OpenPyXL Cell objects instead of plain strings. add parser override in miscellaneous module to normalize header values support both raw strings and Cell instances before calling strip keep OCA module untouched as required preserve existing behavior for CSV/XLS flows Fixes: AttributeError: 'Cell' object has no attribute 'strip' Alternative (more concise) title: fix: normalize XLSX header cells before strip in bg statement import
2562dcc to
e6eecd7
Compare
|
@roboadhoc r+ nobump |
…lues in sheet header parsing Prevent crash when importing XLSX files where header rows are iterated as OpenPyXL Cell objects instead of plain strings. add parser override in miscellaneous module to normalize header values support both raw strings and Cell instances before calling strip keep OCA module untouched as required preserve existing behavior for CSV/XLS flows Fixes: AttributeError: 'Cell' object has no attribute 'strip' Alternative (more concise) title: closes #395 Fix: normalize XLSX header cells before strip in bg statement import Signed-off-by: Filoquin adhoc <maq@adhoc.com.ar>

Prevent crash when importing XLSX files where header rows are iterated as OpenPyXL Cell objects instead of plain strings.
add parser override in miscellaneous module to normalize header values support both raw strings and Cell instances before calling strip keep OCA module untouched as required
preserve existing behavior for CSV/XLS flows
Fixes:
AttributeError: 'Cell' object has no attribute 'strip'
Alternative (more concise) title:
fix: normalize XLSX header cells before strip in bg statement import