diff --git a/hotel_channel_connector/models/__init__.py b/hotel_channel_connector/models/__init__.py index 612e9674c..f4c5970b6 100644 --- a/hotel_channel_connector/models/__init__.py +++ b/hotel_channel_connector/models/__init__.py @@ -14,3 +14,5 @@ from . import inherited_hotel_folio from . import channel_ota_info from . import hotel_channel_connector_issue from . import inherited_hotel_board_service_room_type +from . import inherited_hotel_room_type_class +from . import inherited_hotel_room \ No newline at end of file diff --git a/hotel_channel_connector/models/hotel_room_type/common.py b/hotel_channel_connector/models/hotel_room_type/common.py index 758a88bf2..883cb41f7 100644 --- a/hotel_channel_connector/models/hotel_room_type/common.py +++ b/hotel_channel_connector/models/hotel_room_type/common.py @@ -133,6 +133,7 @@ class ChannelHotelRoomType(models.Model): deleter = work.component(usage='hotel.room.type.deleter') deleter.delete_room(self) + class HotelRoomType(models.Model): _inherit = 'hotel.room.type' diff --git a/hotel_channel_connector/models/inherited_hotel_room.py b/hotel_channel_connector/models/inherited_hotel_room.py new file mode 100644 index 000000000..c03345004 --- /dev/null +++ b/hotel_channel_connector/models/inherited_hotel_room.py @@ -0,0 +1,35 @@ +# Copyright 2019 Pablo Q. Barriuso +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api + + +class HotelRoom(models.Model): + _inherit = 'hotel.room' + + @api.multi + def write(self, vals): + """ + Update default availability for segmentation management + """ + if vals.get('room_type_id'): + room_type_ids = [] + for record in self: + room_type_ids.append({ + 'new_room_type_id': vals.get('room_type_id'), + 'old_room_type_id': record.room_type_id.id, + }) + + res = super().write(vals) + + for item in room_type_ids: + if item['new_room_type_id'] != item['old_room_type_id']: + self.env['channel.hotel.room.type'].search( + [('odoo_id', '=', item['old_room_type_id'])] + )._onchange_availability() + self.env['channel.hotel.room.type'].search( + [('odoo_id', '=', item['new_room_type_id'])] + )._onchange_availability() + else: + res = super().write(vals) + return res