From 65342e9877d4288d286914d9fd0cd93077e14936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 26 Mar 2026 10:56:59 +0100 Subject: [PATCH] Add contextual ``_log`` to force logging events Closes #14712 --- trytond/CHANGELOG | 1 + trytond/doc/modules/ir/design/model.inc.rst | 6 ++++++ trytond/trytond/model/modelstorage.py | 6 ++++-- trytond/trytond/model/modelview.py | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 52c4aff214..50a5456227 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Add contextual ``_log`` to force logging events * Add notify_user to ModelStorage * Check button states when testing access * Remove the files of Binary fields from the Filestore diff --git a/trytond/doc/modules/ir/design/model.inc.rst b/trytond/doc/modules/ir/design/model.inc.rst index 6920c62d49..fc1afa2899 100644 --- a/trytond/doc/modules/ir/design/model.inc.rst +++ b/trytond/doc/modules/ir/design/model.inc.rst @@ -131,6 +131,12 @@ Model Log The *Model Log* records events such as modification, suppression, click, launch and transition that happened to a :class:`~trytond.model.ModelStorage` record. +.. note:: + Only events happening under check access are logged by default except for + transition that are always logged. + But the ``_log`` key if set to ``True`` in the + :attr:`~trytond.transaction.Transaction.context` forces the logging. + .. seealso:: Model Logs are found by opening the main menu item: diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index 464d691bfe..3ae9b1b171 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -359,6 +359,7 @@ class ModelStorage(Model): Trigger = pool.get('ir.trigger') transaction = Transaction() check_access = transaction.user and transaction.check_access + log = transaction.context.get('_log', False) assert not len(args) % 2 @@ -378,7 +379,7 @@ class ModelStorage(Model): on_write.extend(cls.on_write(records, values)) args.append(records) args.append(cls.preprocess_values('write', values)) - if check_access and values: + if (check_access or log) and values: cls.log(records, 'write', ','.join(sorted(values.keys()))) field_names.update(values.keys()) all_records.extend(records) @@ -451,6 +452,7 @@ class ModelStorage(Model): Trigger = pool.get('ir.trigger') transaction = Transaction() check_access = transaction.user and transaction.check_access + log = transaction.context.get('_log', False) ModelAccess.check(cls.__name__, 'delete') cls.__check_xml_record(records, None) @@ -458,7 +460,7 @@ class ModelStorage(Model): cls.check_modification('delete', records, external=check_access) if ModelData.has_model(cls.__name__): ModelData.clean(records) - if check_access: + if check_access or log: cls.log(records, 'delete') on_delete = cls.on_delete(records) cls.on_modification('delete', records) diff --git a/trytond/trytond/model/modelview.py b/trytond/trytond/model/modelview.py index f2f53ae3c9..df886ed284 100644 --- a/trytond/trytond/model/modelview.py +++ b/trytond/trytond/model/modelview.py @@ -747,6 +747,7 @@ class ModelView(Model): transaction = Transaction() check_access = transaction.check_access + log = transaction.context.get('_log', False) assert len(records) == len(set(records)), "Duplicate records" @@ -793,7 +794,7 @@ class ModelView(Model): if names: ButtonClick.reset(cls.__name__, names, records) - if check_access and issubclass(cls, ModelStorage): + if (check_access or log) and issubclass(cls, ModelStorage): cls.log(records, 'button', func.__name__) with without_check_access(): return func(cls, records, *args, **kwargs)