Browse Source

[FIX] Module 'auditlog' - Replace 'try/except statement by 'isinstance()' + Add missing field in unit test + Remove a list comprehension

pull/148/head
sebalix 10 years ago
parent
commit
48fa5cb3b9
  1. 10
      auditlog/models/rule.py
  2. 4
      auditlog/tests/test_auditlog.py

10
auditlog/models/rule.py

@ -219,10 +219,9 @@ class auditlog_rule(models.Model):
def read(self, *args, **kwargs): def read(self, *args, **kwargs):
result = read.origin(self, *args, **kwargs) result = read.origin(self, *args, **kwargs)
# Sometimes the result is not a list but a dictionary # Sometimes the result is not a list but a dictionary
try:
read_values = dict((d['id'], d) for d in result)
except TypeError:
read_values = dict((d['id'], d) for d in [result])
if not isinstance(result, list):
result = [result]
read_values = dict((d['id'], d) for d in result)
# Old API # Old API
if args and isinstance(args[0], sql_db.Cursor): if args and isinstance(args[0], sql_db.Cursor):
cr, uid, ids = args[0], args[1], args[2] cr, uid, ids = args[0], args[1], args[2]
@ -318,8 +317,7 @@ class auditlog_rule(models.Model):
# - search the field in the current model and those it inherits # - search the field in the current model and those it inherits
field_model = self.env['ir.model.fields'] field_model = self.env['ir.model.fields']
all_model_ids = [model.id] all_model_ids = [model.id]
all_model_ids.extend(
inherited.id for inherited in model.inherited_model_ids)
all_model_ids.extend(model.inherited_model_ids.ids)
field = field_model.search( field = field_model.search(
[('model_id', 'in', all_model_ids), ('name', '=', field_name)]) [('model_id', 'in', all_model_ids), ('name', '=', field_name)])
# The field can be a dummy one, like 'in_group_X' on 'res.users' # The field can be a dummy one, like 'in_group_X' on 'res.users'

4
auditlog/tests/test_auditlog.py

@ -96,7 +96,9 @@ class TestAuditlog(TransactionCase):
user = self.env['res.users'].create({ user = self.env['res.users'].create({
'name': 'testuser_inheritedfield', 'name': 'testuser_inheritedfield',
'login': 'testuser.inheritedfield@company.com', 'login': 'testuser.inheritedfield@company.com',
'lang': 'en_US', # field inherited from 'res.partner'
# fields inherited from 'res.partner'
'lang': 'en_US',
'notify_email': 'none',
}) })
self.assertTrue(auditlog_log.search([ self.assertTrue(auditlog_log.search([
('model_id', '=', users_model_id), ('model_id', '=', users_model_id),

Loading…
Cancel
Save