Merge lp:~openerp-dev/openobject-addons/7.0-fix-auditrail-mat into lp:openobject-addons/7.0

Proposed by Martin Trigaux (OpenERP)
Status: Merged
Merged at revision: 9808
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-fix-auditrail-mat
Merge into: lp:openobject-addons/7.0
Diff against target: 50 lines (+12/-4)
1 file modified
audittrail/audittrail.py (+12/-4)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-fix-auditrail-mat
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+204694@code.launchpad.net

Description of the change

Fixing several bugs in the audittrail module

- iter only on fields on __all_columns, this avoids getting virtual fields such as 'in_group_42' for res.users
- make sure read method calls works when passing only one id (lp:1214149)
- when iterating on change values, if different model (eg: if field is o2m) make sure make name_get on the model of the field and not on the parent model
- unlink retrieves first the record and then execute the unlink (the other way around is causes problems for name_get...)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'audittrail/audittrail.py'
--- audittrail/audittrail.py 2012-12-17 15:46:28 +0000
+++ audittrail/audittrail.py 2014-02-04 14:36:46 +0000
@@ -271,10 +271,14 @@
271 new_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)271 new_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
272 elif method == 'read':272 elif method == 'read':
273 res = fct_src(cr, uid_orig, model.model, method, *args, **kw)273 res = fct_src(cr, uid_orig, model.model, method, *args, **kw)
274 if isinstance(res, dict):
275 records = [res]
276 else:
277 records = res
274 # build the res_ids and the old_values dict. Here we don't use get_data() to278 # build the res_ids and the old_values dict. Here we don't use get_data() to
275 # avoid performing an additional read()279 # avoid performing an additional read()
276 res_ids = []280 res_ids = []
277 for record in res:281 for record in records:
278 res_ids.append(record['id'])282 res_ids.append(record['id'])
279 old_values[(model.id, record['id'])] = {'value': record, 'text': record}283 old_values[(model.id, record['id'])] = {'value': record, 'text': record}
280 # log only the fields read284 # log only the fields read
@@ -282,7 +286,9 @@
282 elif method == 'unlink':286 elif method == 'unlink':
283 res_ids = args[0]287 res_ids = args[0]
284 old_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)288 old_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
285 res = fct_src(cr, uid_orig, model.model, method, *args, **kw)289 # process_data first as fct_src will unlink the record
290 self.process_data(cr, uid_orig, pool, res_ids, model, method, old_values, new_values, field_list)
291 return fct_src(cr, uid_orig, model.model, method, *args, **kw)
286 else: # method is write, action or workflow action292 else: # method is write, action or workflow action
287 res_ids = []293 res_ids = []
288 if args:294 if args:
@@ -325,7 +331,7 @@
325 data = {}331 data = {}
326 resource_pool = pool.get(model.model)332 resource_pool = pool.get(model.model)
327 # read all the fields of the given resources in super admin mode333 # read all the fields of the given resources in super admin mode
328 for resource in resource_pool.read(cr, SUPERUSER_ID, res_ids):334 for resource in resource_pool.read(cr, SUPERUSER_ID, res_ids, resource_pool._all_columns):
329 values = {}335 values = {}
330 values_text = {}336 values_text = {}
331 resource_id = resource['id']337 resource_id = resource['id']
@@ -459,7 +465,9 @@
459465
460 # if at least one modification has been found466 # if at least one modification has been found
461 for model_id, resource_id in lines:467 for model_id, resource_id in lines:
462 name = pool.get(model.model).name_get(cr, uid, [resource_id])[0][1]468 line_model = pool.get('ir.model').browse(cr, SUPERUSER_ID, model_id).model
469 name = pool.get(line_model).name_get(cr, uid, [resource_id])[0][1]
470
463 vals = {471 vals = {
464 'method': method,472 'method': method,
465 'object_id': model_id,473 'object_id': model_id,