如何打印动态sql约束错误状态

2024-04-25 17:31:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在处理odoo11,希望更改以下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!' )
  ]

我希望错误消息是'Invoice Number'+number+ 'should be the unique per company'。你知道吗


Tags: id消息numbersqlmodels错误odoo11invoice
1条回答
网友
1楼 · 发布于 2024-04-25 17:31:12

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

您必须知道,无论您在_sql_constraint中编写什么消息,它都不会是可编辑的。你知道吗

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

相关问题 更多 >