Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
1336 Представления

Is it possible to create a function that sends a specific notification through the Odoo mobile app?

Аватар
Отменить
Лучший ответ

I use this function :


    def action_alert(self):

        user_ids = [21,6]  

        subject = f'Message from {self.env.user.name}:'

        body = f'Title of notification '


        for user_id in user_ids:

            user = self.env['res.users'].browse(user_id)

            if user.partner_id:

                channel = self.env['mail.channel'].search([

                    ('channel_partner_ids', 'in', [self.env.user.partner_id.id]),

                    ('channel_partner_ids', 'in', [user.partner_id.id]),

                    ('channel_type', '=', 'chat')

                ], limit=1)


                if not channel:

                    channel = self.env['mail.channel'].create({

                        'channel_partner_ids': [(4, self.env.user.partner_id.id), (4, user.partner_id.id)],

                        'channel_type': 'chat',

                        'name': 'Direct Message'

                    })

                channel.message_post(

                    subject=subject,

                    body=body,

                    message_type='comment',

                    subtype_id=self.env.ref('mail.mt_comment').id,

                    partner_ids=[user.partner_id.id]

                )

                self.message_post(

                    body=f'Body of message',

                    message_type='notification',

                    subtype_id=self.env.ref('mail.mt_note').id

                )


Best regards

Аватар
Отменить
Автор

Thank you, that works!

Related Posts Ответы Просмотры Активность
5
июл. 25
2594
6
нояб. 24
7567
0
мая 25
2268
1
июл. 23
6606
0
сент. 20
3097