我如何打印动态sql约束错误语句

问题描述 投票:1回答:1

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

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'

python sql python-3.x odoo odoo-11
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.