Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3857 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Auteur

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

Gerelateerde posts Antwoorden Weergaven Activiteit
0
dec. 19
4477
2
jan. 16
35553
1
aug. 20
4641
1
apr. 20
5160
1
sep. 19
8795