[IMP] calendar fix

bzr revid: tfr@openerp.com-20110309105959-zblg3a87gt9vu25w
This commit is contained in:
Thibault Francois 2011-03-09 11:59:59 +01:00
parent 5eb533a415
commit 3e7c4ec599
2 changed files with 62 additions and 64 deletions

View File

@ -60,6 +60,7 @@ def get_recurrent_dates(rrulestring, exdate, startdate=None, exrule=None):
if exrule:
rset1.exrule(rrule.rrulestr(str(exrule), dtstart=startdate))
return list(rset1._iter())
def base_calendar_id2real_id(base_calendar_id=None, with_date=False):
@ -374,6 +375,7 @@ property or property parameter."),
'ref': fields.reference('Event Ref', selection=_links_get, size=128),
'availability': fields.selection([('free', 'Free'), ('busy', 'Busy')], 'Free/Busy', readonly="True"),
}
_defaults = {
'state': 'needs-action',
'role': 'req-participant',
@ -914,22 +916,6 @@ class calendar_event(osv.osv):
def _tz_get(self, cr, uid, context=None):
return [(x.lower(), x) for x in pytz.all_timezones]
def onchange_allday(self, cr, uid, ids, allday, context=None):
"""Sets duration as 24 Hours if event is selected for all day
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of calendar events IDs.
@param allday: Value of allday boolean
@param context: A standard dictionary for contextual values
"""
if not allday or not ids:
return {}
value = {
'duration': 24
}
return {'value': value}
def onchange_dates(self, cr, uid, ids, start_date, duration=False, end_date=False, allday=False, context=None):
"""Returns duration and/or end date based on values passed
@param self: The object pointer
@ -954,6 +940,12 @@ class calendar_event(osv.osv):
if allday: # For all day event
value = {'duration': 24}
duration = 24.0
if start_date:
start = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S")
start_date = datetime.strftime(datetime(start.year, start.month, start.day, 0,0,0), "%Y-%m-%d %H:%M:%S")
value['date'] = start_date
print start_date
start = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S")
if end_date and not duration:
@ -1237,7 +1229,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
return True
def get_recurrent_ids(self, cr, uid, select, base_start_date, base_until_date, limit=100):
def get_recurrent_ids(self, cr, uid, select, base_start_date, base_until_date, limit=100, 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
@ -1247,15 +1239,16 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
@param base_until_date: Get End Date
@param limit: The Number of Results to Return """
if not limit:
limit = 100
virtual_id = context and context.get('virtual_id', False) or False
if isinstance(select, (str, int, long)):
ids = [select]
else:
ids = select
result = []
recur_dict = []
if ids and (base_start_date or base_until_date):
if ids and virtual_id:
cr.execute("select m.id, m.rrule, m.date, m.date_deadline, m.duration, \
m.exdate, m.exrule, m.recurrent_id, m.recurrent_uid from " + self._table + \
" m where m.id = ANY(%s)", (ids,) )
@ -1264,6 +1257,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
for data in cr.dictfetchall():
start_date = base_start_date and datetime.strptime(base_start_date[:10]+ ' 00:00:00' , "%Y-%m-%d %H:%M:%S") or False
until_date = base_until_date and datetime.strptime(base_until_date[:10]+ ' 23:59:59', "%Y-%m-%d %H:%M:%S") or False
print count
if count > limit:
break
event_date = datetime.strptime(data['date'], "%Y-%m-%d %H:%M:%S")
@ -1274,7 +1268,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
continue
if until_date and (event_date > until_date):
continue
idval = real_id2base_calendar_id(data['id'], data['date'])
idval = data['id']
if not data['recurrent_id']:
result.append(idval)
count += 1
@ -1317,7 +1311,12 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
continue
idval = real_id2base_calendar_id(data['id'], r_date.strftime("%Y-%m-%d %H:%M:%S"))
result.append(idval)
print "count", count
count += 1
if count > limit:
break
print "result", result
if result:
ids = list(set(result)-set(recur_dict))
if isinstance(select, (str, int, long)):
@ -1371,17 +1370,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
def search(self, cr, uid, args, offset=0, limit=100, order=None,
context=None, count=False):
"""
Overrides orm search method.
@param cr: the current row, from the database cursor,
@param user: the current users ID for security checks,
@param args: list of tuples of form [(name_of_the_field, operator, value), ...].
@param offset: The Number of Results to Pass
@param limit: The Number of Results to Return
@param context: A standard dictionary for contextual values
@param count: If its True the method returns number of records instead of ids
@return: List of id
"""
args_without_date = []
start_date = False
until_date = False
@ -1400,8 +1389,9 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
until_date = arg[2]
res = super(calendar_event, self).search(cr, uid, args_without_date, \
offset, limit, order, context, count)
res = self.get_recurrent_ids(cr, uid, res, start_date, until_date, limit)
print "result normaux", res
res = self.get_recurrent_ids(cr, uid, res, start_date, until_date, limit, context=context)
print "result de merde", res
return res
@ -1626,6 +1616,8 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
if context is None:
context = {}
virtual_id = context.get('virtual_id', False)
if vals.get('vtimezone', '') and vals.get('vtimezone', '').startswith('/freeassociation.sourceforge.net/tzfile/'):
vals['vtimezone'] = vals['vtimezone'][40:]
@ -1640,6 +1632,12 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
res = super(calendar_event, self).create(cr, uid, vals, context)
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date', context=context)
if vals.get('rrule_type') != 'none' and virtual_id:
res = real_id2base_calendar_id(res, vals.get('date', False))
print "id", res
return res
def do_tentative(self, cr, uid, ids, context=None, *args):

View File

@ -50,7 +50,7 @@
<field name="res_model">crm.meeting</field>
<field name="view_mode">calendar,tree,form,gantt</field>
<field name="view_id" ref="crm_case_calendar_view_meet"/>
<field name="context">{"search_default_user_id":uid, 'search_default_section_id': section_id}</field>
<field name="context">{"search_default_user_id":uid, 'search_default_section_id': section_id, 'virtual_id' : True}</field>
<field name="search_view_id" ref="view_crm_case_meetings_filter"/>
<field name="help">The meeting calendar is shared between the sales teams and fully integrated with other applications such as the employee holidays or the business opportunities. You can also synchronize meetings with your mobile phone using the caldav interface.
</field>