event_event.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. class Event(models.Model):
  5. _inherit = "event.event"
  6. meeting_room_ids = fields.One2many("event.meeting.room", "event_id", string="Meeting rooms")
  7. meeting_room_count = fields.Integer("Room count", compute="_compute_meeting_room_count")
  8. meeting_room_allow_creation = fields.Boolean(
  9. "Allow Room Creation", compute="_compute_meeting_room_allow_creation",
  10. readonly=False, store=True,
  11. help="Let Visitors Create Rooms")
  12. @api.depends("event_type_id", "website_menu", "community_menu")
  13. def _compute_community_menu(self):
  14. """ At type onchange: synchronize. At website_menu update: synchronize. """
  15. for event in self:
  16. if event.event_type_id and event.event_type_id != event._origin.event_type_id:
  17. event.community_menu = event.event_type_id.community_menu
  18. elif event.website_menu and (event.website_menu != event._origin.website_menu or not event.community_menu):
  19. event.community_menu = True
  20. elif not event.website_menu:
  21. event.community_menu = False
  22. @api.depends("meeting_room_ids")
  23. def _compute_meeting_room_count(self):
  24. meeting_room_count = self.env["event.meeting.room"].sudo()._read_group(
  25. domain=[("event_id", "in", self.ids)],
  26. fields=["id:count"],
  27. groupby=["event_id"],
  28. )
  29. meeting_room_count = {
  30. result["event_id"][0]: result["event_id_count"]
  31. for result in meeting_room_count
  32. }
  33. for event in self:
  34. event.meeting_room_count = meeting_room_count.get(event.id, 0)
  35. @api.depends("event_type_id", "community_menu", "meeting_room_allow_creation")
  36. def _compute_meeting_room_allow_creation(self):
  37. for event in self:
  38. if event.event_type_id and event.event_type_id != event._origin.event_type_id:
  39. event.meeting_room_allow_creation = event.event_type_id.meeting_room_allow_creation
  40. elif event.community_menu and event.community_menu != event._origin.community_menu:
  41. event.meeting_room_allow_creation = True
  42. elif not event.community_menu or not event.meeting_room_allow_creation:
  43. event.meeting_room_allow_creation = False