Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
3645 Zobrazení

Good afternoon, please tell me if there is an opportunity to refresh the page or, even better, update the owl state using websocket from python code, or existing something else method to do next thing:

Why am I asking:

def test_method(self):

# create new message in 'mail.message' model
message_vals = {
'author_id': 2, # OdooBot id 
'body': '

Test message

',
'email_from': '"OdooBot" ',
'message_type': 'notification',
'model': 'crm.lead',
'res_id': 1, # lead id
'subject': 'Test',
}
notif_message = self.env['mail.message'].sudo().create(message_vals)

# create new notification record in 'mail.notification' model and link with created message
test_values = [{
'author_id': 2, # OdooBot id
'mail_message_id': notif_message.id,
'res_partner_id': 8, # partner id
'notification_type': 'inbox',
'notification_status': 'sent',
'is_read': False,
}]

notification = self.env['mail.notification'].sudo().create(test_values)
self.env['bus.bus']._sendone(8, 'inbox', notification)


I'm trying to send a notification to the user and it comes to him, but he will see the notification only after the page is reloaded. The actual question is what I need to do and how to ensure that the user sees the notification in real time. 

Expected behavior - custom notifications are working like default system notifications 

Thank you

Avatar
Zrušit
Autor Nejlepší odpověď

So, what do I have at the moment:

	    def test_method(self):        
​odoobot_id = self.env.ref('base.partner_root').id
​partner_id = self.env['res.partner'].sudo().search([('id','=',8)]) # 8 - partner_id user - Test       
​body = '

Test Test Test 1

'              


        self.env['mail.thread'].sudo().message_notify(
​partner_ids= [partner_id.id],                   
​body='Some text 1',                   
​author_id = 2,
            ​email_from = ​'"OdooBot" ',                   
​subtype_id = None,                   
​model = 'crm.lead',                   
​res_id = 1,
        )

this code this code allows you to send a notification to the user in real time.
I will be glad if someone writes a better and maybe more correct way to send such notifications

P.S. Please tap that this answer is right(if it is=)), need more karma! Thanks
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
úno 24
1203
1
srp 24
3714
0
led 24
1859
1
čvn 23
6095
3
srp 25
2238