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

Hi,

I try to create a simple automated action which verifies the existing name and email upon contact creation.

The code 1 :

---

name_count = env['res.partner'].search_count([('name', '=ilike', record.name)])

if name_count :
  raise Warning('Ce Nom+Prénom \''+str(record.name)+'\' existe déjà : '+str(name_count))
else :
  name_count = 0
  raise Warning('Name found : '+str(name_count))

---

Raises correctly 'Name found: 0' when I create a contact with unique name.

But a small change commenting the last line of the code makes the first Warning to raise with name_count equal to 1.

What could be the issue with the code that makes it working in such a weird way ?

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Finally, I've found a way to make it working, by assuming that the name_count is always >=1.

So, the code which works is the following (with some message improvement in French):

name_count = env['res.partner'].search_count([('name', '=ilike', record.name)])
if name_count > 1 :
raise Warning('Ce Nom+Prénom \''+str(record.name)+'\' existe déjà ('+str(name_count-1)+' fois)')


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 23
2011
2
gru 23
5555
1
lis 22
2473
1
sie 22
2557
2
sty 22
5653