Skip to content

[ADD] account_statement_import_sheet_file_ux: preview the file a mapping expects - #439

Open
feg-adhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-71587-feg
Open

[ADD] account_statement_import_sheet_file_ux: preview the file a mapping expects#439
feg-adhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-71587-feg

Conversation

@feg-adhoc

Copy link
Copy Markdown
Contributor

Most of the support around the statement sheet import comes from mappings that do not describe the file the bank exports: a renamed header, a header row on the wrong line, the thousands separator the other way around. The error the user gets back ('Date' is not in list) says nothing about which part of the mapping is wrong.

Rather than keep patching account_statement_import_sheet_file, this adds account_statement_import_sheet_file_ux, which auto installs with it.

What it adds

  • Preview Mapping button on the sheet mapping. Renders a sample sheet — column letters, row numbers, header in bold, ignored rows greyed out — built from the mapping as it is configured right now, with three sample transactions filled in so the layout is unambiguous.
  • Downloadable xlsx of that same sample. Every cell is written as text, the way the parser reads them, so the sample file can be imported with that very mapping to check it end to end.
  • The preview reads the mapping back in plain words (date format, separators, ignored rows and columns, whether the column order matters) and warns about configurations that are going to fail: a header row number of 0 (the spreadsheet parser then reads the header row as a transaction too and the import fails), or column names on a mapping declared as having no header line.
  • Failed imports raise a RedirectWarning that keeps the original error, names the mapping and the column that is missing (or the date format that does not match), and offers a button that opens the mapping.
  • Column names are matched ignoring case and padding, so a bank that exports DATE one month and Date the next does not break the import.
  • Header lines skip count is renamed to Header row number with a help that explains what the number means, and the amount columns are cleared when the Amount type changes.

Notes on the approach

  • The preview follows what the parser actually does rather than what the field help claims: the header sits on max(header_lines_skip_count, 1) and the transactions start right after header_lines_skip_count.
  • Ignored rows carry a label so that they exist in the exported file and the row numbers do not shift.
  • _get_column_indexes rewrites the header cells that match a configured name to the configured spelling and delegates to the standard lookup, instead of duplicating it. An unknown column still raises.
  • The redirect action of the failed import is built inline rather than pointing at a preview record, because the failed transaction is rolled back and any record created in that path would be gone by the time the user clicks.
  • Depends on the xls and xlsx modules with auto_install triggered by the base one, so a database that can import csv statements can also import spreadsheets.

Test plan

17 tests, all green:

  • The header row lands where the parser looks for it for 0, 1, 2 and 5, and 0 produces the warning.
  • Offset columns, footer rows, concatenated columns, the three amount types, no_header with indexes, no_header misconfigured with names, the none decimal separator and the inverse sign all render the expected cells.
  • The generated sample is parsed back with its own mapping and yields the three expected amounts, for the four amount types and with footer rows.
  • A failed import names the missing column and the mapping, a wrong date format names the format, and an import without a mapping is left alone.

Manual check pending in runbot for the visual side (button placement and modal rendering).

Task: https://www.adhoc.inc/odoo/project.task/71587

…ing expects

Most of the support around the statement sheet import comes from mappings
that do not describe the file the bank exports, and the error the user gets
back ('Date' is not in list) says nothing about which part of the mapping is
wrong.

Adds a "Preview Mapping" button on the sheet mapping that renders a sample
sheet, with column letters and row numbers, built from the mapping as it is
configured: where the header row must be, which columns must exist, and how
dates and amounts must be written, with three sample transactions filled in.
The sample can be downloaded as xlsx; every cell is written as text, the way
the parser reads them, so the file can be imported with that very mapping to
check it end to end.

The preview also reads the mapping back in plain words and warns about the
configurations that are going to fail, and a failed import now names the
mapping and the missing column (or the date format that does not match) and
offers a button that opens the mapping.

Carries the remaining fixes as an extension instead of patching the base
module: case and padding insensitive column matching, the decimal cast the
xls parser needs, a clearer name and help for the header row number, and
clearing the amount columns when the amount type changes. Depends on the xls
and xlsx modules and auto installs with the base one, so a database that can
import csv statements can also import spreadsheets.
Copilot AI lite review requested due to automatic review settings August 21, 2026 20:48

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 incorpora el nuevo módulo account_statement_import_sheet_file_ux para mejorar la experiencia de configuración e importación de extractos bancarios en planillas (xls/xlsx), agregando previsualización del archivo esperado, generación de un sample importable y errores de importación más accionables para guiar al usuario hacia la corrección del mapping.

Changes:

  • Agrega un wizard de “Mapping preview” que renderiza un sample visual (HTML) y permite descargar un xlsx consistente con el mapping.
  • Mejora la importación: ante fallas de parseo, eleva un RedirectWarning con contexto (mapping/columna/formato) y acceso directo al mapping.
  • Ajusta el comportamiento del parser y del mapping: matching de columnas case/trim-insensitive, parseo de decimales desde números crudos, rename de “header lines skip count” a “Header row number”, y limpieza de columnas al cambiar el Amount type.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
account_statement_import_sheet_file_ux/init.py Inicializa el módulo cargando models y wizard.
account_statement_import_sheet_file_ux/manifest.py Declara el módulo, dependencias y data (vistas + ACL).
account_statement_import_sheet_file_ux/README.rst Documenta funcionalidad, uso y notas técnicas del módulo UX.
account_statement_import_sheet_file_ux/i18n/account_statement_import_sheet_file_ux.pot Template de traducciones para los nuevos textos (Python y QWeb).
account_statement_import_sheet_file_ux/security/ir.model.access.csv ACL para el wizard de preview.
account_statement_import_sheet_file_ux/models/init.py Exporta los overrides del mapping y del parser.
account_statement_import_sheet_file_ux/models/account_statement_import_sheet_mapping.py Implementa preview layout/notes/warnings, botón de preview y mejoras UX del mapping.
account_statement_import_sheet_file_ux/models/account_statement_import_sheet_parser.py Hace el matching de headers case/trim-insensitive y acepta números crudos en _parse_decimal.
account_statement_import_sheet_file_ux/wizard/init.py Registra los wizards nuevos/extendidos.
account_statement_import_sheet_file_ux/wizard/account_statement_import.py Override de _parse_file para re-lanzar errores como RedirectWarning con hint accionable.
account_statement_import_sheet_file_ux/wizard/account_statement_import_sheet_mapping_preview.py Wizard que renderiza el HTML y genera/descarga el xlsx sample.
account_statement_import_sheet_file_ux/views/account_statement_import_sheet_mapping_views.xml Inserta el botón “Preview Mapping” en la vista del mapping.
account_statement_import_sheet_file_ux/views/account_statement_import_sheet_mapping_preview_views.xml QWeb template del preview + vista form del wizard con botón de descarga.
account_statement_import_sheet_file_ux/tests/init.py Habilita la carga del suite de tests del módulo.
account_statement_import_sheet_file_ux/tests/test_mapping_preview.py Cobertura de preview/layout, sample importable, parser fixes y RedirectWarning en imports fallidos.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants