[IMP] event_track_calendar_event*:
change behaviour to allow multiple dates (calendar events) to event tracks
This commit is contained in:
@@ -9,17 +9,17 @@
|
|||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://www.elabore.coop",
|
"website": "https://www.elabore.coop",
|
||||||
"category": "",
|
"category": "",
|
||||||
'summary': 'Link event tracks to calendar event',
|
'summary': 'Replace date of event track with list of calendar events',
|
||||||
'description': """
|
'description': """
|
||||||
Link event tracks to calendar event
|
Replace date of event track with list of calendar events
|
||||||
----------------------------------------------------
|
----------------------------------------------------
|
||||||
* Create calendar event on event track creation
|
* Create calendar events on event track form
|
||||||
* Update calendar event on event track update
|
* Sync calendar event attendees with event track registration
|
||||||
* Update event track when calendar event updated
|
|
||||||
|
|
||||||
""",
|
""",
|
||||||
"depends": ["website_event_track","calendar"],
|
"depends": ["website_event_track","calendar"],
|
||||||
"data": [
|
"data": [
|
||||||
|
"views/event_track_views.xml"
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from . import calendar_event
|
from . import calendar_event
|
||||||
from . import event_event
|
|
||||||
from . import event_registration
|
|
||||||
from . import event_track
|
from . import event_track
|
||||||
|
from . import event_registration
|
||||||
|
from . import event_event
|
@@ -1,8 +1,17 @@
|
|||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
from odoo import fields, models
|
from odoo import fields, models, api, Command
|
||||||
|
|
||||||
|
|
||||||
class CalendarEvent(models.Model):
|
class CalendarEvent(models.Model):
|
||||||
_inherit = 'calendar.event'
|
_inherit = 'calendar.event'
|
||||||
|
|
||||||
|
event_track_id = fields.Many2one('event.track', "Event track")
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
res = super(CalendarEvent,self).create(vals_list)
|
||||||
|
for event in res:
|
||||||
|
if event.event_track_id:
|
||||||
|
event.event_track_id.sync_calendar_event()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -6,8 +6,26 @@ from datetime import timedelta
|
|||||||
class EventTrack(models.Model):
|
class EventTrack(models.Model):
|
||||||
_inherit = "event.track"
|
_inherit = "event.track"
|
||||||
|
|
||||||
calendar_event = fields.Many2one('calendar.event', 'Calendar event')
|
calendar_event_ids = fields.One2many('calendar.event', 'event_track_id', 'Days')
|
||||||
|
date = fields.Datetime(compute="_compute_date")
|
||||||
|
|
||||||
|
def _compute_date(self):
|
||||||
|
"""Date become a field computed from first calendar event date
|
||||||
|
"""
|
||||||
|
for event_track in self:
|
||||||
|
if event_track.calendar_event_ids:
|
||||||
|
event_track.date = event_track.calendar_event_ids.sorted(key=lambda r: r.start)[0].start
|
||||||
|
else:
|
||||||
|
event_track.date = None
|
||||||
|
|
||||||
|
def get_calendar_event_values(self):
|
||||||
|
"""return default values of calendar events
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'partner_ids':[Command.set(self.get_calendar_event_partner_value())],
|
||||||
|
'location':self.location_id.name if self.location_id else '',
|
||||||
|
'user_id':self.user_id.id
|
||||||
|
}
|
||||||
|
|
||||||
def get_calendar_event_partner_value(self):
|
def get_calendar_event_partner_value(self):
|
||||||
"""Compute list of partner ids for calendar event
|
"""Compute list of partner ids for calendar event
|
||||||
@@ -23,36 +41,28 @@ class EventTrack(models.Model):
|
|||||||
partner_ids.extend([registration.partner_id.id for registration in self.event_id.registration_ids if registration.partner_id])
|
partner_ids.extend([registration.partner_id.id for registration in self.event_id.registration_ids if registration.partner_id])
|
||||||
|
|
||||||
return partner_ids
|
return partner_ids
|
||||||
|
|
||||||
|
|
||||||
def get_calendar_event_values(self):
|
|
||||||
self.ensure_one()
|
|
||||||
|
|
||||||
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(self.get_calendar_event_partner_value())],
|
|
||||||
'name':self.event_id.name+' - '+self.name,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def sync_calendar_event(self):
|
def sync_calendar_event(self):
|
||||||
|
"""synchronize calendar event values with event track data
|
||||||
|
"""
|
||||||
for track in self:
|
for track in self:
|
||||||
if not track.calendar_event:
|
track.calendar_event_ids.write(track.get_calendar_event_values())
|
||||||
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
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
|
"""
|
||||||
|
after creation of event track synchronise calendar event values
|
||||||
|
"""
|
||||||
res = super(EventTrack, self).create(vals_list)
|
res = super(EventTrack, self).create(vals_list)
|
||||||
for track in res:
|
res.sync_calendar_event()
|
||||||
track.sync_calendar_event()
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
"""
|
||||||
|
after modification of event track synchronise calendar event values
|
||||||
|
"""
|
||||||
res = super().write(vals)
|
res = super().write(vals)
|
||||||
self.sync_calendar_event()
|
self.sync_calendar_event()
|
||||||
return res
|
return res
|
||||||
|
29
event_track_calendar_event/views/event_track_views.xml
Normal file
29
event_track_calendar_event/views/event_track_views.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record model="ir.ui.view" id="view_event_track_form_ctl_training_customization">
|
||||||
|
<field name="name">event.track.form.ctl.training.customization</field>
|
||||||
|
<field name="inherit_id" ref="website_event_track.view_event_track_form" />
|
||||||
|
<field name="model">event.track</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<!--
|
||||||
|
Replace date with calendar events
|
||||||
|
-->
|
||||||
|
<field name="date" position="replace">
|
||||||
|
<field name="calendar_event_ids" context="{'default_name':name}" colspan="2">
|
||||||
|
<tree default_order="start,stop" editable="bottom">
|
||||||
|
<field name="name" string="Name" invisible="1" />
|
||||||
|
<field name="start" string="From" />
|
||||||
|
<field name="stop" string="To" />
|
||||||
|
</tree>
|
||||||
|
<form>
|
||||||
|
<group>
|
||||||
|
<field name="name" string="Name" />
|
||||||
|
<field name="start" string="From" />
|
||||||
|
<field name="stop" string="To" />
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
@@ -1,3 +1,2 @@
|
|||||||
from . import event_event
|
|
||||||
from . import event_track
|
from . import event_track
|
||||||
from . import event_track_location
|
from . import event_track_location
|
@@ -1,13 +0,0 @@
|
|||||||
# 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
|
|
@@ -1,12 +1,12 @@
|
|||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
from odoo import fields, models, api, Command, _
|
from odoo import fields, models, api, Command, _
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from odoo.tools import format_date
|
||||||
|
|
||||||
|
|
||||||
class EventTrack(models.Model):
|
class EventTrack(models.Model):
|
||||||
_inherit = "event.track"
|
_inherit = "event.track"
|
||||||
|
|
||||||
calendar_event = fields.Many2one('calendar.event', 'Calendar event')
|
|
||||||
|
|
||||||
location_already_in_use = fields.Boolean('Location already in use', compute='_compute_location_already_in_use')
|
location_already_in_use = fields.Boolean('Location already in use', compute='_compute_location_already_in_use')
|
||||||
location_already_in_use_message = fields.Text(compute='_compute_location_already_in_use')
|
location_already_in_use_message = fields.Text(compute='_compute_location_already_in_use')
|
||||||
@@ -17,31 +17,28 @@ class EventTrack(models.Model):
|
|||||||
location_already_in_use = False
|
location_already_in_use = False
|
||||||
location_already_in_use_message = ""
|
location_already_in_use_message = ""
|
||||||
|
|
||||||
if track.location_id and track.date:
|
for calendar_event in track.calendar_event_ids:
|
||||||
|
if track.location_id and calendar_event.start:
|
||||||
|
|
||||||
#search if other track exists for same day on same location
|
#search if other calendar event exists for same day on same location
|
||||||
search_other_tracks = [('location_id','=',track.location_id.id),('date','>',track.date.replace(hour=0,minute=0)),('date','<',track.date.replace(hour=23,minute=59))]
|
search_other_calendar_events = [('event_track_id.location_id','=',track.location_id.id),('start','>=',calendar_event.start.replace(hour=0,minute=0)),('start','<=',calendar_event.start.replace(hour=23,minute=59))]
|
||||||
if track.id or track.id.origin:
|
|
||||||
search_other_tracks.append(('id','!=',track.id or track.id.origin))
|
if track.id or track.id.origin:
|
||||||
other_tracks = self.search(search_other_tracks)
|
search_other_calendar_events.append(('event_track_id','!=',track.id or track.id.origin))
|
||||||
|
other_calendar_events = self.env["calendar.event"].search(search_other_calendar_events)
|
||||||
|
|
||||||
if other_tracks:
|
if other_calendar_events:
|
||||||
location_already_in_use = True
|
location_already_in_use = True
|
||||||
for other_track in other_tracks:
|
for other_calendar_event in other_calendar_events:
|
||||||
location_already_in_use_message += other_track.event_id.name+" - "+other_track.name+"\n"
|
location_already_in_use_message += other_calendar_event.event_track_id.event_id.name+" - "+\
|
||||||
|
other_calendar_event.event_track_id.name+\
|
||||||
|
" ("+format_date(self.env, other_calendar_event.start)+")"+"\n"
|
||||||
|
|
||||||
track.location_already_in_use = location_already_in_use
|
track.location_already_in_use = location_already_in_use
|
||||||
track.location_already_in_use_message = location_already_in_use_message
|
track.location_already_in_use_message = location_already_in_use_message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_calendar_event_values(self):
|
|
||||||
self.ensure_one()
|
|
||||||
res = super(EventTrack, self).get_calendar_event_values()
|
|
||||||
res['location'] = self.location_id.name
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
def get_calendar_event_partner_value(self):
|
def get_calendar_event_partner_value(self):
|
||||||
"""Add event track location partner to list of partner ids
|
"""Add event track location partner to list of partner ids
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user