【问题标题】:how to send notification for specific group when new employee created in odoo v10?在odoo v10中创建新员工时如何发送特定组的通知?
【发布时间】:2019-12-07 04:05:39
【问题描述】:

我从未从事过 odoo 电子邮件模板或通知的工作, 我需要知道如何在创建新员工时通知特定用户组 如果有任何示例,我将不胜感激我正在尝试在 odoo10 上这样做

【问题讨论】:

    标签: python xml python-2.7 odoo odoo-10


    【解决方案1】:

    您应该创建一个模块并继承模型“hr.employee”。

    然后像这样覆盖模块上的“create”函数:

    选项1 这样一一通知每个用户

    @api.model
    def create(self, values):
       all_users = self.env['res.users'].search([('active', '=', True)])
       my_users_group = all_users.filtered(lambda user: user.has_group('my.group.name'))
       for i in range(0, len(my_users_group)):
           item = my_users_group[i]
           item.message_post("New employee created")
       record = super(MyHrModuleName, self).create(values)
       return record
    

    另一种方法:

    选项 2 这样可以同时通知您组中的所有用户。

    转到“讨论”应用程序并创建一个私人频道并自动订阅您的用户。

    @api.model
    def create(self, values):
        my_private_channel = self.env['mail.channel'].search([('name', 'ilike', "My-Private-Channel")])
        my_private_channel.message_post("New employee has been created")
        record = super(MyHrModuleName, self).creates(values)
        return record
    

    您选择的任何两个选项都可以... 有任何担心,请告诉我。

    我建议您阅读整个 Odoo 文档,该文档对如何创建和继承新模块非常用户友好。

    https://www.odoo.com/documentation/10.0/reference/module.html

    【讨论】:

    • 创建 TypeError 时出现此错误:create() got an unexpected keyword argument 'context'
    • 我是这样写的,效果很好,@norbertoonline @api.model def create(self, values): all_users = self.env['res.users'].search([('active', '=', True)]) my_users_group = all_users.filtered(lambda user: user.has_group('base.group_user')) for i in range(0, len(my_users_group)): item = my_users_group[i] item.message_post(body='New employee created', message_type='notification') print ('i'am IN') return super(hr_employee, self).create(values)
    • 但实际上我不知道这个通知出现在哪里,我创建员工没有任何错误,当我去设置消息时我找到了通知,但需要知道其他用户将如何接收这个通知??
    • @MohamedFouad 我已经修改了函数,因为我忘记了返回......并以这个例子说明在哪里做“创造”......记住阅读文档。其他员工将以相同的方式接收消息,因为该功能将向您的每个员工发送消息,您可以尝试创建私人频道并自动订阅您的群组并修改功能以将消息发送到频道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    相关资源
    最近更新 更多