Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
3699 Ansichten

I am trying to send notification to user A then user B Approves a task. (but using the odoobot user)

notification_ids = [(0,0,{'res_partner_id':user_id.partner_id.id,'notification_type':'inbox'})]
self.sudo().message_post(subject=summary,body=summary_link,message_type='notification, subtype_xmlid='mail.mt_comment', author_id=odoo_bot_id.partner_id.id, notification_ids=notification_ids)

it was working but now i am going this:

ValueError: Posting a message should be done on a business document. Use message_notify to send a notification to an user.

if self._name == 'mail.thread' or not self.id or message_type == 'user_notification':
            raise ValueError(_('Posting a message should be done on a business document. Use message_notify to send a notification to an user.'))

what does not self.id mean

according to this I should use

message_notify_ids = [user_id.partner_id.id]
record.sudo().message_notify(partner_ids=message_notify_ids, parent_id=odoo_bot_id.partner_id.id, author_id=odoo_bot_id.partner_id.id,  body=summary_link, subject=summary)

this shows the popup notification but does not show in the index so the user can navigate to the task


stackoverflow

Avatar
Verwerfen
Autor Beste Antwort

When I logged self.id I got NewId_26404 which is a temp id since the function was run in a compute.

Fix

record = record if isinstance(record.id,int) else record._origin

Note: discarding the changes did send the notification in my case, so it maybe better to add it in write function

I am open to suggestions if there is a better solution thank.

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Dez. 23
2573
2
Aug. 23
2268
2
Aug. 23
6616
1
Dez. 23
3980
1
Juli 23
2859