跳至內容
選單
此問題已被標幟
2 回覆
3805 瀏覽次數

Hello, i am currently using Odoo 12. we have the sql constraints below:


_sql_constraints = [
  ('check_pr_ref',

                        "unique(project_reference)",
                        'The project reference already exists'),
]

i'd like to add an exception to allow if the project_reference = "PR0000"


thanks in advance,
Anthony.

頭像
捨棄
最佳答案

Hi,

 In your model add this function,

from odoo.exceptions import  ValidationError

@api.constrains('project_reference')

    def _check_duplicate(self):

        for each in self:

            if each.project_reference and each.project_reference != 'PR0000':

                domain = [('project_reference', '=', each.project_reference)]

                all_forms = self.search_count(domain)

                if all_forms:

                    raise ValidationError(_('The project reference already exists!'))

Hope it helps,

Thanks

頭像
捨棄
作者 最佳答案

Thank you Karthikeyan N R, it worked!

(sorry i don't have enough Karma to mark your comment as best answer)


頭像
捨棄

Happy to help, thanks again!

相關帖文 回覆 瀏覽次數 活動
2
3月 15
10734
1
7月 23
3058
3
11月 22
5925
0
8月 20
4505
0
11月 19
4640