Add contextual `_log` to force logging events

Closes #14712
This commit is contained in:
Cédric Krier committed 2026-03-26 10:56:59 +01:00
1 parent 080dc694ec
commit 65342e9877
4 files changed
+13 -3

No files matched your search

+1
View File
@@ -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
@@ -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:
+4 -2
View File
@@ -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)
+2 -1
View File
@@ -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)