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
1=== modified file 'audittrail/audittrail.py'
2--- audittrail/audittrail.py 2012-12-17 15:46:28 +0000
3+++ audittrail/audittrail.py 2014-02-04 14:36:46 +0000
4@@ -271,10 +271,14 @@
5 new_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
6 elif method == 'read':
7 res = fct_src(cr, uid_orig, model.model, method, *args, **kw)
8+ if isinstance(res, dict):
9+ records = [res]
10+ else:
11+ records = res
12 # build the res_ids and the old_values dict. Here we don't use get_data() to
13 # avoid performing an additional read()
14 res_ids = []
15- for record in res:
16+ for record in records:
17 res_ids.append(record['id'])
18 old_values[(model.id, record['id'])] = {'value': record, 'text': record}
19 # log only the fields read
20@@ -282,7 +286,9 @@
21 elif method == 'unlink':
22 res_ids = args[0]
23 old_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
24- res = fct_src(cr, uid_orig, model.model, method, *args, **kw)
25+ # process_data first as fct_src will unlink the record
26+ self.process_data(cr, uid_orig, pool, res_ids, model, method, old_values, new_values, field_list)
27+ return fct_src(cr, uid_orig, model.model, method, *args, **kw)
28 else: # method is write, action or workflow action
29 res_ids = []
30 if args:
31@@ -325,7 +331,7 @@
32 data = {}
33 resource_pool = pool.get(model.model)
34 # read all the fields of the given resources in super admin mode
35- for resource in resource_pool.read(cr, SUPERUSER_ID, res_ids):
36+ for resource in resource_pool.read(cr, SUPERUSER_ID, res_ids, resource_pool._all_columns):
37 values = {}
38 values_text = {}
39 resource_id = resource['id']
40@@ -459,7 +465,9 @@
41
42 # if at least one modification has been found
43 for model_id, resource_id in lines:
44- name = pool.get(model.model).name_get(cr, uid, [resource_id])[0][1]
45+ line_model = pool.get('ir.model').browse(cr, SUPERUSER_ID, model_id).model
46+ name = pool.get(line_model).name_get(cr, uid, [resource_id])[0][1]
47+
48 vals = {
49 'method': method,
50 'object_id': model_id,