From e39c0e9c4efd688085cd035a95370187007ff88f Mon Sep 17 00:00:00 2001 From: Baptiste Pellarin Date: Thu, 13 Nov 2025 12:06:45 +0700 Subject: [PATCH] [18.0][IMP] auditlog: Allow developers to by-pass the auditlog. In high-volume automated processes, such as batch data imports or recalculations (e.g., journal entries, inventory valuation), the performance overhead of audit logging can lead to thread timeouts and job failures. This feature introduces a way to programmatically disable logging during these specific operations to ensure process stability and completion. --- auditlog/README.rst | 45 ++++++++++++-------------- auditlog/models/rule.py | 2 ++ auditlog/readme/CONTRIBUTORS.md | 1 + auditlog/static/description/index.html | 31 ++++++++---------- auditlog/tests/test_auditlog.py | 19 +++++++++++ 5 files changed, 56 insertions(+), 42 deletions(-) diff --git a/auditlog/README.rst b/auditlog/README.rst index 830964b754a..0af7d879046 100644 --- a/auditlog/README.rst +++ b/auditlog/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ========= Audit Log ========= @@ -17,7 +13,7 @@ Audit Log .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github @@ -82,10 +78,10 @@ right to configure the auditlog configuration rules. Known issues / Roadmap ====================== - - log only operations triggered by some users (currently it logs all - users) - - log read operations does not work on all data models, need - investigation + - log only operations triggered by some users (currently it logs all + users) + - log read operations does not work on all data models, need + investigation Bug Tracker =========== @@ -108,25 +104,26 @@ Authors Contributors ------------ -- Sebastien Alix -- Holger Brunn -- Holden Rehg -- Eric Lembregts -- Pieter Paulussen -- Alan Ramos -- Stefan Rijnhart -- Bhavesh Odedra -- Hardik Suthar -- Kitti U. -- Bogdan Valentin Gabor -- Dennis Sluijk d.sluijk@onestein.nl -- Adam Heinz +- Sebastien Alix +- Holger Brunn +- Holden Rehg +- Eric Lembregts +- Pieter Paulussen +- Alan Ramos +- Stefan Rijnhart +- Bhavesh Odedra +- Hardik Suthar +- Kitti U. +- Bogdan Valentin Gabor +- Dennis Sluijk d.sluijk@onestein.nl +- Adam Heinz +- Baptiste P. Other credits ------------- -- Icon: built with different icons from the `Oxygen - theme `__ (LGPL) +- Icon: built with different icons from the `Oxygen + theme `__ (LGPL) Maintainers ----------- diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 0336ed3e551..07acb0dabf2 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -588,6 +588,8 @@ def create_logs( """Create logs. `old_values` and `new_values` are dictionaries, e.g: {RES_ID: {'FIELD': VALUE, ...}} """ + if self.env.context.get("auditlog_skip", False): + return None if old_values is None: old_values = EMPTY_DICT if new_values is None: diff --git a/auditlog/readme/CONTRIBUTORS.md b/auditlog/readme/CONTRIBUTORS.md index 761a38b9368..2bc5456ae08 100644 --- a/auditlog/readme/CONTRIBUTORS.md +++ b/auditlog/readme/CONTRIBUTORS.md @@ -11,3 +11,4 @@ - Bogdan Valentin Gabor \<\> - Dennis Sluijk - Adam Heinz \<\> +- Baptiste P. \<\> diff --git a/auditlog/static/description/index.html b/auditlog/static/description/index.html index f016642da0c..b0a9df9d09a 100644 --- a/auditlog/static/description/index.html +++ b/auditlog/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Audit Log -
+
+

Audit Log

- - -Odoo Community Association - -
-

Audit Log

-

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

This module allows the administrator to log user operations performed on data models such as create, read, write and delete.

Table of contents

@@ -393,7 +388,7 @@

Audit Log

-

Usage

+

Usage

Go to Settings / Technical / Audit / Rules to subscribe rules. A rule defines which operations to log for a given data model.

image

@@ -417,7 +412,7 @@

Usage

right to configure the auditlog configuration rules.

-

Known issues / Roadmap

+

Known issues / Roadmap

  • log only operations triggered by some users (currently it logs all @@ -428,7 +423,7 @@

    Known issues / Roadmap

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -436,15 +431,15 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • ABF OSIELL
-

Contributors

+

Contributors

-

Other credits

+

Other credits

  • Icon: built with different icons from the Oxygen theme (LGPL)
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -482,6 +478,5 @@

Maintainers

-
diff --git a/auditlog/tests/test_auditlog.py b/auditlog/tests/test_auditlog.py index 58e38b71cfb..4c7ec6deba8 100644 --- a/auditlog/tests/test_auditlog.py +++ b/auditlog/tests/test_auditlog.py @@ -271,6 +271,25 @@ def test_LogDelete(self): 1, ) + def test_LogSkipped(self): + """Tests environment variable to skip the logs results""" + self.groups_rule.subscribe() + group = ( + self.env["res.groups"] + .with_context(auditlog_skip=True) + .create({"name": "testgroup1"}) + ) + group.with_context(auditlog_skip=True).unlink() + self.assertEqual( + self.env["auditlog.log"].search_count( + [ + ("model_id", "=", self.groups_model_id), + ("res_id", "=", group.id), + ] + ), + 0, + ) + class TestAuditlogFull(AuditLogRuleCommon, AuditlogCommon): @classmethod