[IMP]: base_calendar: [573]: Improvment for changing duration when dates changed from sunbird

bzr revid: rpa@tinyerp.com-20100423124021-0z23njkojxxrd1xk
This commit is contained in:
rpa (Open ERP) 2010-04-23 18:10:21 +05:30
parent 44284e33ff
commit be5e13ab5a
2 changed files with 48 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import pytz
import re
import time
import tools
from caldav import caldav
months = {
1: "January", 2: "February", 3: "March", 4: "April", \
@ -1213,7 +1214,52 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
if isinstance(select, (str, int, long)):
return ids and ids[0] or False
return ids
def check_import(self, cr, uid, vals, context={}):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param vals: Get Values
@param context: A standard dictionary for contextual values
"""
ids = []
model_obj = self.pool.get(context.get('model'))
recur_pool = {}
try:
for val in vals:
exists, r_id = caldav.uid2openobjectid(cr, val['id'], context.get('model'), \
val.get('recurrent_id'))
if val.has_key('create_date'): val.pop('create_date')
u_id = val.get('id', None)
val.pop('id')
if exists and r_id:
val.update({'recurrent_uid': exists})
model_obj.write(cr, uid, [r_id], val)
ids.append(r_id)
elif exists:
# Compute value of duration
if 'date_deadline' in val and 'duration' not in val:
start = datetime.strptime(val['date'], '%Y-%m-%d %H:%M:%S')
end = datetime.strptime(val['date_deadline'], '%Y-%m-%d %H:%M:%S')
diff = end - start
val['duration'] = (diff.seconds/float(86400) + diff.days) * 24
model_obj.write(cr, uid, [exists], val)
ids.append(exists)
else:
if u_id in recur_pool and val.get('recurrent_id'):
val.update({'recurrent_uid': recur_pool[u_id]})
revent_id = model_obj.create(cr, uid, val)
ids.append(revent_id)
else:
event_id = model_obj.create(cr, uid, val)
recur_pool[u_id] = event_id
ids.append(event_id)
except Exception, e:
raise osv.except_osv(('Error !'), (str(e)))
return ids
def compute_rule_string(self, cr, uid, datas, context=None, *args):
"""
Compute rule string.

View File

@ -190,7 +190,7 @@
<field name="date" string="Start Date" required="1" select="1"
on_change="onchange_dates(date,duration,False,allday)" />
<field name="duration" widget="float_time"
on_change="onchange_dates(date,duration,False,allday)" attrs="{'readonly': [('allday', '=', True)]}"/>
on_change="onchange_dates(date,duration,False,allday)" attrs="{'invisible': [('allday', '=', True)]}"/>
<field name="date_deadline" string="End Date" required="1"
on_change="onchange_dates(date,False,date_deadline)" />
<field name="location" />