Files
odoo_source/addons/bus/controllers/main.py
T
Adrien Widart 7f7ce72619 [FIX] bus: get im_status of deleted ID
When trying to get the im_status of several partners, if one of them
does not exist, it will return an error.

To reproduce the error:
1. Go to Contacts
2. Open a contact
3. Action > Delete
4. Wait max 50 seconds

=> A Missing Record message is displayed. The im_status RPC includes the
deleted partner's identifier and the server looks for it.

Now, the server skips the missing identifiers.

OPW-2390719

closes odoo/odoo#63198

X-original-commit: a35c65032fc5ed1371957c362921bf5fa30062ff
Signed-off-by: adwid <adwid@users.noreply.github.com>
2020-12-10 16:56:29 +00:00

45 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
from odoo import exceptions, _
from odoo.http import Controller, request, route
from odoo.addons.bus.models.bus import dispatch
class BusController(Controller):
""" Examples:
openerp.jsonRpc('/longpolling/poll','call',{"channels":["c1"],last:0}).then(function(r){console.log(r)});
openerp.jsonRpc('/longpolling/send','call',{"channel":"c1","message":"m1"});
openerp.jsonRpc('/longpolling/send','call',{"channel":"c2","message":"m2"});
"""
@route('/longpolling/send', type="json", auth="public")
def send(self, channel, message):
if not isinstance(channel, str):
raise Exception("bus.Bus only string channels are allowed.")
return request.env['bus.bus'].sendone(channel, message)
# override to add channels
def _poll(self, dbname, channels, last, options):
# update the user presence
if request.session.uid and 'bus_inactivity' in options:
request.env['bus.presence'].update(options.get('bus_inactivity'))
request.cr.close()
request._cr = None
return dispatch.poll(dbname, channels, last, options)
@route('/longpolling/poll', type="json", auth="public", cors="*")
def poll(self, channels, last, options=None):
if options is None:
options = {}
if not dispatch:
raise Exception("bus.Bus unavailable")
if [c for c in channels if not isinstance(c, str)]:
raise Exception("bus.Bus only string channels are allowed.")
if request.registry.in_test_mode():
raise exceptions.UserError(_("bus.Bus not available in test mode"))
return self._poll(request.db, channels, last, options)
@route('/longpolling/im_status', type="json", auth="user")
def im_status(self, partner_ids):
return request.env['res.partner'].with_context(active_test=False).search([('id', 'in', partner_ids)]).read(['im_status'])