[FIX] calendar: sorting error (P3)

When showing a list in Calendar, it is always sorted at least by
id. If the recordset mixes real and virtual (recurrent) events, this
will blow up as sort() will try to compare the int-typed real event
ids and the string-typed virtual event ids.

Generate a type-compatible id key for both real and virtual events in
order to properly sort.

Closes #20278
This commit is contained in:
Giang Manh
2017-10-25 11:33:27 +02:00
committed by Xavier Morel
parent 8991021dc6
commit b844f3bfd5
2 changed files with 36 additions and 2 deletions
+25 -2
View File
@@ -58,6 +58,23 @@ def get_real_ids(ids):
def real_id2calendar_id(record_id, date):
return '%s-%s' % (record_id, date.strftime(VIRTUALID_DATETIME_FORMAT))
def any_id2key(record_id):
""" Creates a (real_id: int, thing: str) pair which allows ordering mixed
collections of real and virtual events.
The first item of the pair is the event's real id, the second one is
either an empty string (for real events) or the datestring (for virtual
ones)
:param record_id:
:type record_id: int | str
:rtype: (int, str)
"""
if isinstance(record_id, pycompat.integer_types):
return record_id, u''
(real_id, virtual_id) = record_id.split('-')
return int(real_id), virtual_id
def is_calendar_id(record_id):
return len(str(record_id).split('-')) != 1
@@ -1124,9 +1141,15 @@ class Meeting(models.Model):
for key in (order or self._order).split(',')
))
def key(record):
return [
tools.Reverse(record[name]) if desc else record[name]
# first extract the values for each key column (ids need special treatment)
vals_spec = (
(any_id2key(record[name]) if name == 'id' else record[name], desc)
for name, desc in sort_spec
)
# then Reverse if the value matches a "desc" column
return [
(tools.Reverse(v) if desc else v)
for v, desc in vals_spec
]
return [r['id'] for r in sorted(result_data, key=key)]
+11
View File
@@ -0,0 +1,11 @@
Japan, 2017-10-19
I hereby agree to the terms of the Odoo Individual Contributor License
Agreement v1.0.
I declare that I am authorized and able to make this agreement and sign this
declaration.
Signed,
Giang Manh manhg@users.noreply.github.com https://github.com/manhg