[IMP]: Caldav: Improvement in rrule wizard for implementing Yearly repeat + Code improvement

bzr revid: rpa@tinyerp.com-20091224110529-ubx5q4ph0rubrnb3
This commit is contained in:
rpa (Open ERP) 2009-12-24 16:35:29 +05:30
parent b16b33b9fb
commit e01bcf3690
2 changed files with 82 additions and 44 deletions

View File

@ -14,7 +14,7 @@
<field name="count"
attrs="{'required' : [('end_date','=',False)]}"/>
<field name="end_date"
attrs="{'required' : [('count','&lt;=',0)]}"/>
attrs="{'required' : [('count','&lt;=',0), ('freq', '!=', 'None')]}"/>
<group col="7" colspan="4" name="Select weekdays"
attrs="{'invisible' : [('freq','!=','WEEKLY')]}">
<separator string="" colspan="6" />
@ -28,21 +28,31 @@
<field name="su" colspan="1" />
<newline />
</group>
<group col="4" colspan="4"
attrs="{'invisible' : [('freq','!=','MONTHLY')]}">
<separator string="" colspan="6" />
<newline />
<field name="day" colspan="1"/>
<newline />
<label string="The"/>
<field name="byday" nolabel="1"
attrs="{'required' : [('day','&lt;=',0)]}"/>
<field name="week_list" nolabel="1"
attrs="{'required' : [('day','&lt;=',0)]}"/>
<label string="of the Month"/>
<newline />
<group col="4" colspan="4" attrs="{'invisible' : [('freq','!=','MONTHLY'), ('freq','!=','YEARLY')]}">
<separator string="" colspan="6"/>
<group col="2" colspan="4">
<field name="select1"/>
</group>
<group col="3" colspan="4" attrs="{'readonly' : [('select1','=','day')]}">
<field name="day" attrs="{'required' : [('select1','=','date')]}"/>
</group>
<newline />
<group col="5" colspan="4" attrs="{'readonly' : [('select1','=','date')]}">
<label string="The" />
<field name="byday" nolabel="1"
attrs="{'required' : [('select1','=','day')]}"/>
<field name="week_list" nolabel="1"
attrs="{'required' : [('select1','=','day')]}"/>
<label string="of the Month" />
<newline />
</group>
<group col="2" colspan="4" attrs="{'invisible' : [('freq','!=','YEARLY')]}">
<field name="month_list" string="of" colspan="1"
attrs="{'required' : [('freq','=','YEARLY')]}"/>
</group>
</group>
<separator string="" colspan="6" />
<label string="" colspan="3"/>
<button name="add_rrule" string="Ok" type="object" icon="gtk-ok"/>
</form>
</field>

View File

@ -30,6 +30,9 @@ def caldevIDs2readIDs(caldev_ID = None):
return int(caldev_ID.split('-')[0])
return caldev_ID
months = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May", 6:"June", \
7:"July", 8:"August", 9:"September", 10:"October", 11:"November", \
12:"December"}
class crm_caldav_attendee(osv.osv):
_name = 'crm.caldav.attendee'
@ -242,73 +245,98 @@ class set_rrule_wizard(osv.osv_memory):
_description = "Set RRULE"
_columns = {
'freq': fields.selection([('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'),
'day': fields.integer('Day of month'),
'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')], 'Select Option'),
'day': fields.integer('Day of month'),
'week_list': fields.selection([('MO', 'Monday'), ('TU', 'Tuesday'), \
('WE', 'Wednesday'), ('TH', 'Thursday'),\
('WE', 'Wednesday'), ('TH', 'Thursday'), \
('FR', 'Friday'), ('SA', 'Saturday'), \
('SU', 'Sunday')], 'Weekday' ),
('SU', 'Sunday')], 'Weekday'),
'byday': fields.selection([('1', 'First'), ('2', 'Second'), \
('3', 'Third'), ('4', 'Fourth'), \
('5', 'Fifth'), ('-1', 'Last')], 'By day' ),
('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 add_rrule(self, cr, uid, ids, context={}):
datas = self.read(cr, uid, ids[0])
datas = self.read(cr, uid, ids)[0]
if not context:
return {}
model = 'crm.case' # for now
obj = self.pool.get(model)
rrule_string = 'TEMP-value'
res_obj = obj.browse(cr, uid, context['active_id'])[0]
weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
weekstring = ''
monthstring = ''
yearstring = ''
# logic for computing rrule string
if datas.get('interval') <= 0:
raise osv.except_osv(_('Error!'),("Please select proper Interval"))
if datas.get('day') > 31:
raise osv.except_osv(_('Error!'),("Please select proper Day of month"))
freq = datas.get('freq')
if freq == 'None':
obj.write(cr, uid, [res_obj.id], {'rrule' : '', 'rdates': ''})
return {}
if datas.get('interval') <= 0:
raise osv.except_osv(_('Error!'), ("Please select proper Interval"))
if freq == 'WEEKLY':
byday = map(lambda x: x.upper(), filter(lambda x: datas.get(x) and x in weekdays, datas))
weekstring = ';BYDAY=' + ','.join(byday)
elif freq == 'MONTHLY':
byday = ''
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('byday') and datas.get('week_list'):
byday = ';BYDAY=' + datas.get('byday') + datas.get('week_list')
monthstring = byday or (';BYMONTHDAY=' + str(datas.get('day')))
monthstring = byday or (';BYMONTHDAY=' + str(datas.get('day')))
elif freq == 'YEARLY':
bymonth = ''
byday = ''
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('byday') and datas.get('week_list'):
byday = ';BYDAY=' + datas.get('byday') + datas.get('week_list')
if datas.get('month_list'):
bymonth = ';BYMONTH=' + str(datas.get('month_list'))
bymonthday = ';BYMONTHDAY=' + str(datas.get('day'))
yearstring = bymonth + (datas.get('day') and bymonthday or '') + byday
if datas.get('end_date'):
datas['end_date'] = ''.join((re.compile('\d')).findall(datas.get('end_date'))) + '235959Z'
enddate_info = (datas.get('count') and (';COUNT=' + str(datas.get('count'))) or '' ) +\
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 + weekstring + ';INTERVAL=' + \
str(datas.get('interval')) + enddate_info + monthstring
str(datas.get('interval')) + enddate + monthstring + yearstring
# End logic
res_obj = obj.browse(cr, uid, context['active_id'])[0]
obj.write(cr, uid, [res_obj.id], {'rrule' : rrule_string})
return {}