event_event.py 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models, _
  4. from odoo.addons.http_routing.models.ir_http import slug
  5. class Event(models.Model):
  6. _inherit = "event.event"
  7. track_ids = fields.One2many('event.track', 'event_id', 'Tracks')
  8. track_count = fields.Integer('Track Count', compute='_compute_track_count')
  9. website_track = fields.Boolean(
  10. 'Tracks on Website', compute='_compute_website_track',
  11. readonly=False, store=True)
  12. website_track_proposal = fields.Boolean(
  13. 'Proposals on Website', compute='_compute_website_track_proposal',
  14. readonly=False, store=True)
  15. track_menu_ids = fields.One2many('website.event.menu', 'event_id', string='Event Tracks Menus', domain=[('menu_type', '=', 'track')])
  16. track_proposal_menu_ids = fields.One2many('website.event.menu', 'event_id', string='Event Proposals Menus', domain=[('menu_type', '=', 'track_proposal')])
  17. allowed_track_tag_ids = fields.Many2many('event.track.tag', relation='event_allowed_track_tags_rel', string='Available Track Tags')
  18. tracks_tag_ids = fields.Many2many(
  19. 'event.track.tag', relation='event_track_tags_rel', string='Track Tags',
  20. compute='_compute_tracks_tag_ids', store=True)
  21. def _compute_track_count(self):
  22. data = self.env['event.track']._read_group([('stage_id.is_cancel', '!=', True)], ['event_id'], ['event_id'])
  23. result = dict((data['event_id'][0], data['event_id_count']) for data in data)
  24. for event in self:
  25. event.track_count = result.get(event.id, 0)
  26. @api.depends('event_type_id', 'website_menu')
  27. def _compute_website_track(self):
  28. """ Propagate event_type configuration (only at change); otherwise propagate
  29. website_menu updated value. Also force True is track_proposal changes. """
  30. for event in self:
  31. if event.event_type_id and event.event_type_id != event._origin.event_type_id:
  32. event.website_track = event.event_type_id.website_track
  33. elif event.website_menu and (event.website_menu != event._origin.website_menu or not event.website_track):
  34. event.website_track = True
  35. elif not event.website_menu:
  36. event.website_track = False
  37. @api.depends('event_type_id', 'website_track')
  38. def _compute_website_track_proposal(self):
  39. """ Propagate event_type configuration (only at change); otherwise propagate
  40. website_track updated value (both together True or False at update). """
  41. for event in self:
  42. if event.event_type_id and event.event_type_id != event._origin.event_type_id:
  43. event.website_track_proposal = event.event_type_id.website_track_proposal
  44. elif event.website_track != event._origin.website_track or not event.website_track or not event.website_track_proposal:
  45. event.website_track_proposal = event.website_track
  46. @api.depends('track_ids.tag_ids', 'track_ids.tag_ids.color')
  47. def _compute_tracks_tag_ids(self):
  48. for event in self:
  49. event.tracks_tag_ids = event.track_ids.mapped('tag_ids').filtered(lambda tag: tag.color != 0).ids
  50. # ------------------------------------------------------------
  51. # WEBSITE MENU MANAGEMENT
  52. # ------------------------------------------------------------
  53. def toggle_website_track(self, val):
  54. self.website_track = val
  55. def toggle_website_track_proposal(self, val):
  56. self.website_track_proposal = val
  57. def _get_menu_update_fields(self):
  58. return super(Event, self)._get_menu_update_fields() + ['website_track', 'website_track_proposal']
  59. def _update_website_menus(self, menus_update_by_field=None):
  60. super(Event, self)._update_website_menus(menus_update_by_field=menus_update_by_field)
  61. for event in self:
  62. if event.menu_id and (not menus_update_by_field or event in menus_update_by_field.get('website_track')):
  63. event._update_website_menu_entry('website_track', 'track_menu_ids', 'track')
  64. if event.menu_id and (not menus_update_by_field or event in menus_update_by_field.get('website_track_proposal')):
  65. event._update_website_menu_entry('website_track_proposal', 'track_proposal_menu_ids', 'track_proposal')
  66. def _get_menu_type_field_matching(self):
  67. res = super(Event, self)._get_menu_type_field_matching()
  68. res['track_proposal'] = 'website_track_proposal'
  69. return res
  70. def _get_website_menu_entries(self):
  71. self.ensure_one()
  72. return super(Event, self)._get_website_menu_entries() + [
  73. (_('Talks'), '/event/%s/track' % slug(self), False, 10, 'track'),
  74. (_('Agenda'), '/event/%s/agenda' % slug(self), False, 70, 'track'),
  75. (_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False, 15, 'track_proposal')
  76. ]