diff --git a/hotel/models/hotel_room.py b/hotel/models/hotel_room.py index 01dad3d52..e4e2c2230 100644 --- a/hotel/models/hotel_room.py +++ b/hotel/models/hotel_room.py @@ -15,59 +15,33 @@ class HotelRoom(models.Model): _order = "sequence, room_type_id, name" name = fields.Char('Room Name', required=True) - active = fields.Boolean('Active', default=True) - sequence = fields.Integer('Sequence', default=0) + # Relationship between models + hotel_id = fields.Many2one('hotel.property', store=True, readonly=True, + related='room_type_id.hotel_id') room_type_id = fields.Many2one('hotel.room.type', 'Hotel Room Type', required=True, ondelete='restrict') + shared_room_id = fields.Many2one('hotel.shared.room', 'Shared Room', + default=False) floor_id = fields.Many2one('hotel.floor', 'Ubication', help='At which floor the room is located.') - hotel_id = fields.Many2one('hotel.property', store=True, readonly=True, - related='room_type_id.hotel_id') max_adult = fields.Integer('Max Adult') max_child = fields.Integer('Max Child') capacity = fields.Integer('Capacity') to_be_cleaned = fields.Boolean('To be Cleaned', default=False) - shared_room_id = fields.Many2one('hotel.shared.room', 'Shared Room', - default=False) + extra_beds_allowed = fields.Integer('Extra beds allowed', + default='0', + required=True) description_sale = fields.Text( 'Sale Description', translate=True, 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") - extra_beds_allowed = fields.Integer('Extra beds allowed', - default='0', - required=True) - - # @api.constrains('room_type_id') - # def _constrain_shared_room_type(self): - # for record in self: - # if record.shared_room_id: - # if not record.room_type_id.shared_room: - # raise ValidationError(_('We cant save normal rooms \ - # in a shared room type')) - # else: - # if record.room_type_id.shared_room: - # raise ValidationError(_('We cant save shared rooms \ - # in a normal room type')) - - # @api.constrains('shared_room_id') - # def _constrain_shared_room(self): - # for record in self: - # if record.shared_room_id: - # if not record.capacity > 1: - # raise ValidationError(_('We cant save normal rooms \ - # in a shared room type')) - - # @api.constrains('capacity') - # def _check_capacity(self): - # for record in self: - # if record.shared_room_id and record.capacity != 1: - # raise ValidationError(_("A Bed only can has capacity one")) - # if record.capacity < 1: - # raise ValidationError(_("Room capacity can't be less than one")) + active = fields.Boolean('Active', default=True) + sequence = fields.Integer('Sequence', default=0) + # Business methods @api.multi def get_capacity(self, extra_bed=0): if not self.shared_room_id: diff --git a/hotel/models/hotel_room_type.py b/hotel/models/hotel_room_type.py index fe1c3caa8..f03549726 100644 --- a/hotel/models/hotel_room_type.py +++ b/hotel/models/hotel_room_type.py @@ -13,6 +13,7 @@ class HotelRoomType(models.Model): _name = "hotel.room.type" _description = "Room Type" _inherits = {'product.product': 'product_id'} + _order = "sequence, code_type, name" @api.model def _get_default_hotel(self): @@ -22,6 +23,8 @@ class HotelRoomType(models.Model): product_id = fields.Many2one('product.product', 'Product Room Type', required=True, delegate=True, ondelete='cascade') + hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict', + default=_get_default_hotel,) room_ids = fields.One2many('hotel.room', 'room_type_id', 'Rooms') class_id = fields.Many2one('hotel.room.type.class', 'Hotel Type Class') board_service_room_type_ids = fields.One2many( @@ -31,44 +34,43 @@ class HotelRoomType(models.Model): 'room_type_ids', 'amenity_ids', string='Room Type Amenities', help='List of Amenities.') - hotel_id = fields.Many2one('hotel.property', 'Hotel', required=True, ondelete='restrict', - default=_get_default_hotel,) - - # TODO Hierarchical relationship for parent-child tree ? - # parent_id = fields.Many2one ... - - # Used for activate records - active = fields.Boolean('Active', default=True, - help="The active field allows you to hide the \ - category without removing it.") - shared_room = fields.Boolean('Shared Room', default=False, - help="This room type is reservation by beds") - # Used for ordering - sequence = fields.Integer('Sequence', default=0) code_type = fields.Char('Code', required=True, ) - - _order = "sequence, code_type, name" - - # total number of rooms in this type + shared_room = fields.Boolean('Shared Room', default=False, + help="This room type is reservation by beds") total_rooms_count = fields.Integer(compute='_compute_total_rooms', store=True) + active = fields.Boolean('Active', default=True) + sequence = fields.Integer('Sequence', default=0) _sql_constraints = [ - ('code_hotel_unique', 'unique(code_type, hotel_id)', 'Room Type Code must be unique by Hotel!'), + ('code_type_hotel_unique', 'unique(code_type, hotel_id)', 'Room Type Code must be unique by Hotel!'), ] + # Constraints and onchanges @api.depends('room_ids', 'room_ids.active') def _compute_total_rooms(self): for record in self: record.total_rooms_count = len(record.room_ids) + # CRUD methods + @api.model + def create(self, vals): + """ Add room types as not purchase services. """ + vals.update({ + 'purchase_ok': False, + 'type': 'service', + }) + return super().create(vals) + + @api.multi + def unlink(self): + for record in self: + record.product_id.unlink() + return super().unlink() + + # Business methods @api.multi def get_capacity(self): - """ - Get the minimum capacity in the rooms of this type or zero if has no rooms - @param self: The object pointer - @return: An integer with the capacity of this room type - """ self.ensure_one() capacities = self.room_ids.mapped('capacity') return min(capacities) if any(capacities) else 0 @@ -77,13 +79,7 @@ class HotelRoomType(models.Model): def check_availability_room_type(self, dfrom, dto, room_type_id=False, notthis=[]): """ - Check the avalability for an specific type of room - @param self: The object pointer - @param dfrom: Range date from - @param dto: Range date to - @param room_type_id: Room Type - @param notthis: Array excluding Rooms - @return: A recordset of free rooms ? + Check the max availability for an specific type of room in a range of dates """ reservations = self.env['hotel.reservation'].get_reservations(dfrom, dto) @@ -99,38 +95,6 @@ class HotelRoomType(models.Model): free_rooms = free_rooms & rooms_linked return free_rooms.sorted(key=lambda r: r.sequence) - @api.model - def create(self, vals): - """ - Overrides orm create method. - @param self: The object pointer - @param vals: dictionary of fields value. - @return: new record set for hotel room type. - """ - vals.update({ - 'purchase_ok': False, - 'type': 'service', - }) - return super().create(vals) - - # @api.constrains('shared_room', 'room_ids') - # def _constrain_shared_room(self): - # for record in self: - # if record.shared_room: - # if any(not room.shared_room_id for room in record.room_ids): - # raise ValidationError(_('We cant save normal rooms \ - # in a shared room type')) - # else: - # if any(room.shared_room_id for room in record.room_ids): - # raise ValidationError(_('We cant save shared rooms \ - # in a normal room type')) - - @api.multi - def unlink(self): - for record in self: - record.product_id.unlink() - return super().unlink() - @api.model def get_rate_room_types(self, **kwargs): """ @@ -138,7 +102,7 @@ class HotelRoomType(models.Model): not use this param, the method return all room_types from: Date from, mandatory days: Number of days, mandatory - pricelist_id: Pricselist to use, optional + pricelist_id: Pricelist to use, optional partner_id: Partner, optional Return Dict Code Room Types: subdict with day, discount, price """ diff --git a/hotel/models/hotel_room_type_class.py b/hotel/models/hotel_room_type_class.py index 09b1550bf..28296160a 100644 --- a/hotel/models/hotel_room_type_class.py +++ b/hotel/models/hotel_room_type_class.py @@ -3,9 +3,10 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields + class HotelRoomTypeClass(models.Model): """ Before creating a 'room type_class', you need to consider the following: - With the term 'room type class' is meant a physicial class of + With the term 'room type class' is meant a physical class of residential accommodation: for example, a Room, a Bed, an Apartment, a Tent, a Caravan... """ @@ -14,14 +15,13 @@ class HotelRoomTypeClass(models.Model): _order = "sequence, name, code_class" name = fields.Char('Class Name', required=True, translate=True) - room_type_ids = fields.One2many('hotel.room.type', 'class_id', 'Types') - active = fields.Boolean('Active', default=True, - help="The active field allows you to hide the \ - category without removing it.") - sequence = fields.Integer('Sequence', default=0) - code_class = fields.Char('Code') + # Relationship between models hotel_ids = fields.Many2many('hotel.property', string='Hotels', required=False, ondelete='restrict') + room_type_ids = fields.One2many('hotel.room.type', 'class_id', 'Types') + code_class = fields.Char('Code') + active = fields.Boolean('Active', default=True) + sequence = fields.Integer('Sequence', default=0) _sql_constraints = [('code_class_unique', 'unique(code_class)', - 'code must be unique!')] + 'Room Class Code must be unique!')]