İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
3755 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici

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

Üretici

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

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Ara 19
4349
2
Oca 16
35352
1
Ağu 20
4486
1
Nis 20
5026
1
Eyl 19
8644