diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index b2ca2af3b0b..5c8aa460da0 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -710,15 +710,6 @@ class calendar_event(osv.osv): def _tz_get(self, cr, uid, context={}): return [(x.lower(), x) for x in pytz.all_timezones] - def onchange_rrule_type(self, cr, uid, ids, rtype, *args, **argv): - if rtype == 'none' or not rtype: - return {'value': {'rrule': ''}} - if rtype == 'custom': - return {} - rrule = self.pool.get('calendar.custom.rrule') - rrulestr = rrule.compute_rule_string(cr, uid, {'freq': rtype.upper(), \ - 'interval': 1}) - return {'value': {'rrule': rrulestr}} def onchange_dates(self, cr, uid, ids, start_date, duration=False, end_date=False, context={}): if not start_date: @@ -735,6 +726,22 @@ class calendar_event(osv.osv): value['date_deadline'] = end.strftime("%Y-%m-%d %H:%M:%S") return {'value': value} + def _get_rulestring(self, cr, uid, ids, name, arg, context=None): + result = {} + for event in ids: + datas = self.read(cr, uid, ids)[0] + if datas.get('rrule_type'): + if datas.get('rrule_type') == 'none': + result[event] = False + elif datas.get('rrule_type') == 'custom': + rrule_custom = self.compute_rule_string(cr, uid, datas) + result[event] = rrule_custom + else: + result[event] = self.compute_rule_string(cr, uid, {'freq':\ + datas.get('rrule_type').upper(), \ + 'interval': 1}, context=context) + return result + _columns = { 'id': fields.integer('ID'), 'sequence': fields.integer('Sequence'), @@ -755,7 +762,7 @@ class calendar_event(osv.osv): defines the list of date/time exceptions for arecurring calendar component."), 'exrule': fields.char('Exception Rule', size=352, help="defines a \ rule or repeating pattern for anexception to a recurrence set"), - 'rrule': fields.char('Recurrent Rule', size=124), + 'rrule': fields.function(_get_rulestring, type='char', size=124, method=True, string='Recurrent Rule', store=True), 'rrule_type': fields.selection([('none', ''), ('daily', 'Daily'), \ ('weekly', 'Weekly'), ('monthly', 'Monthly'), \ ('yearly', 'Yearly'), ('custom', 'Custom')], 'Recurrency'), @@ -764,15 +771,48 @@ rule or repeating pattern for anexception to a recurrence set"), 'recurrent_uid': fields.integer('Recurrent ID'), 'recurrent_id': fields.datetime('Recurrent ID date'), 'vtimezone': fields.related('user_id', 'context_tz', type='char', size=24, string='Timezone'), - 'user_id': fields.many2one('res.users', 'Responsible'), + 'user_id': fields.many2one('res.users', 'Responsible'), + 'freq': fields.selection([('None', 'No Repeat'), \ + ('secondly', 'Secondly'), \ + ('minutely', 'Minutely'), \ + ('hourly', 'Hourly'), \ + ('daily', 'Daily'), \ + ('weekly', 'Weekly'), \ + ('monthly', 'Monthly'), \ + ('yearly', 'Yearly')], 'Frequency'), + 'interval': fields.integer('Interval'), + 'count': fields.integer('Count'), + 'mo': fields.boolean('Mon'), + 'tu': fields.boolean('Tue'), + 'we': fields.boolean('Wed'), + 'th': fields.boolean('Thu'), + 'fr': fields.boolean('Fri'), + 'sa': fields.boolean('Sat'), + 'su': fields.boolean('Sun'), + 'select1': fields.selection([('date', 'Date of month'), \ + ('day', 'Day of month')], 'Option'), + 'day': fields.integer('Date of month'), + 'week_list': fields.selection([('MO', 'Monday'), ('TU', 'Tuesday'), \ + ('WE', 'Wednesday'), ('TH', 'Thursday'), \ + ('FR', 'Friday'), ('SA', 'Saturday'), \ + ('SU', 'Sunday')], 'Weekday'), + 'byday': fields.selection([('1', 'First'), ('2', 'Second'), \ + ('3', 'Third'), ('4', 'Fourth'), \ + ('5', 'Fifth'), ('-1', 'Last')], 'By day'), + 'month_list': fields.selection(months.items(), 'Month'), + 'end_date': fields.date('Repeat Until') } _defaults = { 'class': lambda *a: 'public', 'show_as': lambda *a: 'busy', + 'freq': lambda *x: 'None', + 'select1': lambda *x: 'date', + 'interval': lambda *x: 1, } def modify_this(self, cr, uid, ids, defaults, context=None, *args): + ids = map(lambda x: base_calendar_id2real_id(x), ids) datas = self.read(cr, uid, ids[0], context=context) defaults.update({ 'recurrent_uid': base_calendar_id2real_id(datas['id']), @@ -781,11 +821,27 @@ rule or repeating pattern for anexception to a recurrence set"), 'rrule': '' }) exdate = datas['exdate'] and datas['exdate'].split(',') or [] - exdate.append(defaults.get('date')) + if defaults.get('date'): + exdate.append(defaults.get('date')) self.write(cr, uid, ids, {'exdate': ','.join(exdate)}, context=context) new_id = self.copy(cr, uid, ids[0], default=defaults, context=context) return new_id + def modify_all(self, cr, uid, ids, defaults, context=None, *args): + ids = map(lambda x: base_calendar_id2real_id(x), ids) + defaults.pop('id') + defaults.update({'table': self._table}) + + qry = "UPDATE %(table)s set name='%(name)s', \ + date='%(date)s', date_deadline='%(date_deadline)s'" + if defaults.get('alarm_id'): + qry += ", alarm_id=%(alarm_id)s" + if defaults.get('location'): + qry += ", location='%(location)s'" + qry += "WHERE id=%s" % (ids[0]) + cr.execute(qry % (defaults)) + return True + def get_recurrent_ids(self, cr, uid, select, base_start_date, base_until_date, limit=100): if not limit: limit = 100 @@ -858,6 +914,50 @@ rule or repeating pattern for anexception to a recurrence set"), return ids and ids[0] or False return ids + def compute_rule_string(self, cr, uid, datas, context=None, *args): + weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'] + weekstring = '' + monthstring = '' + yearstring = '' +# logic for computing rrule string + freq = datas.get('freq') + if freq == 'None': + return '' + + if freq == 'weekly': + byday = map(lambda x: x.upper(), filter(lambda x: datas.get(x) and x in weekdays, datas)) + if byday: + weekstring = ';BYDAY=' + ','.join(byday) + + elif freq == 'monthly': + if datas.get('select1')=='date' and (datas.get('day') < 1 or datas.get('day') > 31): + raise osv.except_osv(_('Error!'), ("Please select proper Day of month")) + if datas.get('select1')=='day': + monthstring = ';BYDAY=' + datas.get('byday') + datas.get('week_list') + elif datas.get('select1')=='date': + monthstring = ';BYMONTHDAY=' + str(datas.get('day')) + + elif freq == 'yearly': + if datas.get('select1')=='date' and (datas.get('day') < 1 or datas.get('day') > 31): + raise osv.except_osv(_('Error!'), ("Please select proper Day of month")) + bymonth = ';BYMONTH=' + str(datas.get('month_list')) + if datas.get('select1')=='day': + bystring = ';BYDAY=' + datas.get('byday') + datas.get('week_list') + elif datas.get('select1')=='date': + bystring = ';BYMONTHDAY=' + str(datas.get('day')) + yearstring = bymonth + bystring + + if datas.get('end_date'): + datas['end_date'] = ''.join((re.compile('\d')).findall(datas.get('end_date'))) + '235959Z' + enddate = (datas.get('count') and (';COUNT=' + str(datas.get('count'))) or '') +\ + ((datas.get('end_date') and (';UNTIL=' + datas.get('end_date'))) or '') + + rrule_string = 'FREQ=' + freq.upper() + weekstring + ';INTERVAL=' + \ + str(datas.get('interval')) + enddate + monthstring + yearstring + +# End logic + return rrule_string + def search(self, cr, uid, args, offset=0, limit=100, order=None, context=None, count=False): args_without_date = [] @@ -885,6 +985,10 @@ rule or repeating pattern for anexception to a recurrence set"), select = ids new_ids = [] for id in select: + if len(str(id).split('-')) > 1: + data = self.read(cr, uid, id, ['date', 'date_deadline']) + self.modify_this(cr, uid, [id], vals, context) + continue id = base_calendar_id2real_id(id) if not id in new_ids: new_ids.append(id) @@ -1072,114 +1176,6 @@ class virtual_report_spool(web_services.report_spool): virtual_report_spool() -class calendar_custom_rrule(osv.osv): - _name = "calendar.custom.rrule" - _description = "Custom Recurrency Rule" - - _columns = { - 'freq': fields.selection([('None', 'No Repeat'), \ - ('secondly', 'Secondly'), \ - ('minutely', 'Minutely'), \ - ('hourly', 'Hourly'), \ - ('daily', 'Daily'), \ - ('weekly', 'Weekly'), \ - ('monthly', 'Monthly'), \ - ('yearly', 'Yearly')], 'Frequency', required=True), - 'interval': fields.integer('Interval'), - 'count': fields.integer('Count'), - 'mo': fields.boolean('Mon'), - 'tu': fields.boolean('Tue'), - 'we': fields.boolean('Wed'), - 'th': fields.boolean('Thu'), - 'fr': fields.boolean('Fri'), - 'sa': fields.boolean('Sat'), - 'su': fields.boolean('Sun'), - 'select1': fields.selection([('date', 'Date of month'), \ - ('day', 'Day of month')], 'Option'), - 'day': fields.integer('Date of month'), - 'week_list': fields.selection([('MO', 'Monday'), ('TU', 'Tuesday'), \ - ('WE', 'Wednesday'), ('TH', 'Thursday'), \ - ('FR', 'Friday'), ('SA', 'Saturday'), \ - ('SU', 'Sunday')], 'Weekday'), - 'byday': fields.selection([('1', 'First'), ('2', 'Second'), \ - ('3', 'Third'), ('4', 'Fourth'), \ - ('5', 'Fifth'), ('-1', 'Last')], 'By day'), - 'month_list': fields.selection(months.items(), 'Month'), - 'end_date': fields.date('Repeat Until') - } - - _defaults = { - 'freq': lambda *x: 'daily', - 'select1': lambda *x: 'date', - 'interval': lambda *x: 1, - } - - def compute_rule_string(self, cr, uid, datas, context=None, *args): - weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'] - weekstring = '' - monthstring = '' - yearstring = '' - -# logic for computing rrule string - - freq = datas.get('freq') - if freq == 'None': - obj.write(cr, uid, [res_obj.id], {'rrule': ''}) - return {} - - if freq == 'weekly': - byday = map(lambda x: x.upper(), filter(lambda x: datas.get(x) and x in weekdays, datas)) - if byday: - weekstring = ';BYDAY=' + ','.join(byday) - - elif freq == 'monthly': - if datas.get('select1')=='date' and (datas.get('day') < 1 or datas.get('day') > 31): - raise osv.except_osv(_('Error!'), ("Please select proper Day of month")) - if datas.get('select1')=='day': - monthstring = ';BYDAY=' + datas.get('byday') + datas.get('week_list') - elif datas.get('select1')=='date': - monthstring = ';BYMONTHDAY=' + str(datas.get('day')) - - elif freq == 'yearly': - if datas.get('select1')=='date' and (datas.get('day') < 1 or datas.get('day') > 31): - raise osv.except_osv(_('Error!'), ("Please select proper Day of month")) - bymonth = ';BYMONTH=' + str(datas.get('month_list')) - if datas.get('select1')=='day': - bystring = ';BYDAY=' + datas.get('byday') + datas.get('week_list') - elif datas.get('select1')=='date': - bystring = ';BYMONTHDAY=' + str(datas.get('day')) - yearstring = bymonth + bystring - - if datas.get('end_date'): - datas['end_date'] = ''.join((re.compile('\d')).findall(datas.get('end_date'))) + '235959Z' - enddate = (datas.get('count') and (';COUNT=' + str(datas.get('count'))) or '') +\ - ((datas.get('end_date') and (';UNTIL=' + datas.get('end_date'))) or '') - - rrule_string = 'FREQ=' + freq.upper() + weekstring + ';INTERVAL=' + \ - str(datas.get('interval')) + enddate + monthstring + yearstring - -# End logic - return rrule_string - - def do_add(self, cr, uid, ids, context={}): - datas = self.read(cr, uid, ids)[0] - if datas.get('interval') <= 0: - raise osv.except_osv(_('Error!'), ("Please select proper Interval")) - - - if not context or not context.get('model'): - return {} - else: - model = context.get('model') - obj = self.pool.get(model) - res_obj = obj.browse(cr, uid, context['active_id']) - - rrule_string = self.compute_rule_string(cr, uid, datas) - obj.write(cr, uid, [res_obj.id], {'rrule': rrule_string}) - return {} - -calendar_custom_rrule() - class res_users(osv.osv): _inherit = 'res.users' @@ -1198,7 +1194,7 @@ class res_users(osv.osv): status = 'busy' res.update({user_id:status}) - #TOCHECK: Delegrated Event + #TOCHECK: Delegated Event for user_id in ids: if user_id not in res: res[user_id] = 'free' @@ -1214,4 +1210,5 @@ class res_users(osv.osv): string='Free/Busy', method=True), } res_users() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_calendar/base_calendar_view.xml b/addons/base_calendar/base_calendar_view.xml index 59e426c2c09..d6430ca98a2 100644 --- a/addons/base_calendar/base_calendar_view.xml +++ b/addons/base_calendar/base_calendar_view.xml @@ -173,71 +173,6 @@ tree,form - - Custom Rule - calendar.custom.rrule - form - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -