Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] hr_expense: set main attachment on hr.expense.sheet #142029

Closed
wants to merge 1 commit into from

Conversation

pivi-odoo
Copy link
Contributor

@pivi-odoo pivi-odoo commented Nov 14, 2023

Issue

Main attachments on expense sheets was never correctly set, leading to missing attachment previews in the hr.expense.sheet form view, and unnecessary RPC requests to register_main_attachment, because the attachment was never set.

Steps to reproduce

  • Install Expenses
  • Create 2 different expenses with different attachments
  • Create a report from those 2 expenses, save it
  • Notice there is nothing in the preview for the attachments, but if you zoom in or zoom out the page, then you can see it. Also swiping on the list of attachments isn't persistent, once you refresh the page, the main attachment we selected lastly is lost.

Cause

There are 2 main issues:

  • hr.expense.sheet has message_main_attachment_id, but it's never set.
  • When writing an attachment via register_main_attachment, we pass only the id of the attachment. Then in the backend, the related record is based on the model of the attachment, but the attachment is linked to hr.expense, not hr.expense.sheet. Therefor we re-write the same attachment on the record we read the attachment from. And then the frontend will continue to call register_main_attachment everytime it tries to find the attachments linked to the sheet, but it's never done.

Fix

  • Add a compute to initially set the value of the message_main_attachment_id based on the spec "we take the first line that has an attachment and we set it on the sheet"
  • The hr.expense.sheet now maintains a copies of the attachments linked to it's expenses, for proper ACL and functionality of register_main_attachment.

Affected versions

16.0 up to master = saas-17.1

Reference

task-3572440


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Nov 14, 2023

Pull request status dashboard.

@C3POdoo C3POdoo requested review from a team and JulienVR and removed request for a team November 14, 2023 14:29
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Nov 14, 2023
@pivi-odoo
Copy link
Contributor Author

Hi @xmo-odoo, thanks for your review.

Because the attachment is not copied over, the access checks will not be correctly performed and the relation is inconsistent (the main attachment of the sheet is not in any way related to a sheet let alone this one)

I've reworked completely the patch to follow your suggestion, I've had a bit of a hard time maintaining the sync between the attachments of the expenses and those on the sheet, so I decided to use the checksum of the attachments to avoid unnecessary trashing. If you see a better solution, I am all for it.

Let me know what you think.

Copy link
Contributor

@JulienVR JulienVR left a comment

Choose a reason for hiding this comment

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

It's good to me. Y ou'll just have to ask a runbot exception to the upgrade team to make the CI happy I think. :)

addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
@pivi-odoo pivi-odoo force-pushed the 16.0-opw-3572440-pivi branch 2 times, most recently from d75e136 to de9bf7c Compare November 27, 2023 07:46
@Xavier-Do
Copy link
Contributor

Upgrade exception #277 added.

Waiting the forward-port of this pr, the exception will be applied on all builds, and create an inconsistent state for migrations.
Please forward port this asap up to master without change. Exception should be forward-ported before the end of the week.

If you need to apply any change before it reaches master, please notify runbot team.

Details:

field:hr.expense.sheet.attachment_ids
field:hr.expense.attachment_ids

cc @KangOl @nseinlet

@pivi-odoo
Copy link
Contributor Author

Hi @JulienVR,

The Runbot's template exception has been granted, it just need the r+ :)

@JulienVR
Copy link
Contributor

I don't have r+ rights 😓, but @csnauwaert do (I'm only pre-reviewing PRs)

Copy link
Contributor

@seb-odoo seb-odoo left a comment

Choose a reason for hiding this comment

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

Hello, some comments as I'm passing by.

Also, as this is rather tricky, we should have some tests to cover this behavior.

addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
@pivi-odoo
Copy link
Contributor Author

pivi-odoo commented Nov 28, 2023

@JulienVR @csnauwaert I've updated the PR, to apply @seb-odoo and @ryv-odoo suggestions of moving the syncing of the attachments to the CRUD operations. I've also added a test that covers the use-cases that I could think of.

I guess the previous approval is considered outdated, since the patch completely changed.

Since I'm extending ir.attachment now to override the create and unlink, I guess I need to reping @odoo/rd-security (@xmo-odoo) but I think it's ok.

Copy link
Collaborator

@xmo-odoo xmo-odoo left a comment

Choose a reason for hiding this comment

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

I don't really get why you're now full-sync-ing the sheet with the expenses, my understanding of the original was just that the sheet should get an (any) attachment from its expenses in order not to be attachmentless, but 🤷

addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
addons/hr_expense/models/ir_attachment.py Outdated Show resolved Hide resolved
addons/hr_expense/models/hr_expense.py Outdated Show resolved Hide resolved
@pivi-odoo pivi-odoo marked this pull request as draft November 28, 2023 09:56
@pivi-odoo pivi-odoo force-pushed the 16.0-opw-3572440-pivi branch 2 times, most recently from 068ef92 to 0defce2 Compare December 6, 2023 12:07
robodoo pushed a commit that referenced this pull request May 6, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in /pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

Part-of: #155417
robodoo pushed a commit that referenced this pull request May 6, 2024
In /pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in /pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes #155417

Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request May 6, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in odoo/pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

X-original-commit: 912b91c
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request May 6, 2024
In odoo/pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in odoo/pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

X-original-commit: 0624487
robodoo pushed a commit that referenced this pull request May 7, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in /pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

X-original-commit: 912b91c
Part-of: #164640
robodoo pushed a commit that referenced this pull request May 7, 2024
In /pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in /pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes #164640

X-original-commit: 0624487
Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
alialfie added a commit to odoo-dev/odoo that referenced this pull request May 10, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in odoo/pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922
alialfie added a commit to odoo-dev/odoo that referenced this pull request May 10, 2024
In odoo/pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in odoo/pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes odoo#155417

Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
robodoo pushed a commit that referenced this pull request May 10, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in /pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

Part-of: #164645
robodoo pushed a commit that referenced this pull request May 10, 2024
In /pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in /pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes #155417

closes #164645

Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
Signed-off-by: Ali Alfie (alal) <alal@odoo.com>
alialfie added a commit to odoo-dev/odoo that referenced this pull request May 10, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in odoo/pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922
alialfie added a commit to odoo-dev/odoo that referenced this pull request May 10, 2024
In odoo/pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in odoo/pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes odoo#155417

Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
robodoo pushed a commit that referenced this pull request May 11, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in /pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

Part-of: #165117
robodoo pushed a commit that referenced this pull request May 11, 2024
In /pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in /pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes #155417

closes #165117

Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
zel-odoo pushed a commit to odoo-dev/odoo that referenced this pull request May 24, 2024
In an expense sheet, when an expense line is clicked on, its receipts are shown in the attachment viewer. This was broken in odoo/pull/142029 since it duplicates the attachments from the expense, leaving inconsistency between the attachment ID of the lines and the ones in the sheet. To fix this, the checksum is used instead to find which attachment in the sheet corresponds to the one in the line that was clicked on.

task-3758922

Part-of: odoo#165117
zel-odoo pushed a commit to odoo-dev/odoo that referenced this pull request May 24, 2024
In odoo/pull/138387, a new feature was added where clicking on an expense line in an expense sheet will highlight the receipts of that line in the attachment viewer if any. A JS test was included for this feature that mocked the fetching of the sheet's attachment. Since this changed in the backend in odoo/pull/142029, the feature no longer worked but the test never broke since it was mocking the backend. This commit adds a tour to prevent that from happening again.

closes odoo#155417

closes odoo#165117

Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet