2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra import api, fields, models
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Meeting(models.Model):
|
|
|
|
|
|
|
|
_inherit = "calendar.event"
|
|
|
|
|
2018-01-16 11:34:37 +01:00
|
|
|
oe_update_date = fields.Datetime('Flectra Update Date')
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def get_fields_need_update_google(self):
|
|
|
|
recurrent_fields = self._get_recurrent_fields()
|
|
|
|
return recurrent_fields + ['name', 'description', 'allday', 'start', 'date_end', 'stop',
|
|
|
|
'attendee_ids', 'alarm_ids', 'location', 'privacy', 'active',
|
|
|
|
'start_date', 'start_datetime', 'stop_date', 'stop_datetime']
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def write(self, values):
|
|
|
|
sync_fields = set(self.get_fields_need_update_google())
|
|
|
|
if (set(values) and sync_fields) and 'oe_update_date' not in values and 'NewMeeting' not in self._context:
|
|
|
|
values['oe_update_date'] = fields.Datetime.now()
|
|
|
|
return super(Meeting, self).write(values)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def copy(self, default=None):
|
|
|
|
default = default or {}
|
|
|
|
if default.get('write_type', False):
|
|
|
|
del default['write_type']
|
|
|
|
elif default.get('recurrent_id', False):
|
|
|
|
default['oe_update_date'] = fields.Datetime.now()
|
|
|
|
else:
|
|
|
|
default['oe_update_date'] = False
|
|
|
|
return super(Meeting, self).copy(default)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def unlink(self, can_be_deleted=False):
|
|
|
|
return super(Meeting, self).unlink(can_be_deleted=can_be_deleted)
|
|
|
|
|
|
|
|
|
|
|
|
class Attendee(models.Model):
|
|
|
|
|
|
|
|
_inherit = 'calendar.attendee'
|
|
|
|
|
|
|
|
google_internal_event_id = fields.Char('Google Calendar Event Id')
|
2018-01-16 11:34:37 +01:00
|
|
|
oe_synchro_date = fields.Datetime('Flectra Synchro Date')
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
_sql_constraints = [
|
|
|
|
('google_id_uniq', 'unique(google_internal_event_id,partner_id,event_id)', 'Google ID should be unique!')
|
|
|
|
]
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def write(self, values):
|
|
|
|
for attendee in self:
|
|
|
|
meeting_id_to_update = values.get('event_id', attendee.event_id.id)
|
|
|
|
|
|
|
|
# If attendees are updated, we need to specify that next synchro need an action
|
|
|
|
# Except if it come from an update_from_google
|
|
|
|
if not self._context.get('curr_attendee', False) and not self._context.get('NewMeeting', False):
|
|
|
|
self.env['calendar.event'].browse(meeting_id_to_update).write({'oe_update_date': fields.Datetime.now()})
|
|
|
|
return super(Attendee, self).write(values)
|