Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
3304 Vizualizări

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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
feb. 24
985
1
aug. 24
3371
0
ian. 24
1368
1
iun. 23
5630
1
mai 25
1818