details: https://code.tryton.org/tryton/commit/836f1e24ada9
branch: default
user: Cédric Krier <[email protected]>
date: Thu Mar 26 10:56:59 2026 +0100
description:
Add contextual ``_log`` to force logging events
Closes #14712
diffstat:
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(-)
diffs (81 lines):
diff -r 13b3bb1c7bc9 -r 836f1e24ada9 trytond/CHANGELOG
--- a/trytond/CHANGELOG Sun Mar 29 11:50:11 2026 +0200
+++ b/trytond/CHANGELOG Thu Mar 26 10:56:59 2026 +0100
@@ -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 -r 13b3bb1c7bc9 -r 836f1e24ada9 trytond/doc/modules/ir/design/model.inc.rst
--- a/trytond/doc/modules/ir/design/model.inc.rst Sun Mar 29 11:50:11
2026 +0200
+++ b/trytond/doc/modules/ir/design/model.inc.rst Thu Mar 26 10:56:59
2026 +0100
@@ -131,6 +131,12 @@
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 -r 13b3bb1c7bc9 -r 836f1e24ada9 trytond/trytond/model/modelstorage.py
--- a/trytond/trytond/model/modelstorage.py Sun Mar 29 11:50:11 2026 +0200
+++ b/trytond/trytond/model/modelstorage.py Thu Mar 26 10:56:59 2026 +0100
@@ -359,6 +359,7 @@
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 @@
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 @@
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 @@
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 -r 13b3bb1c7bc9 -r 836f1e24ada9 trytond/trytond/model/modelview.py
--- a/trytond/trytond/model/modelview.py Sun Mar 29 11:50:11 2026 +0200
+++ b/trytond/trytond/model/modelview.py Thu Mar 26 10:56:59 2026 +0100
@@ -747,6 +747,7 @@
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 @@
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)