PURPOSE Ease chat room management, especially when dealing with meeting rooms and exhibitors in backend: multi edit, avoid name collision, better support of copy with room names, ... SPECIFICATIONS Clean code managing chat rooms: handle most of its management in chat room mixin. It allows to lessen custom code in website_event_meet. Improve sanitize heuristic of chat rooms by avoiding name collision. If a room with a given name already exists, simply increment a counter as suffix. Improve copy management: when copying from the chat.room.mixin on a record with a room set, simply propagate an updated room name. As room_id itself is not kept but a new one is create, it will create a new room with a name avoiding collisions. Allow multi edit for event meeting rooms and exhibitors. It allows notably to publish by batch, and to set exhibitors as having chat rooms by batch. Give default values for max participants count when creating exhibitors so that required field has a default value. Otherwise people forgot it and have to come back on form view to set it. This is due to default value coming from mixin not being propagated to the form view. LINKS Coming from internal feedback while deploying online support Task ID-2314778 PR #55887 X-original-commit d35d6295ae1b50e9ecb4e57c5e7fb6cdd52c8b27
62 lines
2.6 KiB
Python
62 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from uuid import uuid4
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ChatRoom(models.Model):
|
|
""" Store all useful information to manage chat room (currently limited
|
|
to Jitsi). This model embeds all information about the chat room. We do not
|
|
store them in the related mixin (see chat.room.mixin) to avoid to add too
|
|
many fields on the models which want to use the chat room mixin as the
|
|
behavior can be optional in those models.
|
|
|
|
The participant count is automatically updated thanks to the chat room widget
|
|
to avoid having a costly computed field with a members model.
|
|
"""
|
|
_name = "chat.room"
|
|
_description = "Chat Room"
|
|
|
|
def _default_name(self, objname='room'):
|
|
return "odoo-%s-%s" % (objname, str(uuid4())[:8])
|
|
|
|
name = fields.Char(
|
|
"Room Name", required=True, copy=False,
|
|
default=lambda self: self._default_name())
|
|
is_full = fields.Boolean("Full", compute="_compute_is_full")
|
|
jitsi_server_domain = fields.Char(
|
|
'Jitsi Server Domain', compute='_compute_jitsi_server_domain',
|
|
help='The Jitsi server domain can be customized through the settings to use a different server than the default "meet.jit.si"')
|
|
lang_id = fields.Many2one(
|
|
"res.lang", "Language",
|
|
default=lambda self: self.env["res.lang"].search([("code", "=", self.env.user.lang)], limit=1))
|
|
max_capacity = fields.Selection(
|
|
[("4", "4"), ("8", "8"), ("12", "12"), ("16", "16"),
|
|
("20", "20"), ("no_limit", "No limit")], string="Max capacity",
|
|
default="8", required=True)
|
|
participant_count = fields.Integer("Participant count", default=0, copy=False)
|
|
# reporting fields
|
|
last_activity = fields.Datetime(
|
|
"Last Activity", copy=False, readonly=True,
|
|
default=lambda self: fields.Datetime.now())
|
|
max_participant_reached = fields.Integer(
|
|
"Max participant reached", copy=False, readonly=True,
|
|
help="Maximum number of participant reached in the room at the same time")
|
|
|
|
@api.depends("max_capacity", "participant_count")
|
|
def _compute_is_full(self):
|
|
for room in self:
|
|
if room.max_capacity == "no_limit":
|
|
room.is_full = False
|
|
else:
|
|
room.is_full = room.participant_count >= int(room.max_capacity)
|
|
|
|
def _compute_jitsi_server_domain(self):
|
|
jitsi_server_domain = self.env['ir.config_parameter'].sudo().get_param(
|
|
'website_jitsi.jitsi_server_domain', 'meet.jit.si')
|
|
|
|
for room in self:
|
|
room.jitsi_server_domain = jitsi_server_domain
|