[FIX] models: don't assume ids are ints in sorted()

Some models (e.g. calendar.event), use "virtual" ids which are not represented
as integers. It was not possible to use sorted method on those models as calling
int() is failing.

This commit fixes the method, making it agnostic to the type of the
'id' member variable.

Fixes #7454
master
andreparames 2015-07-03 15:20:01 +01:00 committed by Martin Trigaux
parent a35af81e6a
commit 067fd2f342
1 changed files with 2 additions and 1 deletions

View File

@ -50,6 +50,7 @@ import re
import time
from collections import defaultdict, MutableMapping
from inspect import getmembers, currentframe
from operator import itemgetter
import babel.dates
import dateutil.relativedelta
@ -5391,7 +5392,7 @@ class BaseModel(object):
recs = self.search([('id', 'in', self.ids)])
return self.browse(reversed(recs._ids)) if reverse else recs
else:
return self.browse(map(int, sorted(self, key=key, reverse=reverse)))
return self.browse(map(itemgetter('id'), sorted(self, key=key, reverse=reverse)))
def update(self, values):
""" Update record `self[0]` with ``values``. """