Skip to content

[18.0][IMP] excel_import_export: read dates typed as text with the language date format - #4

Open
mileo wants to merge 5 commits into
18.0from
18.0-imp-excel_import_export-br-date
Open

mileo wants to merge 5 commits into
18.0from
18.0-imp-excel_import_export-br-date

Conversation

@mileo

@mileo mileo commented Nov 28, 2026

Copy link
Copy Markdown
Member

Depends on: OCA#3479
Test coverage of the changed lines: 100.0%

Contexto

OCA#3479 fixes the cells that Excel stores as real dates (they become %Y-%m-%d). It does not cover a date typed as text in the sheet, such as 25/12/2025, which is very common in spreadsheets sent by suppliers and customers: the text is passed on as is and the import rejects it, because the standard load only accepts ISO dates.

O que muda

  • _get_cell_value takes an optional date_format. For date and datetime fields, a text cell is parsed with that format (and with the time HH:MM or HH:MM:SS after it) and converted to the ISO string the import expects. Text that does not match the format is kept as it was, so ISO text and invalid values behave as before.
  • xlsx.import passes the date format of the language of the user (res.lang.date_format), so a user in pt_BR can type 25/12/2025 and one in en_US 12/25/2025.
  • The date handling of [18.0] [IMP] excel_import_export: Code for Compatibility with xlrd 2.0+ and fix date handling OCA/server-tools#3479 is moved to a helper (_get_date_cell_value) to keep the function below the complexity limit of the pre-commit, with the same behavior.

For datetime fields the converted value goes to the standard import, which decides the time zone, as it already does for any other datetime.

Como testar (passo a passo na base de demonstração)

The module has no demo module in 18.0, so the check uses a template made by hand:

  1. Install excel_import_export and set the language of the user to Portuguese (Brazil).
  2. In Settings > Technical > Excel Import/Export > XLSX Templates, create a template for a model with a date field (for example Contact, field Date of Birth if available, or any model with a date) with an import instruction such as {"__IMPORT__": {"Sheet1": {"_HEAD_": {"B2": "name", "B3": "<date field>"}}}}.
  3. Fill a sheet with a name in B2 and a date typed as text (25/12/2025, in a cell formatted as text) in B3, and import it with the template.
  4. The record is created with the date 25 December 2025. Without this change the text is passed on as typed, which the standard load does not accept as a date.
  5. With the language set to English (US), the same cell must be typed 12/25/2025.

Testes automatizados

tests/test_text_date.py (new): text date and datetime with the language format, text kept when it does not match, no conversion without a format, and the date format taken from the language of the user. 5 tests, no failures.

BhaveshHeliconia and others added 5 commits July 17, 2026 13:24
… date format

Cells holding a date as text (e.g. 25/12/2025) were passed on as is and rejected by the import, which only accepts ISO dates. When the field is a date or datetime, the text is now parsed with the date format of the user's language and converted to ISO. Real date cells (handled by the previous commit) and text that does not match the format keep their behavior.
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

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