我在点击按钮后点击按钮发送邀请,成功发送邀请后会弹出邀请发送成功的消息。但问题是弹出消息的主要标题是 Odoo 服务器错误。那是因为我正在使用
raise osv.except_osv("Success", "Invitation is successfully sent")
有什么办法可以让它更好。
最佳答案
当我需要这样的东西时,我有一个虚拟 wizard
与 message
字段,并有一个简单的表单 View 来显示该字段的值。
当我想在单击按钮后显示消息时,我会这样做:
@api.multi
def action_of_button(self):
# do what ever login like in your case send an invitation
...
...
# don't forget to add translation support to your message _()
message_id = self.env['message.wizard'].create({'message': _("Invitation is successfully sent")})
return {
'name': _('Successfull'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'message.wizard',
# pass the id
'res_id': message_id.id,
'target': 'new'
}
form view
消息向导就像这样简单:<record id="message_wizard_form" model="ir.ui.view">
<field name="name">message.wizard.form</field>
<field name="model">message.wizard</field>
<field name="arch" type="xml">
<form >
<p class="text-center">
<field name="message"/>
</p>
<footer>
<button name="action_ok" string="Ok" type="object" default_focus="1" class="oe_highlight"/>
</footer>
<form>
</field>
</record>
Wizard
很简单是这样的:class MessageWizard(model.TransientModel):
_name = 'message.wizard'
message = fields.Text('Message', required=True)
@api.multi
def action_ok(self):
""" close wizard"""
return {'type': 'ir.actions.act_window_close'}
注:从不使用
exceptions
显示信息留言因为一切都在一个大 transaction
内运行当你点击按钮时,如果有没有
exception
凸起 一个 Odoo 会做 rollback
在 database
,否则您将丢失数据 commit
在此之前先手动完成您的工作,女巫不是 推荐 在 Odoo 中也是如此
关于python - 如何在odoo中弹出成功消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58302569/