Code review comment for lp:~openerp-dev/openobject-addons/trunk-bug-832635-nch

Revision history for this message
qdp (OpenERP) (qdp) wrote :

> - four empty writes on res.partner.address where no changes are logged (not
> correct)
yes but no, you didn't implemented it in the right way: what you should do is avoid creating the audittrail log if there is no log line, instead of creating it then deleting it if there is no line. It will avoid useless operations.

For that, you need to do a small change:
=> replace the function
     self.create_log_line(cr, uid, log_id, model, lines)
   by
     self.create_log(cr, uid, model, lines)

def create_log(self, cr, uid, model, lines=[]):
    if not lines:
        return True
    vals = { ... }
    vals['lines] = [(0, 0, { ... }), ...]
    return self.pool.get('audittrail.log').create(cr, uid, vals, context)

> - one write on res.partner.address with the data you just created
> (incorrect, the method logged should be 'create' instead of 'write', otherwise
> it's ok)
i know, but it's not a argument. You can force the method to use. For example, try to add those 2 lines (it seems doing the trick but i didn't test completly):
=== modified file 'audittrail/audittrail.py'
--- audittrail/audittrail.py 2011-11-08 16:55:34 +0000
+++ audittrail/audittrail.py 2011-11-09 09:43:22 +0000
@@ -354,6 +357,8 @@
                     vals = {'method': method,'object_id': model.id,'user_id': uid_orig }
                     for resource in resource_data:
                         resource_id = resource['id']
+ if resource_id not in dict_to_use.keys():
+ vals.update({'method': 'create'})
                         vals.update({'res_id': resource_id})
                         log_id = log_pool.create(cr, uid, vals)
                         lines = []

i set it back to 'work in progress' ;-)
Quentin

review: Needs Fixing

« Back to merge proposal