From 48fa5cb3b9499b40894ebbd0c71d964c710d1f63 Mon Sep 17 00:00:00 2001 From: sebalix Date: Thu, 2 Apr 2015 11:01:34 +0200 Subject: [PATCH] [FIX] Module 'auditlog' - Replace 'try/except statement by 'isinstance()' + Add missing field in unit test + Remove a list comprehension --- auditlog/models/rule.py | 10 ++++------ auditlog/tests/test_auditlog.py | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 7e58579a4..9549a7d5b 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -219,10 +219,9 @@ class auditlog_rule(models.Model): def read(self, *args, **kwargs): result = read.origin(self, *args, **kwargs) # 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 if args and isinstance(args[0], sql_db.Cursor): 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 field_model = self.env['ir.model.fields'] 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( [('model_id', 'in', all_model_ids), ('name', '=', field_name)]) # The field can be a dummy one, like 'in_group_X' on 'res.users' diff --git a/auditlog/tests/test_auditlog.py b/auditlog/tests/test_auditlog.py index c288184f1..ae1e7b751 100644 --- a/auditlog/tests/test_auditlog.py +++ b/auditlog/tests/test_auditlog.py @@ -96,7 +96,9 @@ class TestAuditlog(TransactionCase): user = self.env['res.users'].create({ 'name': 'testuser_inheritedfield', '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([ ('model_id', '=', users_model_id),