Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
3765 Visninger

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.

Avatar
Kassér
Bedste svar

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

Avatar
Kassér
Forfatter Bedste svar

Thank you Karthikeyan N R, it worked!

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


Avatar
Kassér

Happy to help, thanks again!

Related Posts Besvarelser Visninger Aktivitet
2
mar. 15
10690
1
jul. 23
3024
3
nov. 22
5887
0
aug. 20
4469
0
nov. 19
4606