1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- # -*- coding: utf-8 -*-
- # Part of Odoo. See LICENSE file for full copyright and licensing details.
- from odoo import api, fields, models, _
- from odoo.addons.http_routing.models.ir_http import slug
- class Event(models.Model):
- _inherit = "event.event"
- track_ids = fields.One2many('event.track', 'event_id', 'Tracks')
- track_count = fields.Integer('Track Count', compute='_compute_track_count')
- website_track = fields.Boolean(
- 'Tracks on Website', compute='_compute_website_track',
- readonly=False, store=True)
- website_track_proposal = fields.Boolean(
- 'Proposals on Website', compute='_compute_website_track_proposal',
- readonly=False, store=True)
- track_menu_ids = fields.One2many('website.event.menu', 'event_id', string='Event Tracks Menus', domain=[('menu_type', '=', 'track')])
- track_proposal_menu_ids = fields.One2many('website.event.menu', 'event_id', string='Event Proposals Menus', domain=[('menu_type', '=', 'track_proposal')])
- allowed_track_tag_ids = fields.Many2many('event.track.tag', relation='event_allowed_track_tags_rel', string='Available Track Tags')
- tracks_tag_ids = fields.Many2many(
- 'event.track.tag', relation='event_track_tags_rel', string='Track Tags',
- compute='_compute_tracks_tag_ids', store=True)
- def _compute_track_count(self):
- data = self.env['event.track']._read_group([('stage_id.is_cancel', '!=', True)], ['event_id'], ['event_id'])
- result = dict((data['event_id'][0], data['event_id_count']) for data in data)
- for event in self:
- event.track_count = result.get(event.id, 0)
- @api.depends('event_type_id', 'website_menu')
- def _compute_website_track(self):
- """ Propagate event_type configuration (only at change); otherwise propagate
- website_menu updated value. Also force True is track_proposal changes. """
- for event in self:
- if event.event_type_id and event.event_type_id != event._origin.event_type_id:
- event.website_track = event.event_type_id.website_track
- elif event.website_menu and (event.website_menu != event._origin.website_menu or not event.website_track):
- event.website_track = True
- elif not event.website_menu:
- event.website_track = False
- @api.depends('event_type_id', 'website_track')
- def _compute_website_track_proposal(self):
- """ Propagate event_type configuration (only at change); otherwise propagate
- website_track updated value (both together True or False at update). """
- for event in self:
- if event.event_type_id and event.event_type_id != event._origin.event_type_id:
- event.website_track_proposal = event.event_type_id.website_track_proposal
- elif event.website_track != event._origin.website_track or not event.website_track or not event.website_track_proposal:
- event.website_track_proposal = event.website_track
- @api.depends('track_ids.tag_ids', 'track_ids.tag_ids.color')
- def _compute_tracks_tag_ids(self):
- for event in self:
- event.tracks_tag_ids = event.track_ids.mapped('tag_ids').filtered(lambda tag: tag.color != 0).ids
- # ------------------------------------------------------------
- # WEBSITE MENU MANAGEMENT
- # ------------------------------------------------------------
- def toggle_website_track(self, val):
- self.website_track = val
- def toggle_website_track_proposal(self, val):
- self.website_track_proposal = val
- def _get_menu_update_fields(self):
- return super(Event, self)._get_menu_update_fields() + ['website_track', 'website_track_proposal']
- def _update_website_menus(self, menus_update_by_field=None):
- super(Event, self)._update_website_menus(menus_update_by_field=menus_update_by_field)
- for event in self:
- if event.menu_id and (not menus_update_by_field or event in menus_update_by_field.get('website_track')):
- event._update_website_menu_entry('website_track', 'track_menu_ids', 'track')
- if event.menu_id and (not menus_update_by_field or event in menus_update_by_field.get('website_track_proposal')):
- event._update_website_menu_entry('website_track_proposal', 'track_proposal_menu_ids', 'track_proposal')
- def _get_menu_type_field_matching(self):
- res = super(Event, self)._get_menu_type_field_matching()
- res['track_proposal'] = 'website_track_proposal'
- return res
- def _get_website_menu_entries(self):
- self.ensure_one()
- return super(Event, self)._get_website_menu_entries() + [
- (_('Talks'), '/event/%s/track' % slug(self), False, 10, 'track'),
- (_('Agenda'), '/event/%s/agenda' % slug(self), False, 70, 'track'),
- (_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False, 15, 'track_proposal')
- ]
|