Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3706 Vistas

I've already searching how to modify save button and get some solution like this :

def create(self, cr, uid, vals, context=None):
        # Your logic goes here or call your method
        res_id = super(reservation, self).create(cr, uid, vals, context=context)
        # Your logic goes here or call your method
        return res_id

    def write(self, cr, uid, vals, context=None):
        # Your logic goes here or call your method
        super(reservation, self).write(cr, uid, id, vals, context=context)
        # Your logic goes here or call your method
        return True

I have Hotel module and class reservation. I want user will see this message warning

if self.duration < 0:
            return {
                'warning': {
                    'title': "Something bad happened",
                    'message': "It's very bad indeed",
                    }
                }

if they break some condition like let the guest name and room number being not filled or let check out date less than check in date. Where should I locate this warning code in that function?

Avatar
Descartar
Mejor respuesta

Hi,

For this case, there is no need to override the create method or the write method. You can use the api.constrains and raise the validation error message if the user forgets to enter some value or if some value is less than the specified limit.

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


@api.constrains('duration')
def check_duration(self):
if self.duration < 0:
raise ValidationError(_("Duration Must Be Non-Zero Positive Number !"))

Thanks

Avatar
Descartar
Autor

Hi, should I import something? because ValidationError returns error: undefined variable

Autor

Sorry to say but that don't gives any effect. Is there another solution?

This is the standard solution, rather than looking for other solutions, check why this is not working. Just search the constrains in the odoo code you will get a lot of samples

Publicaciones relacionadas Respuestas Vistas Actividad
0
dic 19
4276
2
ene 16
35237
1
ago 20
4383
1
abr 20
4921
1
sept 19
8557