콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5104 화면
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'


아바타
취소
베스트 답변

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)  

아바타
취소
작성자

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