[FIX] calendar: in method write(), process all records and not the last one only
This commit is contained in:
parent
748a719fd9
commit
70fdb5a26e
|
@ -1571,75 +1571,64 @@ class calendar_event(osv.Model):
|
||||||
return super(calendar_event, self)._name_search(cr, user, name=name, args=args, operator=operator, context=context, limit=limit, name_get_uid=name_get_uid)
|
return super(calendar_event, self)._name_search(cr, user, name=name, args=args, operator=operator, context=context, limit=limit, name_get_uid=name_get_uid)
|
||||||
|
|
||||||
def write(self, cr, uid, ids, values, context=None):
|
def write(self, cr, uid, ids, values, context=None):
|
||||||
def _only_changes_to_apply_on_real_ids(field_names):
|
context = context or {}
|
||||||
''' return True if changes are only to be made on the real ids'''
|
|
||||||
for field in field_names:
|
|
||||||
if field in ['start', 'start_date', 'start_datetime', 'stop', 'stop_date', 'stop_datetime', 'active']:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
if not isinstance(ids, (tuple, list)):
|
if not isinstance(ids, (tuple, list)):
|
||||||
ids = [ids]
|
ids = [ids]
|
||||||
|
|
||||||
context = context or {}
|
values0 = values
|
||||||
self._set_date(cr, uid, values, id=ids[0], context=context)
|
|
||||||
|
|
||||||
for one_ids in ids:
|
# process events one by one
|
||||||
if isinstance(one_ids, (basestring, int, long)):
|
for event_id in ids:
|
||||||
if len(str(one_ids).split('-')) == 1:
|
# make a copy, since _set_date() modifies values depending on event
|
||||||
ids = [int(one_ids)]
|
values = dict(values0)
|
||||||
else:
|
self._set_date(cr, uid, values, event_id, context=context)
|
||||||
ids = [one_ids]
|
|
||||||
|
|
||||||
res = False
|
# special write of complex IDS
|
||||||
new_id = False
|
real_ids = []
|
||||||
|
new_ids = []
|
||||||
# Special write of complex IDS
|
if '-' not in str(event_id):
|
||||||
for event_id in list(ids):
|
real_ids = [int(event_id)]
|
||||||
if len(str(event_id).split('-')) == 1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
ids.remove(event_id)
|
|
||||||
real_event_id = calendar_id2real_id(event_id)
|
|
||||||
|
|
||||||
# if we are setting the recurrency flag to False or if we are only changing fields that
|
|
||||||
# should be only updated on the real ID and not on the virtual (like message_follower_ids):
|
|
||||||
# then set real ids to be updated.
|
|
||||||
if not values.get('recurrency', True) or not _only_changes_to_apply_on_real_ids(values.keys()):
|
|
||||||
ids.append(real_event_id)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
data = self.read(cr, uid, event_id, ['start', 'stop', 'rrule', 'duration'])
|
real_event_id = calendar_id2real_id(event_id)
|
||||||
if data.get('rrule'):
|
|
||||||
new_id = self._detach_one_event(cr, uid, event_id, values, context=None)
|
|
||||||
|
|
||||||
res = super(calendar_event, self).write(cr, uid, [int(event_id) for event_id in ids], values, context=context)
|
# if we are setting the recurrency flag to False or if we are only changing fields that
|
||||||
|
# should be only updated on the real ID and not on the virtual (like message_follower_ids):
|
||||||
# set end_date for calendar searching
|
# then set real ids to be updated.
|
||||||
if values.get('recurrency', True) and values.get('end_type', 'count') in ('count', unicode('count')) and \
|
blacklisted = any(key in values for key in ('start', 'stop', 'active'))
|
||||||
(values.get('rrule_type') or values.get('count') or values.get('start') or values.get('stop')):
|
if not values.get('recurrency', True) or not blacklisted:
|
||||||
for id in ids:
|
real_ids = [real_event_id]
|
||||||
final_date = self._get_recurrency_end_date(cr, uid, id, context=context)
|
|
||||||
super(calendar_event, self).write(cr, uid, [id], {'final_date': final_date}, context=context)
|
|
||||||
|
|
||||||
attendees_create = False
|
|
||||||
if values.get('partner_ids', False):
|
|
||||||
attendees_create = self.create_attendees(cr, uid, ids, context)
|
|
||||||
|
|
||||||
if (values.get('start_date') or values.get('start_datetime', False)) and values.get('active', True):
|
|
||||||
the_id = new_id or (ids and int(ids[0]))
|
|
||||||
if the_id:
|
|
||||||
if attendees_create:
|
|
||||||
attendees_create = attendees_create[the_id]
|
|
||||||
mail_to_ids = list(set(attendees_create['old_attendee_ids']) - set(attendees_create['removed_attendee_ids']))
|
|
||||||
else:
|
else:
|
||||||
mail_to_ids = [att.id for att in self.browse(cr, uid, the_id, context=context).attendee_ids]
|
data = self.read(cr, uid, event_id, ['start', 'stop', 'rrule', 'duration'])
|
||||||
|
if data.get('rrule'):
|
||||||
|
new_ids = [self._detach_one_event(cr, uid, event_id, values, context=None)]
|
||||||
|
|
||||||
if mail_to_ids:
|
super(calendar_event, self).write(cr, uid, real_ids, values, context=context)
|
||||||
current_user = self.pool['res.users'].browse(cr, uid, uid, context=context)
|
|
||||||
if self.pool['calendar.attendee']._send_mail_to_attendees(cr, uid, mail_to_ids, template_xmlid='calendar_template_meeting_changedate', email_from=current_user.email, context=context):
|
# set end_date for calendar searching
|
||||||
self.message_post(cr, uid, the_id, body=_("A email has been send to specify that the date has been changed !"), subtype="calendar.subtype_invitation", context=context)
|
if values.get('recurrency') and values.get('end_type', 'count') in ('count', unicode('count')) and \
|
||||||
return res or True and False
|
(values.get('rrule_type') or values.get('count') or values.get('start') or values.get('stop')):
|
||||||
|
for id in real_ids:
|
||||||
|
final_date = self._get_recurrency_end_date(cr, uid, id, context=context)
|
||||||
|
super(calendar_event, self).write(cr, uid, [id], {'final_date': final_date}, context=context)
|
||||||
|
|
||||||
|
attendees_create = False
|
||||||
|
if values.get('partner_ids', False):
|
||||||
|
attendees_create = self.create_attendees(cr, uid, real_ids + new_ids, context)
|
||||||
|
|
||||||
|
if (values.get('start_date') or values.get('start_datetime')) and values.get('active', True):
|
||||||
|
for the_id in real_ids + new_ids:
|
||||||
|
if attendees_create:
|
||||||
|
attendees_create = attendees_create[the_id]
|
||||||
|
mail_to_ids = list(set(attendees_create['old_attendee_ids']) - set(attendees_create['removed_attendee_ids']))
|
||||||
|
else:
|
||||||
|
mail_to_ids = [att.id for att in self.browse(cr, uid, the_id, context=context).attendee_ids]
|
||||||
|
|
||||||
|
if mail_to_ids:
|
||||||
|
current_user = self.pool['res.users'].browse(cr, uid, uid, context=context)
|
||||||
|
if self.pool['calendar.attendee']._send_mail_to_attendees(cr, uid, mail_to_ids, template_xmlid='calendar_template_meeting_changedate', email_from=current_user.email, context=context):
|
||||||
|
self.message_post(cr, uid, the_id, body=_("A email has been send to specify that the date has been changed !"), subtype="calendar.subtype_invitation", context=context)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
def create(self, cr, uid, vals, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
|
|
|
@ -91,5 +91,12 @@
|
||||||
meetings = self.browse(cr, uid, meeting_ids, context)
|
meetings = self.browse(cr, uid, meeting_ids, context)
|
||||||
for meeting in meetings:
|
for meeting in meetings:
|
||||||
assert meeting.description == 'Review code of the module: sync_google_calendar.', 'Description not changed for id: %s' %meeting.id
|
assert meeting.description == 'Review code of the module: sync_google_calendar.', 'Description not changed for id: %s' %meeting.id
|
||||||
|
-
|
||||||
|
I update the description of two meetings, and check that both have been updated
|
||||||
|
-
|
||||||
|
!python {model: calendar.event}: |
|
||||||
|
DESCRIPTION = "Some description"
|
||||||
|
ids = [ref('calendar_event_testmeeting0'), ref('calendar_event_sprintreview0')]
|
||||||
|
self.write(cr, uid, ids, {'description': DESCRIPTION}, context=context)
|
||||||
|
for i, event in enumerate(self.browse(cr, uid, ids, context)):
|
||||||
|
assert event.description == DESCRIPTION, "Event %d has not been updated" % i
|
||||||
|
|
Loading…
Reference in New Issue