← Back to team overview

credativ team mailing list archive

[Branch ~credativ/openobject-addons/6.1] Rev 7048: [MERGE] audittrail fixes

 

Merge authors:
  Jacob Hicks (credativ) (jah256)
------------------------------------------------------------
revno: 7048 [merge]
committer: Craig Gowing (credativ) <craig.gowing@xxxxxxxxxxxxxx>
branch nick: addons
timestamp: Wed 2013-07-24 08:56:49 +0100
message:
  [MERGE] audittrail fixes
modified:
  audittrail/audittrail.py


--
lp:~credativ/openobject-addons/6.1
https://code.launchpad.net/~credativ/openobject-addons/6.1

Your team credativ is subscribed to branch lp:~credativ/openobject-addons/6.1.
To unsubscribe from this branch go to https://code.launchpad.net/~credativ/openobject-addons/6.1/+edit-subscription
=== modified file 'audittrail/audittrail.py'
--- audittrail/audittrail.py	2012-03-23 14:25:41 +0000
+++ audittrail/audittrail.py	2013-07-22 10:27:12 +0000
@@ -300,7 +300,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, prev_data=False):
         """
         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
@@ -319,6 +319,12 @@
                                            },
                 }
         """
+        if not prev_data:
+            prev_data = []
+        key = (model.id, res_ids)
+        if key in prev_data:
+            return {}
+        prev_data.append(key)
         data = {}
         resource_pool = pool.get(model.model)
         # read all the fields of the given resources in super admin mode
@@ -328,14 +334,14 @@
             resource_id = resource['id']
             # loop on each field on the res_ids we just have read
             for field in resource:
-                if field in ('__last_update', 'id'):
+                if field in ('__last_update', 'id') or not resource_pool._all_columns.get(field):
                     continue
                 values[field] = resource[field]
                 # 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'):
+                if field_obj._type in ('one2many'):
                     # 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
@@ -344,11 +350,11 @@
                         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))
+                        data.update(self.get_data(cr, 1, pool, resource[field], x2m_model, method, prev_data))
             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=[], prev_data=False):
         """
         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
@@ -378,17 +384,22 @@
         record (res.partner, for example), we may have to log a change done in a x2many field (on 
         res.partner.address, for example)
         """
+        if not prev_data:
+            prev_data = []
         key = (model.id, resource_id)
+        if key in prev_data:
+            return {}
+        prev_data.append(key)
         lines = {
             key: []
         }
         # loop on all the fields
         for field_name, field_definition in pool.get(model.model)._all_columns.items():
             #if the field_list param is given, skip all the fields not in that list
-            if field_list and field_name not in field_list:
+            if (field_list and field_name not in field_list) or field_name in ('__last_update', 'id'):
                 continue
             field_obj = field_definition.column
-            if field_obj._type in ('one2many','many2many'):
+            if field_obj._type in ('one2many'):
                 # checking if an audittrail rule apply in super admin mode
                 if self.check_rules(cr, 1, field_obj._obj, method):
                     # checking if the model associated to a *2m field exists, in super admin mode
@@ -403,7 +414,7 @@
                     # 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))
+                        lines.update(self.prepare_audittrail_log_line(cr, 1, pool, x2m_model, res_id, method, old_values, new_values, field_list, prev_data))
             # if the value value is different than the old value: record the change
             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 = {