PKS ks
PKS ks

Reputation: 116

Show the error message

how to show the error message "The room was already booked" . i want to check by ** room_id,** start** , how it is possible?

py file

 _columns = {
    'room_id' : fields.many2one('room.management', string="Room Booking"),
    'duration': fields.integer('Duration'),
    'reason': fields.char('Reason',requierd=True ,help="short deatails about booking"),
    'start': fields.datetime('Start At',requierd=True),
    'end': fields.datetime('End At',requierd=True),
}

Upvotes: 0

Views: 99

Answers (1)

Ludwik Trammer
Ludwik Trammer

Reputation: 25032

You can use a constrains method decorator:

@api.one
@api.constrains('start', 'end', 'room_id')
def _check_room_overlap(self):
    overlaping_bookings = self.search_count([
        ('room_id', '=', self.room_id.id),
        ('start', '<', self.end),
        ('end', '>', self.start),
    ])
    if overlaping_bookings:
        raise exceptions.ValidationError("The room was already booked")

Upvotes: 1

Related Questions