[NEW] event_track_calendar_event_event_track_location:
manage event track location calendar
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from . import event_event
|
||||
from . import event_track
|
||||
from . import event_track_location
|
@@ -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
|
@@ -0,0 +1,54 @@
|
||||
# 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')
|
||||
|
||||
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')
|
||||
|
||||
@api.depends('date', 'duration', 'location_id')
|
||||
def _compute_location_already_in_use(self):
|
||||
for track in self:
|
||||
location_already_in_use = False
|
||||
location_already_in_use_message = ""
|
||||
|
||||
if track.location_id and track.date:
|
||||
|
||||
#search if other track 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))]
|
||||
if track.id or track.id.origin:
|
||||
search_other_tracks.append(('id','!=',track.id or track.id.origin))
|
||||
other_tracks = self.search(search_other_tracks)
|
||||
|
||||
if other_tracks:
|
||||
location_already_in_use = True
|
||||
for other_track in other_tracks:
|
||||
location_already_in_use_message += other_track.event_id.name+" - "+other_track.name+"\n"
|
||||
|
||||
track.location_already_in_use = location_already_in_use
|
||||
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):
|
||||
"""Add event track location partner to list of partner ids
|
||||
"""
|
||||
|
||||
res = super(EventTrack, self).get_calendar_event_partner_value()
|
||||
if self.location_id and self.location_id.partner_id:
|
||||
res.append(self.location_id.partner_id.id)
|
||||
return res
|
||||
|
||||
|
@@ -0,0 +1,17 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class EventTrackLocation(models.Model):
|
||||
_inherit = 'event.track.location'
|
||||
|
||||
partner_id = fields.Many2one('res.partner', 'Address')
|
||||
|
||||
def write(self, vals):
|
||||
"""update calendar events related to event tracks if partner change
|
||||
"""
|
||||
res = super(EventTrackLocation, self).write(vals)
|
||||
if 'partner_id' in vals:
|
||||
event_tracks = self.env['event.track'].search([('location_id','in',self.ids)])
|
||||
event_tracks.sync_calendar_event()
|
||||
return res
|
Reference in New Issue
Block a user