【问题标题】:Odoo no UserError message without any errorOdoo 没有 UserError 消息没有任何错误
【发布时间】:2017-06-20 08:41:07
【问题描述】:

我的代码:

from openerp.tools.translate import _
from openerp.exceptions import UserError

和功能:

@api.multi
def button_in_progress(self):
    for rec in self:
        rec.state = 'in_progress'
    test = self.test_ids.ids
    test1 = len(test)
    if test1 == 0:
        raise UserError(_('Test test'))
    return True

我登录了。当我得到 test1 为 0 时,我的错误消息不会出现。我也没有收到任何错误。有什么问题?

【问题讨论】:

  • 编辑您的问题并更正缩进?
  • 记录self.test_ids.ids的值以确定。
  • 现在一切正常,谢谢!问题是因为我的缩进。
  • 不客气。

标签: python-2.7 openerp odoo-9 raiserror


【解决方案1】:

无需查找 len 然后检查,试试这个

@api.multi
def button_in_progress(self):
    for rec in self:
        rec.state = 'in_progress'
    if not self.test_ids.ids:
        raise UserError(_('Test test'))
    return True

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-14
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多