显示错误消息

时间:2015-08-21 09:30:56

标签: openerp odoo openerp-8

如何显示错误消息“房间已经预订”。我想通过** room_id检查,**开始**,怎么可能?

  

py文件

 _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),
}

1 个答案:

答案 0 :(得分:1)

您可以使用constrains方法装饰器:

@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")