Skip to content

Commit 067fd2f

Browse files
andreparamesmart-e
authored andcommitted
[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 odoo#7454
1 parent a35af81 commit 067fd2f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

openerp/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import time
5151
from collections import defaultdict, MutableMapping
5252
from inspect import getmembers, currentframe
53+
from operator import itemgetter
5354

5455
import babel.dates
5556
import dateutil.relativedelta
@@ -5391,7 +5392,7 @@ def sorted(self, key=None, reverse=False):
53915392
recs = self.search([('id', 'in', self.ids)])
53925393
return self.browse(reversed(recs._ids)) if reverse else recs
53935394
else:
5394-
return self.browse(map(int, sorted(self, key=key, reverse=reverse)))
5395+
return self.browse(map(itemgetter('id'), sorted(self, key=key, reverse=reverse)))
53955396

53965397
def update(self, values):
53975398
""" Update record `self[0]` with ``values``. """

0 commit comments

Comments
 (0)