Skip to content

[FIX] account_statement_import_sheet_file_bg: handle OpenPyXL Cell values in sheet header parsing#395

Closed
rov-adhoc wants to merge 1 commit into
ingadhoc:18.0from
adhoc-dev:18.0-h-114683-rov
Closed

[FIX] account_statement_import_sheet_file_bg: handle OpenPyXL Cell values in sheet header parsing#395
rov-adhoc wants to merge 1 commit into
ingadhoc:18.0from
adhoc-dev:18.0-h-114683-rov

Conversation

@rov-adhoc

Copy link
Copy Markdown
Contributor

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

Copilot AI review requested due to automatic review settings April 9, 2026 12:27
@roboadhoc

Copy link
Copy Markdown
Contributor

Pull request status dashboard

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() en account.statement.import.sheet.parser para convertir valores/celdas a string de forma segura antes de aplicar strip().

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.

Comment on lines +23 to +27
[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 "")

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
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]

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)]

Copilot uses AI. Check for mistakes.
@rov-adhoc

Copy link
Copy Markdown
Contributor Author

@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
@rov-adhoc rov-adhoc force-pushed the 18.0-h-114683-rov branch from 2562dcc to e6eecd7 Compare April 9, 2026 13:54
@maq-adhoc

Copy link
Copy Markdown
Contributor

@roboadhoc r+ nobump

roboadhoc pushed a commit that referenced this pull request Apr 9, 2026
…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>
@roboadhoc roboadhoc closed this Apr 9, 2026
@roboadhoc roboadhoc deleted the 18.0-h-114683-rov branch April 9, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants