[18.0] [IMP] excel_import_export: Code for Compatibility with xlrd 2.0+ and fix date handling #3479
+100
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This update fixes a few issues we encountered when running with newer versions of xlrd (2.0 and above), which dropped support for .xlsx files. The existing fallback mechanism wasn't catching this case correctly, causing import failures in updated environments.
I've improved the file detection logic to explicitly check for the file signature (PK header), which allows us to correctly route .xlsx files to openpyxl when needed, while safely keeping the traditional xlrd behavior for legacy .xls files.
I also took the opportunity to clean up how we handle date fields. I noticed that midnight timestamps (like "2025-01-01 00:00:00") were sometimes being passed to Date fields, causing Odoo to reject the import with "unconverted data" errors. I've updated the value extraction logic to enforce the correct format based on the field type—stripping the time component for Date fields while preserving it for Datetime fields.