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

[REF] fetch field data as user #3115

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions auditlog/models/rule.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright 2015 ABF OSIELL <https://osiell.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import contextlib
import copy

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.exceptions import AccessError, UserError

FIELDS_BLACKLIST = [
"id",
Expand Down Expand Up @@ -263,11 +264,13 @@ def get_auditlog_fields(self, model):
By default it is all stored fields only, but you can
override this.
"""
return list(
n
for n, f in model._fields.items()
if (not f.compute and not f.related) or f.store
)
fields_list = []
for n, f in model._fields.items():
if (not f.compute and not f.related) or f.store:
with contextlib.suppress(AccessError):
model.check_field_access_rights("read", [n])
fields_list.append(n)
return fields_list

def _make_create(self):
"""Instanciate a create method that log its calls."""
Expand All @@ -287,7 +290,7 @@ def create_full(self, vals_list, **kwargs):
# their values exist in cache.
new_values = {}
fields_list = rule_model.get_auditlog_fields(self)
for new_record in new_records.sudo():
for new_record in new_records:
new_values.setdefault(new_record.id, {})
for fname, field in new_record._fields.items():
if fname not in fields_list:
Expand Down Expand Up @@ -385,9 +388,7 @@ def write_full(self, vals, **kwargs):
fields_list = rule_model.get_auditlog_fields(self)
old_values = {
d["id"]: d
for d in self.sudo()
.with_context(prefetch_fields=False)
.read(fields_list)
for d in self.with_context(prefetch_fields=False).read(fields_list)
}
# invalidate_recordset method must be called with existing fields
if self._name == "res.users":
Expand All @@ -398,9 +399,7 @@ def write_full(self, vals, **kwargs):
result = write_full.origin(self, vals, **kwargs)
new_values = {
d["id"]: d
for d in self.sudo()
.with_context(prefetch_fields=False)
.read(fields_list)
for d in self.with_context(prefetch_fields=False).read(fields_list)
}
if self.env.user in users_to_exclude:
return result
Expand Down Expand Up @@ -453,9 +452,7 @@ def unlink_full(self, **kwargs):
fields_list = rule_model.get_auditlog_fields(self)
old_values = {
d["id"]: d
for d in self.sudo()
.with_context(prefetch_fields=False)
.read(fields_list)
for d in self.with_context(prefetch_fields=False).read(fields_list)
}
if self.env.user in users_to_exclude:
return unlink_full.origin(self, **kwargs)
Expand Down
Loading