如何从另一个功能更新记录
我正在尝试从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在Custom_button中的代码下面的代码将返回多记录,因为RES_ID将重复多个模型,
您需要将模型添加到搜索:
Your below line of code in custom_button will return multi record because res_id will be repeated for more than one model
You need to add the model to search:
消息主体应更新,您需要刷新页面以查看更改。
尝试返回以下客户端操作:
聊天聊天与
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:
The chatter has an One2many relation to
mail.message
model. Your function will update all messages