clearcorp team mailing list archive
-
clearcorp team
-
Mailing list archive
-
Message #00848
[Merge] lp:~rr.clearcorp/openobject-addons/6.1-pending_merge into lp:~clearcorp-drivers/openobject-addons/6.1-ccorp
Ronald Rubi has proposed merging lp:~rr.clearcorp/openobject-addons/6.1-pending_merge into lp:~clearcorp-drivers/openobject-addons/6.1-ccorp.
Requested reviews:
CLEARCORP drivers (clearcorp-drivers)
Related bugs:
Bug #1012931 in OpenERP Addons: "audit trail one2many error"
https://bugs.launchpad.net/openobject-addons/+bug/1012931
For more details, see:
https://code.launchpad.net/~rr.clearcorp/openobject-addons/6.1-pending_merge/+merge/175616
[MRG] Merge patch test_audit.patch, fix audittrail in models: res.users and res.groups
--
https://code.launchpad.net/~rr.clearcorp/openobject-addons/6.1-pending_merge/+merge/175616
Your team CLEARCORP development team is subscribed to branch lp:~clearcorp-drivers/openobject-addons/6.1-ccorp.
=== modified file 'audittrail/audittrail.py'
--- audittrail/audittrail.py 2012-03-23 14:25:41 +0000
+++ audittrail/audittrail.py 2013-07-18 15:59:33 +0000
@@ -25,6 +25,7 @@
import pooler
import time
import tools
+from openerp import SUPERUSER_ID
class audittrail_rule(osv.osv):
"""
@@ -172,7 +173,9 @@
class audittrail_objects_proxy(object_proxy):
""" Uses Object proxy for auditing changes on object of subscribed Rules"""
-
+
+ _default_recursive_level = 1
+
def get_value_text(self, cr, uid, pool, resource_pool, method, field, value):
"""
Gets textual values for the fields.
@@ -189,17 +192,20 @@
:return: string value or a list of values(for O2M/M2M)
"""
- field_obj = (resource_pool._all_columns.get(field)).column
- if field_obj._type in ('one2many','many2many'):
- data = pool.get(field_obj._obj).name_get(cr, uid, value)
- #return the modifications on x2many fields as a list of names
- res = map(lambda x:x[1], data)
- elif field_obj._type == 'many2one':
- #return the modifications on a many2one field as its value returned by name_get()
- res = value and value[1] or value
+ if field not in resource_pool._all_columns.keys():
+ return value
else:
- res = value
- return res
+ field_obj = (resource_pool._all_columns.get(field)).column
+ if field_obj._type in ('one2many','many2many'):
+ data = pool.get(field_obj._obj).name_get(cr, uid, value)
+ #return the modifications on x2many fields as a list of names
+ res = map(lambda x:x[1], data)
+ elif field_obj._type == 'many2one':
+ #return the modifications on a many2one field as its value returned by name_get()
+ res = value and value[1] or value
+ else:
+ res = value
+ return res
def create_log_line(self, cr, uid, log_id, model, lines=[]):
"""
@@ -300,7 +306,7 @@
self.process_data(cr, uid_orig, pool, res_ids, model, method, old_values, new_values, field_list)
return res
- def get_data(self, cr, uid, pool, res_ids, model, method):
+ def get_data(self, cr, uid, pool, res_ids, model, method, parent=None):
"""
This function simply read all the fields of the given res_ids, and also recurisvely on
all records of a x2m fields read that need to be logged. Then it returns the result in
@@ -334,21 +340,25 @@
# get the textual value of that field for this record
values_text[field] = self.get_value_text(cr, 1, pool, resource_pool, method, field, resource[field])
- field_obj = resource_pool._all_columns.get(field).column
- if field_obj._type in ('one2many','many2many'):
- # check if an audittrail rule apply in super admin mode
- if self.check_rules(cr, 1, field_obj._obj, method):
- # check if the model associated to a *2m field exists, in super admin mode
- x2m_model_ids = pool.get('ir.model').search(cr, 1, [('model', '=', field_obj._obj)])
- x2m_model_id = x2m_model_ids and x2m_model_ids[0] or False
- assert x2m_model_id, _("'%s' Model does not exist..." %(field_obj._obj))
- x2m_model = pool.get('ir.model').browse(cr, 1, x2m_model_id)
- #recursive call on x2m fields that need to be checked too
- data.update(self.get_data(cr, 1, pool, resource[field], x2m_model, method))
+ if field not in resource_pool._all_columns.keys():
+ pass
+ else:
+ field_obj = resource_pool._all_columns.get(field).column
+ if field_obj._type in ('one2many','many2many'):
+ # check if an audittrail rule apply in super admin mode
+ if self.check_rules(cr, 1, field_obj._obj, method):
+ # check if the model associated to a *2m field exists, in super admin mode
+ x2m_model_ids = pool.get('ir.model').search(cr, 1, [('model', '=', field_obj._obj)])
+ x2m_model_id = x2m_model_ids and x2m_model_ids[0] or False
+ assert x2m_model_id, _("'%s' Model does not exist..." %(field_obj._obj))
+ x2m_model = pool.get('ir.model').browse(cr, 1, x2m_model_id)
+ #recursive call on x2m fields that need to be checked too
+ if not parent in [x2m_model.model, model.model] and resource[field]:
+ data.update(self.get_data(cr, SUPERUSER_ID, pool, resource[field], x2m_model, method, parent=model.model))
data[(model.id, resource_id)] = {'text':values_text, 'value': values}
return data
- def prepare_audittrail_log_line(self, cr, uid, pool, model, resource_id, method, old_values, new_values, field_list=[]):
+ def prepare_audittrail_log_line(self, cr, uid, pool, model, resource_id, method, old_values, new_values, field_list=[], parent=None):
"""
This function compares the old data (i.e before the method was executed) and the new data
(after the method was executed) and returns a structure with all the needed information to
@@ -402,9 +412,12 @@
x2m_new_values_ids = new_values.get(key, {'value': {}})['value'].get(field_name, [])
# We use list(set(...)) to remove duplicates.
res_ids = list(set(x2m_old_values_ids + x2m_new_values_ids))
- for res_id in res_ids:
- lines.update(self.prepare_audittrail_log_line(cr, 1, pool, x2m_model, res_id, method, old_values, new_values, field_list))
+ if not parent in [x2m_model.model, model.model] and res_ids:
+ for res_id in res_ids:
+ lines.update(self.prepare_audittrail_log_line(cr, SUPERUSER_ID, pool, x2m_model, res_id, method, old_values, new_values, field_list, parent=model.model))
# if the value value is different than the old value: record the change
+ if field_name == 'id':
+ continue
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]:
data = {
'name': field_name,
@@ -442,11 +455,18 @@
# if at least one modification has been found
for model_id, resource_id in lines:
+ objmodel = pool.get('ir.model').browse(cr, uid, model_id)
+
+ if method == 'unlink':
+ name = old_values[(model_id, resource_id)]['text'].get(pool.get(objmodel.model)._rec_name)
+ else:
+ name = pool.get(objmodel.model).name_get(cr, uid, [resource_id])[0][1]
vals = {
'method': method,
'object_id': model_id,
'user_id': uid,
'res_id': resource_id,
+ 'name':name,
}
if (model_id, resource_id) not in old_values and method not in ('copy', 'read'):
# the resource was not existing so we are forcing the method to 'create'
@@ -461,8 +481,7 @@
# create the audittrail log in super admin mode, only if a change has been detected
if lines[(model_id, resource_id)]:
log_id = pool.get('audittrail.log').create(cr, 1, vals)
- model = pool.get('ir.model').browse(cr, uid, model_id)
- self.create_log_line(cr, 1, log_id, model, lines[(model_id, resource_id)])
+ self.create_log_line(cr, SUPERUSER_ID, log_id, objmodel, lines[(model_id, resource_id)])
return True
def check_rules(self, cr, uid, model, method):
Follow ups