Skip to content

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Mar 5, 2025

Steps to reproduce:

  • Create a new invoice
  • Attach a ZIP file then a PDF file
  • The file viewer shows but tries to preview the ZIP file
  • Happens with all non-viewable files

Cause:

The ZIP file is put as main attachment and the method register_as_main_attachment only change the main attachment (with force=False) when there is no main attachment.

The behavior of the file viewer is problematic because we cannot switch between the attachments in the preview, so we cannot see the PDF. But if we add another PDF file (so one ZIP and 2 PDFs), we can switch but it will never show the ZIP again, only the two PDFs. This behavior is due to the next/previous arrows being displayed only if attachmentsInWebClientView contains more than one item. But this list only contains viewable attachments (PDF or Images), and the next/previous arrows only take attachments from this list. As the arrows are changing the main attachment to change the displayed preview, it never comes back to the problematic ZIP file.

Solution:

Also display the arrows if the main attachment is not viewable and there is more than one attachment.
This way the user can return in the list of viewable attachments.

This is not an optimal because Odoo will still try to display the ZIP file, but it is a simple fix that works.
I tried restraining the main attachment field only to viewable files in this PR, but it seems to break things specially with OCR extraction and apparently it is sometimes wanted to have an XML as main attachment.

opw-4486363

Forward-Port-Of: #200243
Forward-Port-Of: #196446

@robodoo robodoo added forwardport This PR was created by @fw-bot conflict There was an error while creating this forward-port PR labels Mar 5, 2025
@robodoo
Copy link
Contributor

robodoo commented Mar 5, 2025

Pull request status dashboard

@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 5, 2025

@mathcoutant @alexkuhn cherrypicking of pull request #196446 failed.

stdout:

Auto-merging addons/mail/static/src/core/common/attachment_view.js
CONFLICT (content): Merge conflict in addons/mail/static/src/core/common/attachment_view.js
Auto-merging addons/mail/static/src/core/common/attachment_view.xml
CONFLICT (content): Merge conflict in addons/mail/static/src/core/common/attachment_view.xml
Auto-merging addons/mail/static/tests/chatter/web/attachment_box.test.js
CONFLICT (content): Merge conflict in addons/mail/static/tests/chatter/web/attachment_box.test.js

Either perform the forward-port manually (and push to this branch, proceeding as usual) or close this PR (maybe?).

In the former case, you may want to edit this PR message as well.

⚠️ after resolving this conflict, you will need to merge it via @robodoo.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 5, 2025
@mathcoutant mathcoutant force-pushed the saas-17.4-16.0-opw-4486363-switch_main_attachment-mcou-420360-fw branch from a2878f2 to 5f613d4 Compare March 6, 2025 17:05
@C3POdoo C3POdoo requested review from a team March 6, 2025 17:07
@mathcoutant mathcoutant force-pushed the saas-17.4-16.0-opw-4486363-switch_main_attachment-mcou-420360-fw branch from 5f613d4 to 5087e79 Compare March 6, 2025 17:25
@mathcoutant mathcoutant force-pushed the saas-17.4-16.0-opw-4486363-switch_main_attachment-mcou-420360-fw branch from 5087e79 to 9ff1012 Compare March 7, 2025 12:12
Steps to reproduce:
- Create a new invoice
- Attach a ZIP file then a PDF file
- The file viewer shows but tries to preview the ZIP file
- Happens with all non-viewable files

Cause:
The ZIP file is put as main attachment and the method `register_as_main_attachment` only change the main attachment (with `force=False`) when there is no main attachment.

The behavior of the file viewer is inconsistent because we cannot switch between the attachments in the preview, so we cannot see the PDF. But if we add another PDF file (so one ZIP and 2 PDFs), we can switch but it will never show the ZIP again, only the two PDFs.
This behavior is due to the [next/previous arrows being displayed](https://github.com/odoo/odoo/blob/e4da068d6c9c8885dd4663d50dee11c9ea1516a3/addons/mail/static/src/components/web_client_view_attachment_view/web_client_view_attachment_view.xml#L13) only if [`attachmentsInWebClientView`](https://github.com/odoo/odoo/blob/e4da068d6c9c8885dd4663d50dee11c9ea1516a3/addons/mail/static/src/models/attachment.js#L323-L328) contains more than one item. But this list only contains viewable attachments (PDF or Images), and the next/previous arrows only take attachments from this list. As the arrows are [changing the main attachment](https://github.com/odoo/odoo/blob/e4da068d6c9c8885dd4663d50dee11c9ea1516a3/addons/mail/static/src/models/web_client_view_attachment_view.js#L17) to change the displayed preview, it never comes back to the problematic ZIP file.

Solution:
Also display the arrows if the main attachment is not viewable and there is more than one attachment.

opw-4486363
@mathcoutant mathcoutant force-pushed the saas-17.4-16.0-opw-4486363-switch_main_attachment-mcou-420360-fw branch from 9ff1012 to 9160e8f Compare March 7, 2025 12:13
Copy link
Contributor

@alexkuhn alexkuhn left a comment

Choose a reason for hiding this comment

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

robodoo pushed a commit that referenced this pull request Mar 7, 2025
Steps to reproduce:
- Create a new invoice
- Attach a ZIP file then a PDF file
- The file viewer shows but tries to preview the ZIP file
- Happens with all non-viewable files

Cause:
The ZIP file is put as main attachment and the method `register_as_main_attachment` only change the main attachment (with `force=False`) when there is no main attachment.

The behavior of the file viewer is inconsistent because we cannot switch between the attachments in the preview, so we cannot see the PDF. But if we add another PDF file (so one ZIP and 2 PDFs), we can switch but it will never show the ZIP again, only the two PDFs.
This behavior is due to the [next/previous arrows being displayed](https://github.com/odoo/odoo/blob/e4da068d6c9c8885dd4663d50dee11c9ea1516a3/addons/mail/static/src/components/web_client_view_attachment_view/web_client_view_attachment_view.xml#L13) only if [`attachmentsInWebClientView`](https://github.com/odoo/odoo/blob/e4da068d6c9c8885dd4663d50dee11c9ea1516a3/addons/mail/static/src/models/attachment.js#L323-L328) contains more than one item. But this list only contains viewable attachments (PDF or Images), and the next/previous arrows only take attachments from this list. As the arrows are [changing the main attachment](https://github.com/odoo/odoo/blob/e4da068d6c9c8885dd4663d50dee11c9ea1516a3/addons/mail/static/src/models/web_client_view_attachment_view.js#L17) to change the displayed preview, it never comes back to the problematic ZIP file.

Solution:
Also display the arrows if the main attachment is not viewable and there is more than one attachment.

opw-4486363

closes #200427

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
@robodoo robodoo closed this Mar 7, 2025
@alexkuhn alexkuhn deleted the saas-17.4-16.0-opw-4486363-switch_main_attachment-mcou-420360-fw branch March 7, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflict There was an error while creating this forward-port PR forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants