Skip to content

[17.0][ADD] attachment_preview_xml: preview XML attachments as a collapsible tree - #636

Open
alan196 wants to merge 1 commit into
OCA:17.0from
Jarsa-dev:17.0-add-attachment_preview_xml
Open

[17.0][ADD] attachment_preview_xml: preview XML attachments as a collapsible tree#636
alan196 wants to merge 1 commit into
OCA:17.0from
Jarsa-dev:17.0-add-attachment_preview_xml

Conversation

@alan196

@alan196 alan196 commented Aug 24, 2026

Copy link
Copy Markdown

Summary

New module that renders XML attachments in the standard file viewer as an indented, collapsible tree instead of a wall of raw text.

Context

ir.attachment._check_contents neutralizes xml-like mimetypes to text/plain for every user without write access on views, so XML attachments end up in the plain-text branch of the FileViewer. Machine-generated XML (electronic invoices such as CFDI or UBL, bank statements, EDI messages) is usually serialized on a single line, which makes that preview unreadable.

How it works

  • A JS patch on the mail Attachment model adds isXml (by extension, or by mimetype when it survives), removes those files from the isText branch and keeps them viewable.
  • XmlViewer fetches the attachment, parses it with DOMParser and renders the tree with plain <details>/<summary> elements, so collapsing is native HTML: no library, no server-side conversion, no external service.
  • Malformed XML, or content over 5 MB, falls back to the raw text instead of showing nothing.
  • No Python code and no new dependencies: the module ships assets only.

Test plan

  • QUnit tests on the parser (hierarchy, attributes, comments, text-only nodes, malformed input), run in CI through an HttpCase that loads the module suite in a real browser.
  • Manually validated on 17.0 with a single-line CFDI 4.0 attached to a chatter: the tree renders and every branch collapses; a deliberately malformed XML falls back to raw text.

@OCA-git-bot OCA-git-bot added series:17.0 mod:attachment_preview_xml Module attachment_preview_xml labels Aug 24, 2026
Odoo stores XML attachments as text/plain for users without write access on
views, so the standard viewer renders them as raw text. Machine-generated XML
(CFDI, UBL, EDI) comes in a single line, which makes that preview unreadable.

Render XML attachments client-side as an indented, collapsible tree with
highlighted tags, attributes and values. No server-side conversion and no
extra software involved. Malformed or oversized files fall back to raw text.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYJ2yGZfDKKKEW3KxuG2wh
@alan196
alan196 force-pushed the 17.0-add-attachment_preview_xml branch from 415eab9 to f427873 Compare August 24, 2026 21:56
@pedrobaeza pedrobaeza added this to the 17.0 milestone Aug 25, 2026

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested on runboat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:attachment_preview_xml Module attachment_preview_xml series:17.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants