如何从另一个功能更新记录

发布于 2025-02-10 04:40:11 字数 911 浏览 3 评论 0原文

我正在尝试从payrun_chatter_log()更新body字段,但不会更新。关于如何这样做的任何想法吗?这就是我所做的:

def payrun_chatter_log(self):
        subtype = self.env['mail.message.subtype'].search([('id','=', '2')])
    
        vals = {
            'date': fields.datetime.now(),
            'email_from': self.env.user.email_formatted,
            'author_id': self.env.user.id,
            'message_type': 'notification',
            'subtype_id': subtype.id,
            'is_internal': True,
            'model': 'custom.module',
            'res_id': self.id,
            'body': 'Test'
        }
        self.env['mail.message'].create(vals)
    
def custom_button(self):
        chatter = self.env['mail.message'].search([('res_id', '=', self.id)])
        message = 'Custom Message here'
        chatter.update({'body': message})
        return super(CustomModule, self).custom_button()

I'm trying to update the body field from the payrun_chatter_log() but it won't update. any idea on how to do this? This is what I did:

def payrun_chatter_log(self):
        subtype = self.env['mail.message.subtype'].search([('id','=', '2')])
    
        vals = {
            'date': fields.datetime.now(),
            'email_from': self.env.user.email_formatted,
            'author_id': self.env.user.id,
            'message_type': 'notification',
            'subtype_id': subtype.id,
            'is_internal': True,
            'model': 'custom.module',
            'res_id': self.id,
            'body': 'Test'
        }
        self.env['mail.message'].create(vals)
    
def custom_button(self):
        chatter = self.env['mail.message'].search([('res_id', '=', self.id)])
        message = 'Custom Message here'
        chatter.update({'body': message})
        return super(CustomModule, self).custom_button()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空宴 2025-02-17 04:40:11

您在Custom_button中的代码下面的代码将返回多记录,因为RES_ID将重复多个模型,

chatter = self.env['mail.message'].search([('res_id', '=', self.id)])

您需要将模型添加到搜索:

chatter = self.env['mail.message'].search([('model', '=', self._name), ('res_id', '=', self.id)])

Your below line of code in custom_button will return multi record because res_id will be repeated for more than one model

chatter = self.env['mail.message'].search([('res_id', '=', self.id)])

You need to add the model to search:

chatter = self.env['mail.message'].search([('model', '=', self._name), ('res_id', '=', self.id)])
天生の放荡 2025-02-17 04:40:11

消息主体应更新,您需要刷新页面以查看更改。

尝试返回以下客户端操作:

return {
    'type': 'ir.actions.client',
    'tag': 'reload',
}

聊天聊天与mail.message模型有一个单一的关系。您的功能将更新所有消息

The message body should be updated, you need to refresh the page to see the changes.

Try to return the following client action:

return {
    'type': 'ir.actions.client',
    'tag': 'reload',
}

The chatter has an One2many relation to mail.message model. Your function will update all messages

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文