Merge lp:~openerp-dev/openobject-addons/7.0-opw-589931-rgo into lp:openobject-addons

Proposed by Lithin T
Status: Rejected
Rejected by: Naresh(OpenERP)
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-opw-589931-rgo
Merge into: lp:openobject-addons
Diff against target: 208 lines (+177/-0) (has conflicts)
1 file modified
audittrail/audittrail.py (+177/-0)
Text conflict in audittrail/audittrail.py
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-opw-589931-rgo
Reviewer Review Type Date Requested Status
Lithin T (community) Disapprove
Review via email: mp+191347@code.launchpad.net

Commit message

This fix is not traking when we deleting the records. So it should not be merged to the branch

To post a comment you must log in.
Revision history for this message
Lithin T (lithint-mail) :
review: Disapprove
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello Lithin,

Please don't propose a merge proposal to its opposite source version. Here you proposed this to trunk source while it was intended for stable 7.0. Infact already a merge proposal was available for stable 7.0 https://code.launchpad.net/~openerp-dev/openobject-addons/7.0-opw-589931-rgo/+merge/156130 so there was no need to do this extra work.

Please keep this note for future reference. It will save time for all of us.

Thanks,

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 2013-03-29 14:37:20 +0000
3+++ audittrail/audittrail.py 2013-10-16 08:27:50 +0000
4@@ -284,6 +284,7 @@
5 res_ids = []
6 if args:
7 res_ids = args[0]
8+<<<<<<< TREE
9 if isinstance(res_ids, (long, int)):
10 res_ids = [res_ids]
11 if res_ids:
12@@ -305,6 +306,88 @@
13 This function simply read all the fields of the given res_ids, and also recurisvely on
14 all records of a x2m fields read that need to be logged. Then it returns the result in
15 convenient structure that will be used as comparison basis.
16+=======
17+ old_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
18+ res = fct_src(cr, uid_orig, model.model, method, *args, **kw)
19+ else: # method is write, action or workflow action
20+ res_ids = []
21+ if args:
22+ res_ids = args[0]
23+ if isinstance(res_ids, (long, int)):
24+ res_ids = [res_ids]
25+ if res_ids:
26+ # store the old values into a dictionary
27+ old_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
28+ # process the original function, workflow trigger...
29+ res = fct_src(cr, uid_orig, model.model, method, *args, **kw)
30+ if method == 'copy':
31+ res_ids = [res]
32+ if res_ids:
33+ # check the new values and store them into a dictionary
34+ new_values = self.get_data(cr, uid_orig, pool, res_ids, model, method)
35+ # compare the old and new values and create audittrail log if needed
36+ self.process_data(cr, uid_orig, pool, res_ids, model, method, old_values, new_values, field_list)
37+ return res
38+
39+ def get_data(self, cr, uid, pool, res_ids, model, method):
40+ """
41+ This function simply read all the fields of the given res_ids, and also recurisvely on
42+ all records of a x2m fields read that need to be logged. Then it returns the result in
43+ convenient structure that will be used as comparison basis.
44+
45+ :param cr: the current row, from the database cursor,
46+ :param uid: the current user’s ID. This parameter is currently not used as every
47+ operation to get data is made as super admin. Though, it could be usefull later.
48+ :param pool: current db's pooler object.
49+ :param res_ids: Id's of resource to be logged/compared.
50+ :param model: Object whose values are being changed
51+ :param method: method to log: create, read, unlink, write, actions, workflow actions
52+ :return: dict mapping a tuple (model_id, resource_id) with its value and textual value
53+ { (model_id, resource_id): { 'value': ...
54+ 'textual_value': ...
55+ },
56+ }
57+ """
58+ data = {}
59+ resource_pool = pool.get(model.model)
60+ # read all the fields of the given resources in super admin mode
61+ for resource in resource_pool.read(cr, SUPERUSER_ID, res_ids):
62+ values = {}
63+ values_text = {}
64+ resource_id = resource['id']
65+ # loop on each field on the res_ids we just have read
66+ for field in resource:
67+ if field in ('__last_update', 'id') or not resource_pool._all_columns.get(field):
68+ continue
69+ values[field] = resource[field]
70+ # get the textual value of that field for this record
71+ values_text[field] = self.get_value_text(cr, SUPERUSER_ID, pool, resource_pool, method, field, resource[field])
72+
73+ field_obj = resource_pool._all_columns.get(field).column
74+ if field_obj._type in ('one2many','many2many'):
75+ # check if an audittrail rule apply in super admin mode
76+ if self.check_rules(cr, SUPERUSER_ID, field_obj._obj, method):
77+ # check if the model associated to a *2m field exists, in super admin mode
78+ x2m_model_ids = pool.get('ir.model').search(cr, SUPERUSER_ID, [('model', '=', field_obj._obj)])
79+ x2m_model_id = x2m_model_ids and x2m_model_ids[0] or False
80+ assert x2m_model_id, _("'%s' Model does not exist..." %(field_obj._obj))
81+ x2m_model = pool.get('ir.model').browse(cr, SUPERUSER_ID, x2m_model_id)
82+ field_resource_ids = list(set(resource[field]))
83+ if model.model == x2m_model.model:
84+ # we need to remove current resource_id from the many2many to prevent an infinit loop
85+ if resource_id in field_resource_ids:
86+ field_resource_ids.remove(resource_id)
87+ data.update(self.get_data(cr, SUPERUSER_ID, pool, field_resource_ids, x2m_model, method))
88+
89+ data[(model.id, resource_id)] = {'text':values_text, 'value': values}
90+ return data
91+
92+ def prepare_audittrail_log_line(self, cr, uid, pool, model, resource_id, method, old_values, new_values, field_list=None):
93+ """
94+ This function compares the old data (i.e before the method was executed) and the new data
95+ (after the method was executed) and returns a structure with all the needed information to
96+ log those differences.
97+>>>>>>> MERGE-SOURCE
98
99 :param cr: the current row, from the database cursor,
100 :param uid: the current user’s ID. This parameter is currently not used as every
101@@ -346,6 +429,7 @@
102 field_resource_ids = list(set(resource[field]))
103 if model.model == x2m_model.model:
104 # we need to remove current resource_id from the many2many to prevent an infinit loop
105+<<<<<<< TREE
106 if resource_id in field_resource_ids:
107 field_resource_ids.remove(resource_id)
108 data.update(get_data(cr, SUPERUSER_ID, pool, field_resource_ids, x2m_model, method))
109@@ -502,6 +586,99 @@
110 return True
111 elif method not in ('default_get','read','fields_view_get','fields_get','search','search_count','name_search','name_get','get','request_get', 'get_sc', 'unlink', 'write', 'create', 'read_group', 'import_data'):
112 if rule['log_action']:
113+=======
114+ if resource_id in res_ids:
115+ res_ids.remove(resource_id)
116+ for res_id in res_ids:
117+ lines.update(self.prepare_audittrail_log_line(cr, SUPERUSER_ID, pool, x2m_model, res_id, method, old_values, new_values, field_list))
118+ # if the value value is different than the old value: record the change
119+ if key not in old_values or key not in new_values or old_values[key]['value'][field_name] != new_values[key]['value'][field_name]:
120+ data = {
121+ 'name': field_name,
122+ 'new_value': key in new_values and new_values[key]['value'].get(field_name),
123+ 'old_value': key in old_values and old_values[key]['value'].get(field_name),
124+ 'new_value_text': key in new_values and new_values[key]['text'].get(field_name),
125+ 'old_value_text': key in old_values and old_values[key]['text'].get(field_name)
126+ }
127+ lines[key].append(data)
128+ return lines
129+
130+ def process_data(self, cr, uid, pool, res_ids, model, method, old_values=None, new_values=None, field_list=None):
131+ """
132+ This function processes and iterates recursively to log the difference between the old
133+ data (i.e before the method was executed) and the new data and creates audittrail log
134+ accordingly.
135+
136+ :param cr: the current row, from the database cursor,
137+ :param uid: the current user’s ID,
138+ :param pool: current db's pooler object.
139+ :param res_ids: Id's of resource to be logged/compared.
140+ :param model: model object which values are being changed
141+ :param method: method to log: create, read, unlink, write, actions, workflow actions
142+ :param old_values: dict of values read before execution of the method
143+ :param new_values: dict of values read after execution of the method
144+ :param field_list: optional argument containing the list of fields to log. Currently only
145+ used when performing a read, it could be usefull later on if we want to log the write
146+ on specific fields only.
147+ :return: True
148+ """
149+ if field_list is None:
150+ field_list = []
151+ # loop on all the given ids
152+ for res_id in res_ids:
153+ # compare old and new values and get audittrail log lines accordingly
154+ lines = self.prepare_audittrail_log_line(cr, uid, pool, model, res_id, method, old_values, new_values, field_list)
155+
156+ # if at least one modification has been found
157+ for model_id, resource_id in lines:
158+ current_model = pool.get('ir.model').browse(cr, uid, model_id).model
159+ if method == 'unlink':
160+ name = old_values[(model_id, resource_id)]['text'].get(pool.get(current_model)._rec_name)
161+ else:
162+ name = pool.get(current_model).name_get(cr, uid, [resource_id])[0][1]
163+ vals = {
164+ 'method': method,
165+ 'object_id': model_id,
166+ 'user_id': uid,
167+ 'res_id': resource_id,
168+ 'name': name,
169+ }
170+ if (model_id, resource_id) not in old_values and method not in ('copy', 'read'):
171+ # the resource was not existing so we are forcing the method to 'create'
172+ # (because it could also come with the value 'write' if we are creating
173+ # new record through a one2many field)
174+ vals.update({'method': 'create'})
175+ if (model_id, resource_id) not in new_values and method not in ('copy', 'read'):
176+ # the resource is not existing anymore so we are forcing the method to 'unlink'
177+ # (because it could also come with the value 'write' if we are deleting the
178+ # record through a one2many field)
179+ vals.update({'method': 'unlink'})
180+ # create the audittrail log in super admin mode, only if a change has been detected
181+ if lines[(model_id, resource_id)]:
182+ log_id = pool.get('audittrail.log').create(cr, SUPERUSER_ID, vals)
183+ model = pool.get('ir.model').browse(cr, uid, model_id)
184+ self.create_log_line(cr, SUPERUSER_ID, log_id, model, lines[(model_id, resource_id)])
185+ return True
186+
187+ def check_rules(self, cr, uid, model, method):
188+ """
189+ Checks if auditrails is installed for that db and then if one rule match
190+ @param cr: the current row, from the database cursor,
191+ @param uid: the current user’s ID,
192+ @param model: value of _name of the object which values are being changed
193+ @param method: method to log: create, read, unlink,write,actions,workflow actions
194+ @return: True or False
195+ """
196+ pool = pooler.get_pool(cr.dbname)
197+ if 'audittrail.rule' in pool.models:
198+ model_ids = pool.get('ir.model').search(cr, SUPERUSER_ID, [('model', '=', model)])
199+ model_id = model_ids and model_ids[0] or False
200+ if model_id:
201+ rule_ids = pool.get('audittrail.rule').search(cr, SUPERUSER_ID, [('object_id', '=', model_id), ('state', '=', 'subscribed')])
202+ for rule in pool.get('audittrail.rule').read(cr, SUPERUSER_ID, rule_ids, ['user_id','log_read','log_write','log_create','log_unlink','log_action','log_workflow']):
203+ if len(rule['user_id']) == 0 or uid in rule['user_id']:
204+ if rule.get('log_'+method,0):
205+>>>>>>> MERGE-SOURCE
206 return True
207
208 # Replace the openerp.service.model functions.

Subscribers

People subscribed via source and target branches

to all changes: