[FIX] auditlog: log computed fields stored in db as expected
Fixing #1134. Odoo stores values of computed fields at the end of the transaction only, as such performing a 'read()' to make a data snapshot on the record created in the current transaction doesn't return the expected result regarding these fields. Also as a side-effect 'read()' alters the environment cache and break the values on the record inducing issues in the whole user transaction/workflow. This fix replaces the use of 'read()' to do the data snapshot directly from the cache of the record (computed values are already there).pull/1793/head
parent
a72c87be77
commit
0f990fcbab
|
@ -240,12 +240,15 @@ class AuditlogRule(models.Model):
|
|||
self = self.with_context(auditlog_disabled=True)
|
||||
rule_model = self.env["auditlog.rule"]
|
||||
new_record = create_full.origin(self, vals, **kwargs)
|
||||
new_values = {
|
||||
d["id"]: d
|
||||
for d in new_record.sudo()
|
||||
.with_context(prefetch_fields=False)
|
||||
.read(list(self._fields))
|
||||
}
|
||||
# Take a snapshot of record values from the cache instead of using
|
||||
# 'read()'. It avoids issues with related/computed fields which
|
||||
# stored in the database only at the end of the transaction, but
|
||||
# their values exist in cache.
|
||||
new_values = {new_record.id: {}}
|
||||
for fname, field in new_record._fields.items():
|
||||
new_values[new_record.id][fname] = field.convert_to_read(
|
||||
new_record[fname], new_record
|
||||
)
|
||||
rule_model.sudo().create_logs(
|
||||
self.env.uid,
|
||||
self._name,
|
||||
|
|
Loading…
Reference in New Issue