From 902a284fbf64644525965b49c32b4344d0552e65 Mon Sep 17 00:00:00 2001 From: Pablo Date: Fri, 26 Jul 2019 13:08:47 +0200 Subject: [PATCH] [UPD] Task 973 - constrain for archive --- hotel_channel_connector/models/hotel_room_type/common.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hotel_channel_connector/models/hotel_room_type/common.py b/hotel_channel_connector/models/hotel_room_type/common.py index 43e50ab10..2b70f9676 100644 --- a/hotel_channel_connector/models/hotel_room_type/common.py +++ b/hotel_channel_connector/models/hotel_room_type/common.py @@ -137,6 +137,14 @@ class HotelRoomType(models.Model): for record in self: record.capacity = record.get_capacity() + @api.constrains('active') + def _check_active(self): + for record in self: + if not record.active and record.total_rooms_count > 0: + raise ValidationError( + _("You can not archive a room type with active rooms.") + " " + + _("Please, change the %s room(s) to other room type.") % str(record.total_rooms_count)) + @api.multi def get_restrictions(self, date, restriction_plan_id): self.ensure_one()