[NEW] event_track_calendar_event*
This commit is contained in:
1
event_track_calendar_event/__init__.py
Normal file
1
event_track_calendar_event/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
25
event_track_calendar_event/__manifest__.py
Normal file
25
event_track_calendar_event/__manifest__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2016-2020 Akretion France (<https://www.akretion.com>)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Event track calendar event",
|
||||
"version": "16.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
"category": "",
|
||||
'summary': 'Link event tracks to calendar event',
|
||||
'description': """
|
||||
Link event tracks to calendar event
|
||||
----------------------------------------------------
|
||||
* Create calendar event on event track creation
|
||||
* Update calendar event on event track update
|
||||
* Update event track when calendar event updated
|
||||
|
||||
""",
|
||||
"depends": ["website_event_track","calendar"],
|
||||
"data": [
|
||||
],
|
||||
"installable": True,
|
||||
}
|
4
event_track_calendar_event/models/__init__.py
Normal file
4
event_track_calendar_event/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from . import calendar_event
|
||||
from . import event_event
|
||||
from . import event_registration
|
||||
from . import event_track
|
8
event_track_calendar_event/models/calendar_event.py
Normal file
8
event_track_calendar_event/models/calendar_event.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class CalendarEvent(models.Model):
|
||||
_inherit = 'calendar.event'
|
||||
|
||||
|
13
event_track_calendar_event/models/event_event.py
Normal file
13
event_track_calendar_event/models/event_event.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
|
||||
|
||||
class EventEvent(models.Model):
|
||||
_inherit = "event.event"
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
for event in self:
|
||||
for track in event.track_ids:
|
||||
track.sync_calendar_event()
|
||||
return res
|
21
event_track_calendar_event/models/event_registration.py
Normal file
21
event_track_calendar_event/models/event_registration.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
|
||||
|
||||
class EventRegistration(models.Model):
|
||||
_inherit = "event.registration"
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
for registration in self:
|
||||
for track in registration.event_id.track_ids:
|
||||
track.sync_calendar_event()
|
||||
return res
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
res = super(EventRegistration, self).create(vals_list)
|
||||
for registration in res:
|
||||
for track in registration.event_id.track_ids:
|
||||
track.sync_calendar_event()
|
||||
return res
|
53
event_track_calendar_event/models/event_track.py
Normal file
53
event_track_calendar_event/models/event_track.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
class EventTrack(models.Model):
|
||||
_inherit = "event.track"
|
||||
|
||||
calendar_event = fields.Many2one('calendar.event', 'Calendar event')
|
||||
|
||||
|
||||
def get_calendar_event_values(self):
|
||||
self.ensure_one()
|
||||
|
||||
# compute list of attendees
|
||||
partner_ids = []
|
||||
|
||||
# add event track contact
|
||||
if self.partner_id:
|
||||
partner_ids.append(self.partner_id.id)
|
||||
|
||||
# add event registration attendees
|
||||
partner_ids.extend([registration.partner_id.id for registration in self.event_id.registration_ids if registration.partner_id])
|
||||
|
||||
|
||||
return {
|
||||
'start':self.date,
|
||||
'duration':self.duration,
|
||||
'stop':self.date + timedelta(minutes=round((self.duration or 1.0) * 60)),
|
||||
'user_id':self.user_id.id,
|
||||
'partner_ids':[Command.set(partner_ids)],
|
||||
'name':self.event_id.name+' - '+self.name,
|
||||
}
|
||||
|
||||
|
||||
def sync_calendar_event(self):
|
||||
for track in self:
|
||||
if not track.calendar_event:
|
||||
track.calendar_event = self.env['calendar.event'].create(track.get_calendar_event_values())
|
||||
else:
|
||||
track.calendar_event.write(track.get_calendar_event_values())
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
res = super(EventTrack, self).create(vals_list)
|
||||
for track in res:
|
||||
track.sync_calendar_event()
|
||||
return res
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
self.sync_calendar_event()
|
||||
return res
|
Reference in New Issue
Block a user