【问题标题】:How do I print dynamic sql constraint error statement如何打印动态sql约束错误语句
【发布时间】:2019-12-16 12:04:48
【问题描述】:

我正在使用 odoo 11,我想更改以下 SQL 约束的错误状态并打印一条动态错误语句,该语句在错误消息中显示字段“数字”。

from odoo import api, fields, models

 class ValidateMessageUnique(models.Model):

  _inherit = 'account.invoice'

  _sql_constraints = [
    ('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number should be unique per Company!' )
  ]

我希望 ErrorMessage 为 'Invoice Number'+number+ 'should be the unique per company'

【问题讨论】:

  • 如何在错误信息中打印变量值??
  • 创建记录时可以使用api报错。

标签: python sql python-3.x odoo odoo-11


【解决方案1】:

不,无法在_sql_constraint 错误消息中打印动态消息。

您必须知道,您在_sql_constraint 中写的任何消息都不是可编辑的。

如果您希望消息是动态的,有一种方法,那么您需要检查发生此类错误时的所有可能性,然后需要使用动态消息内容发出警告。希望你能理解。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多