Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
4232 Visualizzazioni

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
Abbandona
Autore Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
set 25
1748
1
ago 24
4381
0
gen 24
2596
1
giu 23
6749
5
set 25
22712