Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3586 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
feb. 24
1140
1
aug. 24
3652
0
jan. 24
1778
1
jun. 23
6048
5
jul. 25
2354