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

[16.0][imp] auditlog file only #3177

Open
wants to merge 2 commits into
base: 16.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
34 changes: 27 additions & 7 deletions auditlog/models/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import copy
import logging

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

_logger = logging.getLogger(__name__)

FIELDS_BLACKLIST = [
"id",
"create_uid",
Expand All @@ -20,7 +23,7 @@
EMPTY_DICT = {}


class DictDiffer(object):
class DictDiffer:
"""Calculate the difference between two dictionaries as:
(1) items added
(2) items removed
Expand Down Expand Up @@ -107,7 +110,7 @@
states={"subscribed": [("readonly", True)]},
)
log_type = fields.Selection(
[("full", "Full log"), ("fast", "Fast log")],
[("full", "Full log"), ("fast", "Fast log"), ("file", "File only")],
string="Type",
required=True,
default="full",
Expand All @@ -116,7 +119,8 @@
"the operation (log more info like computed fields which were "
"updated, but it is slower)\n"
"Fast log: only log the changes made through the create and "
"write operations (less information, but it is faster)"
"write operations (less information, but it is faster)\n"
"File only: only prints information to logfile"
),
states={"subscribed": [("readonly", True)]},
)
Expand Down Expand Up @@ -315,7 +319,7 @@
vals_list2 = copy.deepcopy(vals_list)
new_records = create_fast.origin(self, vals_list, **kwargs)
new_values = {}
for vals, new_record in zip(vals_list2, new_records):
for vals, new_record in zip(vals_list2, new_records, strict=False):
new_values.setdefault(new_record.id, vals)
if self.env.user in users_to_exclude:
return new_records
Expand Down Expand Up @@ -513,6 +517,25 @@
for res_id in res_ids:
name = model_model.browse(res_id).name_get()
res_name = name and name[0] and name[0][1]
diff = DictDiffer(
new_values.get(res_id, EMPTY_DICT), old_values.get(res_id, EMPTY_DICT)
)
if additional_log_values.get("log_type", "file") == "file":
_logger.info({

Check warning on line 524 in auditlog/models/rule.py

View check run for this annotation

Codecov / codecov/patch

auditlog/models/rule.py#L524

Added line #L524 was not covered by tests
"auditlog": "_",
"name": res_name,
"model_id": model_id,
"res_id": res_id,
"method": method,
"user_id": uid,
"added": diff.added(),
"changed": diff.changed(),
"new": new_values,
"old": old_values,
"fields_to_exclude": fields_to_exclude,
"additional_log_values": additional_log_values,
})
return False

Check warning on line 538 in auditlog/models/rule.py

View check run for this annotation

Codecov / codecov/patch

auditlog/models/rule.py#L538

Added line #L538 was not covered by tests
vals = {
"name": res_name,
"model_id": model_id,
Expand All @@ -524,9 +547,6 @@
}
vals.update(additional_log_values or {})
log = log_model.create(vals)
diff = DictDiffer(
new_values.get(res_id, EMPTY_DICT), old_values.get(res_id, EMPTY_DICT)
)
if method == "create":
self._create_log_line_on_create(
log, diff.added(), new_values, fields_to_exclude
Expand Down
Loading