*: base, account, crm, hr, hr_attendance, test_access_rights The various public methods of the ORM can be override in other models, those overrides sometime don't implement the exact same signature as the original method in the ORM. In this work we sanitize all the overrides to ensure a better compatibility. The background objective is to make it possible to call any public method using kwarg: `search(domain=[...])`. * `search`, the first parameter was renamed from `args` to `domain` in0e9adf7but the overrides were not updated. * `invalidate_models` and `invalidate_recordset`, a new `flush=True` parameter was introduced in9c3b9a4but the overrides were not updated. * `update`, there is a clash between the `update` method responsible for writing on a record and `update` in bus responsible to update the user presence. The bus method has been renamed so it doesn't clash with the ORM. This sanitization comes with a new linter that verifies that all overrides of BaseModel public methods share a compatible signature. The linter has been disabled for `create`, `write` and `default_get` as too many overrides don't respect the signature of BaseModel. closes odoo/odoo#106999 Related: odoo/enterprise#34991 Signed-off-by: Julien Castiaux <juc@odoo.com>
50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
from odoo import models
|
|
from odoo.http import request
|
|
from odoo.addons.bus.websocket import wsrequest
|
|
|
|
|
|
class IrWebsocket(models.AbstractModel):
|
|
_inherit = 'ir.websocket'
|
|
|
|
def _get_im_status(self, data):
|
|
im_status = super()._get_im_status(data)
|
|
if 'mail.guest' in data:
|
|
im_status['Guest'] = self.env['mail.guest'].sudo().with_context(active_test=False).search_read(
|
|
[('id', 'in', data['mail.guest'])],
|
|
['im_status']
|
|
)
|
|
return im_status
|
|
|
|
def _build_bus_channel_list(self, channels):
|
|
# This method can either be called due to an http or a
|
|
# websocket request. The request itself is necessary to
|
|
# retrieve the current guest. Let's retrieve the proper
|
|
# request.
|
|
req = request or wsrequest
|
|
channels = list(channels) # do not alter original list
|
|
guest_sudo = self.env['mail.guest']._get_guest_from_request(req).sudo()
|
|
mail_channels = self.env['mail.channel']
|
|
if self.env.uid:
|
|
partner = self.env.user.partner_id
|
|
mail_channels = partner.channel_ids
|
|
channels.append(partner)
|
|
elif guest_sudo:
|
|
mail_channels = guest_sudo.channel_ids
|
|
channels.append(guest_sudo)
|
|
for mail_channel in mail_channels:
|
|
channels.append(mail_channel)
|
|
return super()._build_bus_channel_list(channels)
|
|
|
|
def _update_bus_presence(self, inactivity_period, im_status_ids_by_model):
|
|
super()._update_bus_presence(inactivity_period, im_status_ids_by_model)
|
|
if not self.env.user or self.env.user._is_public():
|
|
# This method can either be called due to an http or a
|
|
# websocket request. The request itself is necessary to
|
|
# retrieve the current guest. Let's retrieve the proper
|
|
# request.
|
|
req = request or wsrequest
|
|
guest_sudo = self.env['mail.guest']._get_guest_from_request(req).sudo()
|
|
if not guest_sudo:
|
|
return
|
|
guest_sudo.env['bus.presence'].update_presence(inactivity_period, identity_field='guest_id', identity_value=guest_sudo.id)
|