我正在使用Odoo11,我想在@api.constraint方法中显示一个警告弹出窗口。我想要显示的警告弹出窗口有两个按钮,第一个是用于忽略警告的OK按钮,另一个是用于尝试保存操作的Cancel按钮,它类似于odoo使用的警告弹出窗口,如下图所示:

我在网上搜索了很多,我找到了不同的解决方案,比如使用向导,exception.Warning()和osv.except_osv(),但不幸的是,这个解决方案没有一个能给我真正想要的。
有什么需要帮忙的吗?
发布于 2019-06-20 23:52:02
您可以使用的基本odoo警告是从odoo.exception类调用的。例如:
from odoo.exceptions import AccessError, UserError, RedirectWarning, ValidationError, Warning
@api.constrains('age')
def _check_something(self):
for record in self:
if record.age > 20:
raise Warning(_("Your record is too old: %s" % record.age))这应该适用于您的问题。
发布于 2018-03-27 19:06:14
您可以通过不同的方式发出警告消息。我已经通过这种方式创建了与库存数量相关的消息:
if self.qty > new_qty:
message = _('You plan to sell %s quantity but you only have %s available in %s warehouse.') % \
(self.qty, self.product_id.virtual_available, self.order_id.warehouse_id.name)
mess= {
'title': _('Not enough inventory!'),
'message' : message
}
return {'warning': mess}这将返回与您想要的和给定图像所示相同的警告向导。
发布于 2020-04-12 00:07:31
我写了一个(草稿)模块来打开对话框请参阅:https://github.com/Micronaet/micronaet-sales/tree/master/confirm_dialog_wizard
在你的按钮中,你可以写这段代码来打开,例如。要隐藏产品,请执行以下操作:
@api.multi
def hide_product_pricelist(self):
""" Hide product
"""
return self.env['dialog.box.wizard'].open_dialog(
message='The product will be hided, <b>you cannot use again</b> '
'but remain in sale order where yet present, <br/>'
'confirm?',
action='self.env["product.product"].browse(%s).write('
'{"active": False})' % self.id,
title='Confirm request:',
mode='cancel_confirm',
)程序将弹出一个窗口进行确认(因为在树中你不能使用“确认”消息参数),我正在尝试做得更好,但是…这是一个开始... :)
https://stackoverflow.com/questions/49508693
复制相似问题