Skip to Content
Menu
This question has been flagged
1 Reply
3478 Views
I want to notify whenever one 'comment' is added in backend to any sale order. To do some actions in the website (I have created one view to show sale orders information).

This is mi code:
@api.model
def create(self, values):
    if values.get('model') == 'sale.order' and values.get('message_type') == 'comment':
        channel = (self._cr.dbname, 'sale.order', 3)
        messages = {'type': 'user_notification', 'title': 'Notifiy User'}
self.env['bus.bus'].sendone(channel, messages)
    return super(MailMessage, self).create(values)                    

And I added the channel before like this:

class UserPortalBusController(BusController):
def _poll(self, dbname, channels, last, options):
    """Add the relevant channels to the BusController polling."""
    if request.session.uid:
        channels = list(channels)
        channels.append((request.db, 'sale.order', 3))  
    return super(UserPortalBusController, self)._poll(dbname, channels, last, options)            

When I add one message to sale order I am having this error:

File "/usr/lib/python3/dist-packages/odoo/api.py", line 394, in _model_create_single return self.browse().concat(*(create(self, vals) for vals in arg)) File "/usr/lib/python3/dist-packages/odoo/api.py", line 394, in return self.browse().concat(*(create(self, vals) for vals in arg)) File "/mnt/addons_bp/user_portal/models/mail_message.py", line 18, in create self.env['bus.bus'].sendone(channel, messages) Exception The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 644, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 302, in _handle_exception raise exception.with_traceback(None) from new_cause AttributeError: 'bus.bus' object has no attribute 'sendone'


Avatar
Discard
Best Answer

If you are using Odoo 15, then you have to use _sendone not sendone and you have to pass three parameters (channel, notification_type and message)

odoo/bus.py at 15.0 · odoo/odoo (github.com)  

Avatar
Discard
Author

Thanks, you are right. I was using odoo15 but I had not update since a lot. Now all sendone changed to _sendone.