Skip to content
Advertisement

How do I print dynamic sql constraint error statement

I am working on odoo 11 and I want to change the error states of the following SQL constraint and print a dynamic error statement which shows the field “number” inside the error message.

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!' )
  ]

I want the ErrorMessage to be 'Invoice Number'+number+ 'should be the unique per company'.

Advertisement

Answer

No, there is no way to print a dynamic message in _sql_constraint error message.

You must have to know that whatever message you are writing in _sql_constraint it will not be editable letter.

There is one way if you want that message dynamic then you need to check that all possibilities when these type of error occurs and then need to raise warning with dynamic message content. Hope you understand well.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement