Skip to content

Commit

Permalink
[FIX] tracking_manager: Avoid error when accessing the value of a fie…
Browse files Browse the repository at this point in the history
…ld that we do not have access

Example use case:
- Install hr_fleet
- Set the employee_ids field of hr.employee as a tracking field
- Modify the user to not have permissions in Fleet
- Modify the name of an employee

TT51160
  • Loading branch information
victoralmau committed Oct 8, 2024
1 parent 22400c3 commit b41e7ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion tracking_manager/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict

from odoo import api, models, tools
from odoo.exceptions import AccessError

from ..tools import format_m2m

Expand Down Expand Up @@ -120,7 +121,11 @@ def _tm_prepare_o2m_tracking(self):
values = initial_values.setdefault(record.id, {})
if values is not None:
for fname in fnames:
values.setdefault(fname, record[fname])
try:
values.setdefault(fname, record[fname])
except AccessError:

Check warning on line 126 in tracking_manager/models/models.py

View check run for this annotation

Codecov / codecov/patch

tracking_manager/models/models.py#L126

Added line #L126 was not covered by tests
# User does not have access to the field (example with groups)
continue

Check warning on line 128 in tracking_manager/models/models.py

View check run for this annotation

Codecov / codecov/patch

tracking_manager/models/models.py#L128

Added line #L128 was not covered by tests

def _tm_finalize_o2m_tracking(self):
initial_values = self.env.cr.precommit.data.pop(
Expand Down
10 changes: 9 additions & 1 deletion tracking_manager/tests/test_tracking_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# Copyright 2024 Tecnativa - Víctor Martínez
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

Expand Down Expand Up @@ -27,7 +28,7 @@ def setUpClass(cls):
}
)
cls.partner_model = cls.env.ref("base.model_res_partner")
cls._active_tracking(["user_ids", "category_id"])
cls._active_tracking(["user_ids", "category_id", "child_ids"])
cls.flush_tracking()
cls.partner.message_ids.unlink()

Expand Down Expand Up @@ -267,3 +268,10 @@ def test_o2m_write_and_unlink_directly(self):
self.assertEqual(len(self.messages), 1)
self.assertEqual(self.messages.body.count("Change"), 0)
self.assertEqual(self.messages.body.count("Delete"), 1)

def test_o2m_update_record(self):
child = self.env["res.partner"].create(
{"name": "Test child", "parent_id": self.partner.id}
)
child.write({"parent_id": False})
self.assertEqual(len(self.messages), 1)

0 comments on commit b41e7ae

Please sign in to comment.