[IMP] event_track_calendar_event*:

change behaviour to allow multiple dates (calendar events) to event tracks
This commit is contained in:
clementthomas
2024-02-28 12:03:30 +01:00
parent a8467735f2
commit 3ed3a7fae4
8 changed files with 96 additions and 65 deletions

View File

@@ -1,3 +1,2 @@
from . import event_event
from . import event_track
from . import event_track_location

View File

@@ -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

View File

@@ -1,12 +1,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models, api, Command, _
from datetime import timedelta
from odoo.tools import format_date
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')
@@ -17,31 +17,28 @@ class EventTrack(models.Model):
location_already_in_use = False
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_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)
#search if other calendar event exists for same day on same location
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_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:
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"
if other_calendar_events:
location_already_in_use = True
for other_calendar_event in other_calendar_events:
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_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
"""