Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3682 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thank you Karthikeyan N R, it worked!

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


Awatar
Odrzuć

Happy to help, thanks again!

Powiązane posty Odpowiedzi Widoki Czynność
2
mar 15
10627
1
lip 23
2841
3
lis 22
5791
0
sie 20
4392
0
lis 19
4522