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

Hi,

I made a SQL Constraint in a form but unfortunately it didn't work very well, because we when enter something wrong it give us the constraint error( the Form still not saved), but the problem is behind  the system make the incrementation of the sequence.

How can make a validation of Constraint without incrementing the Sequence ?

 
Awatar
Odrzuć
Autor Najlepsza odpowiedź

Hi i found the solution :

It's the actually issue of sequence type.

There are two types (Implementation) of sequence used in odoo : - Standard an d -No Gap

Standard

If you selected this implementation type in sequence (it's default) then sequence will be created in postgresql and managed by postgresql. There is no such control over it. So in case any transactions gets failed then sequence (next number) won't rollbacked.

No Gap

If you select this implementation type then it will be managed by odoo, so in case any issue is there then no sequence number will be skipped.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi ,

As far as i understood your problem is that, the sequence get  generated once the form is opening.

To solve this you can create the sequence to get created only once the from get saved. For that you can super the create function.

@api.model
def create(self, vals):
if vals.get('name', 'New') == 'New':
vals['name'] = self.env['ir.sequence'].next_by_code('model_name') or '/'
res = super(ClassName, self).create(vals)
return res

Thanks

Awatar
Odrzuć