[NEW] event_track_calendar_event_event_track_location:
manage event track location calendar
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
@@ -0,0 +1,29 @@
|
|||||||
|
# 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 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,
|
||||||
|
}
|
@@ -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
|
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<!-- EVENTS/CONFIGURATION/EVENT locations -->
|
||||||
|
<record model="ir.ui.view" id="view_event_location_form_inherit_event_track_location_calendar">
|
||||||
|
<field name="name">Event Locations inherit for event track location calendar</field>
|
||||||
|
<field name="model">event.track.location</field>
|
||||||
|
<field name="inherit_id" ref="website_event_track.view_event_location_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='name']" position="after">
|
||||||
|
<field name="partner_id" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="view_event_location_tree_inherit_event_track_location_calendar">
|
||||||
|
<field name="name">Event Location</field>
|
||||||
|
<field name="model">event.track.location</field>
|
||||||
|
<field name="inherit_id" ref="website_event_track.view_event_location_tree" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='name']" position="after">
|
||||||
|
<field name="partner_id" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<odoo>
|
||||||
|
<record model="ir.ui.view" id="view_event_track_form_inherit_event_track_location_calendar">
|
||||||
|
<field name="name">event.track.form inherit for event track location calendar</field>
|
||||||
|
<field name="model">event.track</field>
|
||||||
|
<field name="inherit_id" ref="website_event_track.view_event_track_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//header" position="after">
|
||||||
|
<field name="location_already_in_use" invisible="1" />
|
||||||
|
<div attrs="{'invisible':[('location_already_in_use','=',False)]}" class="alert alert-warning mb-0" role="alert">
|
||||||
|
<strong>Location already in use for this date !</strong><field name="location_already_in_use_message" />
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
Reference in New Issue
Block a user