Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
2363 Vistas

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 ?

 
Avatar
Descartar
Autor Mejor respuesta

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.

Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar