From 7498057ef23298873e244fe5734cd36308a15760 Mon Sep 17 00:00:00 2001 From: clementthomas Date: Wed, 24 Jan 2024 22:25:08 +0100 Subject: [PATCH] [NEW] event_track_calendar_event_event_track_location: manage event track location calendar --- .../__init__.py | 1 + .../__manifest__.py | 29 ++++++++++ .../models/__init__.py | 3 ++ .../models/event_event.py | 13 +++++ .../models/event_track.py | 54 +++++++++++++++++++ .../models/event_track_location.py | 17 ++++++ .../views/event_track_location_views.xml | 28 ++++++++++ .../views/event_track_views.xml | 17 ++++++ 8 files changed, 162 insertions(+) create mode 100644 event_track_calendar_event_event_track_location/__init__.py create mode 100644 event_track_calendar_event_event_track_location/__manifest__.py create mode 100644 event_track_calendar_event_event_track_location/models/__init__.py create mode 100644 event_track_calendar_event_event_track_location/models/event_event.py create mode 100644 event_track_calendar_event_event_track_location/models/event_track.py create mode 100644 event_track_calendar_event_event_track_location/models/event_track_location.py create mode 100644 event_track_calendar_event_event_track_location/views/event_track_location_views.xml create mode 100644 event_track_calendar_event_event_track_location/views/event_track_views.xml diff --git a/event_track_calendar_event_event_track_location/__init__.py b/event_track_calendar_event_event_track_location/__init__.py new file mode 100644 index 0000000..9a7e03e --- /dev/null +++ b/event_track_calendar_event_event_track_location/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/event_track_calendar_event_event_track_location/__manifest__.py b/event_track_calendar_event_event_track_location/__manifest__.py new file mode 100644 index 0000000..f902839 --- /dev/null +++ b/event_track_calendar_event_event_track_location/__manifest__.py @@ -0,0 +1,29 @@ +# Copyright 2016-2020 Akretion France () +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Event track location in calendar event", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Elabore", + "website": "https://www.elabore.coop", + "category": "", + 'summary': 'Link event tracks locations to calendar event', + 'description': """ +Link event tracks locations to calendar event +---------------------------------------------------- +* Add Partner field on event track location +* Add partner "location" to calendar event +* Update calendar event if event track location change (or partner in event track location) +* Alert if location is used + + +""", + "depends": ["website_event_track","calendar"], + "data": [ + 'views/event_track_location_views.xml', + 'views/event_track_views.xml' + ], + "installable": True, +} diff --git a/event_track_calendar_event_event_track_location/models/__init__.py b/event_track_calendar_event_event_track_location/models/__init__.py new file mode 100644 index 0000000..4452179 --- /dev/null +++ b/event_track_calendar_event_event_track_location/models/__init__.py @@ -0,0 +1,3 @@ +from . import event_event +from . import event_track +from . import event_track_location \ No newline at end of file diff --git a/event_track_calendar_event_event_track_location/models/event_event.py b/event_track_calendar_event_event_track_location/models/event_event.py new file mode 100644 index 0000000..1d3e665 --- /dev/null +++ b/event_track_calendar_event_event_track_location/models/event_event.py @@ -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 diff --git a/event_track_calendar_event_event_track_location/models/event_track.py b/event_track_calendar_event_event_track_location/models/event_track.py new file mode 100644 index 0000000..3ab3a52 --- /dev/null +++ b/event_track_calendar_event_event_track_location/models/event_track.py @@ -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 + + \ No newline at end of file diff --git a/event_track_calendar_event_event_track_location/models/event_track_location.py b/event_track_calendar_event_event_track_location/models/event_track_location.py new file mode 100644 index 0000000..60edde1 --- /dev/null +++ b/event_track_calendar_event_event_track_location/models/event_track_location.py @@ -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 \ No newline at end of file diff --git a/event_track_calendar_event_event_track_location/views/event_track_location_views.xml b/event_track_calendar_event_event_track_location/views/event_track_location_views.xml new file mode 100644 index 0000000..dabd3f0 --- /dev/null +++ b/event_track_calendar_event_event_track_location/views/event_track_location_views.xml @@ -0,0 +1,28 @@ + + + + + + Event Locations inherit for event track location calendar + event.track.location + + + + + + + + + + Event Location + event.track.location + + + + + + + + + + diff --git a/event_track_calendar_event_event_track_location/views/event_track_views.xml b/event_track_calendar_event_event_track_location/views/event_track_views.xml new file mode 100644 index 0000000..c4dda64 --- /dev/null +++ b/event_track_calendar_event_event_track_location/views/event_track_views.xml @@ -0,0 +1,17 @@ + + + + event.track.form inherit for event track location calendar + event.track + + + + + + + + + +