[FIX] base_calendar: allow to sort crm.meeting in search calls with recurrent events, based on code from Erik Heeren
lp bug: https://launchpad.net/bugs/1023322 fixed bzr revid: mat@openerp.com-20140109103708-xw35n9q5u6z6pfby
This commit is contained in:
parent
ad17716632
commit
3b23bf6f8c
|
@ -26,9 +26,11 @@ from dateutil.relativedelta import relativedelta
|
|||
from openerp.osv import fields, osv
|
||||
from openerp.service import web_services
|
||||
from openerp.tools.translate import _
|
||||
|
||||
import pytz
|
||||
import re
|
||||
import time
|
||||
from operator import itemgetter
|
||||
from openerp import tools, SUPERUSER_ID
|
||||
|
||||
months = {
|
||||
|
@ -1170,18 +1172,29 @@ rule or repeating pattern of time to exclude from the recurring rule."),
|
|||
(_check_closing_date, 'Error ! End date cannot be set before start date.', ['date_deadline']),
|
||||
]
|
||||
|
||||
def get_recurrent_ids(self, cr, uid, select, domain, limit=100, context=None):
|
||||
def get_recurrent_ids(self, cr, uid, select, domain, limit=100, order=None, context=None):
|
||||
"""Gives virtual event ids for recurring events based on value of Recurrence Rule
|
||||
This method gives ids of dates that comes between start date and end date of calendar views
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user's ID for security checks,
|
||||
@param limit: The Number of Results to Return """
|
||||
@param limit: The Number of Results to Return
|
||||
@param order: The fields (comma separated, format "FIELD {DESC|ASC}") on which the events should be sorted"""
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
result = []
|
||||
for data in super(calendar_event, self).read(cr, uid, select, ['rrule', 'recurrency', 'exdate', 'exrule', 'date'], context=context):
|
||||
result_data = []
|
||||
fields = ['rrule', 'recurrency', 'exdate', 'exrule', 'date']
|
||||
if order:
|
||||
order_fields = [field.split()[0] for field in order.split(',')]
|
||||
else:
|
||||
# fallback on self._order defined on the model
|
||||
order_fields = [field.split()[0] for field in self._order.split(',')]
|
||||
fields = list(set(fields + order_fields))
|
||||
|
||||
for data in super(calendar_event, self).read(cr, uid, select, fields, context=context):
|
||||
result_data.append(data)
|
||||
if not data['recurrency'] or not data['rrule']:
|
||||
result.append(data['id'])
|
||||
continue
|
||||
|
@ -1249,12 +1262,24 @@ rule or repeating pattern of time to exclude from the recurring rule."),
|
|||
if [True for item in new_pile if not item]:
|
||||
continue
|
||||
idval = real_id2base_calendar_id(data['id'], r_date.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
r_data = dict(data, id=idval, date=r_date.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
result.append(idval)
|
||||
result_data.append(r_data)
|
||||
ids = list(set(result))
|
||||
|
||||
if isinstance(select, (str, int, long)):
|
||||
return ids and ids[0] or False
|
||||
else:
|
||||
ids = list(set(result))
|
||||
if order_fields:
|
||||
|
||||
def comparer(left, right):
|
||||
for fn, mult in comparers:
|
||||
result = cmp(fn(left), fn(right))
|
||||
if result:
|
||||
return mult * result
|
||||
return 0
|
||||
|
||||
sort_params = [key.split()[0] if key[-4:].lower() != 'desc' else '-%s' % key.split()[0] for key in (order or self._order).split(',')]
|
||||
comparers = [ ((itemgetter(col[1:]), -1) if col[0] == '-' else (itemgetter(col), 1)) for col in sort_params]
|
||||
ids = [r['id'] for r in sorted(result_data, cmp=comparer)]
|
||||
|
||||
return ids
|
||||
|
||||
def compute_rule_string(self, data):
|
||||
|
@ -1378,10 +1403,13 @@ rule or repeating pattern of time to exclude from the recurring rule."),
|
|||
new_id = get_real_ids(arg[2])
|
||||
new_arg = (arg[0], arg[1], new_id)
|
||||
new_args.append(new_arg)
|
||||
#offset, limit and count must be treated separately as we may need to deal with virtual ids
|
||||
res = super(calendar_event, self).search(cr, uid, new_args, offset=0, limit=0, order=order, context=context, count=False)
|
||||
#offset, limit, order and count must be treated separately as we may need to deal with virtual ids
|
||||
if context.get('virtual_id', True):
|
||||
res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context)
|
||||
res = super(calendar_event, self).search(cr, uid, new_args, offset=0, limit=0, order=None, context=context, count=False)
|
||||
res = self.get_recurrent_ids(cr, uid, res, args, limit, order=order, context=context)
|
||||
else:
|
||||
res = super(calendar_event, self).search(cr, uid, new_args, offset=offset, limit=limit, order=order, context=context, count=count)
|
||||
|
||||
if count:
|
||||
return len(res)
|
||||
elif limit:
|
||||
|
|
Loading…
Reference in New Issue