From 5b12446bc520544107a475d2383a29708bc20272 Mon Sep 17 00:00:00 2001 From: Pablo Quesada Barriuso Date: Fri, 27 Jul 2018 17:42:18 +0200 Subject: [PATCH] [FIX] Room capacity can't be less than one --- hotel/models/hotel_reservation.py | 7 ++----- hotel/models/hotel_room.py | 7 ++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index 384c5717f..ca4d3f0f3 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -1165,11 +1165,8 @@ class HotelReservation(models.Model): return {'total_price': total_price, 'commands': cmds} @api.constrains('adults') - def check_adults(self): - if self.adults == 0 and self.room_id: - # room = self.env['hotel.room'].search([ - # ('product_id', '=', self.product_id.id) - # ], limit=1) + def _check_adults(self): + if self.adults == 0 and self.room_id and self.room_id > 0: self.adults = self.room_id.capacity @api.multi diff --git a/hotel/models/hotel_room.py b/hotel/models/hotel_room.py index f1aaa0faa..27d452841 100644 --- a/hotel/models/hotel_room.py +++ b/hotel/models/hotel_room.py @@ -3,7 +3,7 @@ # Copyright 2017 Dario Lodeiros # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api, _ - +from odoo.exceptions import ValidationError class HotelRoom(models.Model): """ The rooms for lodging can be for sleeping, usually called rooms, and also @@ -45,3 +45,8 @@ class HotelRoom(models.Model): help="A description of the Product that you want to communicate to " " your customers. This description will be copied to every Sales " " Order, Delivery Order and Customer Invoice/Credit Note") + + @api.constrains('capacity') + def _check_capacity(self): + if self.capacity < 1: + raise ValidationError(_("Room capacity can't be less than one"))