This commit is contained in:
2026-07-25 09:13:12 +02:00
parent 9fa91f1255
commit 99763f10f2
5 changed files with 103 additions and 2 deletions

View File

@@ -1538,6 +1538,10 @@ class Log(ResourceAccessMixin, ModelSQL, ModelView):
})
action = fields.Function(
fields.Char("Action"), 'get_action', searcher='search_action')
old_values = fields.Text("Old Values", readonly=True)
new_values = fields.Text("New Values", readonly=True)
change_summary = fields.Function(
fields.Text("Changes"), 'get_change_summary')
@classmethod
def __setup__(cls):
@@ -1583,6 +1587,53 @@ class Log(ResourceAccessMixin, ModelSQL, ModelView):
return f'{field_name} : {state}'
return self.target
@staticmethod
def _load_change_values(value):
if not value:
return {}
try:
return json.loads(value)
except (TypeError, ValueError):
return {}
@staticmethod
def _format_change_value(value):
if isinstance(value, list):
if len(value) > 6:
return '[%s items]' % len(value)
return ', '.join(Log._format_change_value(v) for v in value)
if isinstance(value, dict):
return json.dumps(value, sort_keys=True, ensure_ascii=False)
if value in (None, ''):
return ''
return str(value)
def get_change_summary(self, name):
if self.event != 'write':
return ''
old_values = self._load_change_values(self.old_values)
new_values = self._load_change_values(self.new_values)
if not old_values and not new_values:
return ''
pool = Pool()
Field = pool.get('ir.model.field')
model = self.resource.__name__ if self.resource else None
lines = []
for field_name in sorted(set(old_values) | set(new_values)):
old_value = old_values.get(field_name)
new_value = new_values.get(field_name)
if old_value == new_value:
continue
if model:
field_label = Field.get_name(model, field_name)
else:
field_label = field_name
lines.append('%s: %s -> %s' % (
field_label,
self._format_change_value(old_value),
self._format_change_value(new_value)))
return '\n'.join(lines)
@classmethod
def search_action(cls, name, clause):
return [('target', *clause[1:])]

View File

@@ -13,4 +13,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="event"/>
<field name="action"/>
</group>
<label name="change_summary"/>
<field name="change_summary"/>
<label name="old_values"/>
<field name="old_values"/>
<label name="new_values"/>
<field name="new_values"/>
</form>

View File

@@ -8,4 +8,5 @@ this repository contains the full copyright notices and license terms. -->
<field name="user" expand="1"/>
<field name="event"/>
<field name="action" expand="1"/>
<field name="change_summary" optional="1"/>
</tree>