[FIX] hr_expense_report_merge_attachment: handle HEIC images uploaded as JPEG #19

Open
stephansainleger wants to merge 1 commits from 14.0-heif into 14.0

Some iPhone users upload HEIC files with a .jpg extension. Odoo stores
the file as-is, but the mimetype is detected as image/..., so the code
enters the image processing branch. reportlab's ImageReader relies
on PIL.Image.open() which cannot identify HEIC files without an explicit
plugin, causing a PIL.UnidentifiedImageError and a 500 error on report
download.

Fix by:

  • Registering the pillow-heif opener at module load time (optional
    dependency, silently ignored if not installed) so that Pillow can decode
    HEIC/HEIF images.
  • Converting any image to JPEG in memory via Pillow before passing it to
    ImageReader, bypassing reportlab's own format detection entirely.
  • Wrapping the image block in a try/except to gracefully skip
    attachments that cannot be decoded, consistent with the existing PDF
    error handling.
Some iPhone users upload HEIC files with a ``.jpg`` extension. Odoo stores the file as-is, but the mimetype is detected as ``image/...``, so the code enters the image processing branch. ``reportlab``'s ``ImageReader`` relies on ``PIL.Image.open()`` which cannot identify HEIC files without an explicit plugin, causing a ``PIL.UnidentifiedImageError`` and a 500 error on report download. Fix by: - Registering the ``pillow-heif`` opener at module load time (optional dependency, silently ignored if not installed) so that Pillow can decode HEIC/HEIF images. - Converting any image to JPEG in memory via Pillow before passing it to ``ImageReader``, bypassing ``reportlab``'s own format detection entirely. - Wrapping the image block in a ``try/except`` to gracefully skip attachments that cannot be decoded, consistent with the existing PDF error handling.
stephansainleger added 1 commit 2026-05-15 11:38:31 +00:00
Some iPhone users upload HEIC files with a ``.jpg`` extension. Odoo stores
the file as-is, but the mimetype is detected as ``image/...``, so the code
enters the image processing branch. ``reportlab``'s ``ImageReader`` relies
on ``PIL.Image.open()`` which cannot identify HEIC files without an explicit
plugin, causing a ``PIL.UnidentifiedImageError`` and a 500 error on report
download.

Fix by:
- Registering the ``pillow-heif`` opener at module load time (optional
  dependency, silently ignored if not installed) so that Pillow can decode
  HEIC/HEIF images.
- Converting any image to JPEG in memory via Pillow before passing it to
  ``ImageReader``, bypassing ``reportlab``'s own format detection entirely.
- Wrapping the image block in a ``try/except`` to gracefully skip
  attachments that cannot be decoded, consistent with the existing PDF
  error handling.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 14.0-heif:14.0-heif
git checkout 14.0-heif
Sign in to join this conversation.
No description provided.