diff --git a/hotel/models/hotel_room_type.py b/hotel/models/hotel_room_type.py index 26e789eb9..17577d3da 100644 --- a/hotel/models/hotel_room_type.py +++ b/hotel/models/hotel_room_type.py @@ -44,15 +44,6 @@ class HotelRoomType(models.Model): # total number of rooms in this type total_rooms_count = fields.Integer(compute='_compute_total_rooms') - @api.multi - @api.constrains('room_ids') - def _check_capacity(self): - for record in self: - for room in record.room_ids: - if room.room_type_id and room.room_type_id != record.id: - raise ValidationError(_("You need change de room type from de room form")) - - @api.depends('room_ids') def _compute_total_rooms(self): for record in self: diff --git a/hotel/tests/__init__.py b/hotel/tests/__init__.py index 6289c6fab..09be3071d 100644 --- a/hotel/tests/__init__.py +++ b/hotel/tests/__init__.py @@ -23,3 +23,4 @@ #from . import test_reservation #from . import test_folio from . import test_hotel_room_type_model +from . import test_hotel_room_model diff --git a/hotel/tests/common.py b/hotel/tests/common.py index efd4bb8f9..b0b6cb3dd 100644 --- a/hotel/tests/common.py +++ b/hotel/tests/common.py @@ -21,7 +21,7 @@ # ############################################################################## from datetime import timedelta -from odoo import api, fields +from odoo import api, fields from odoo.tests import common from odoo.tools import ( DEFAULT_SERVER_DATE_FORMAT, @@ -81,15 +81,15 @@ class TestHotel(common.SavepointCase): cls._init_mock_hotel() # Create Tests Records - cls.room_type_0 = cls.env.ref('hotel_room_type_0') - cls.room_type_1 = cls.env.ref('hotel_room_type_1') - cls.room_type_2 = cls.env.ref('hotel_room_type_2') - cls.room_type_3 = cls.env.ref('hotel_room_type_3') + cls.room_type_0 = cls.env.ref('hotel.hotel_room_type_0') + cls.room_type_1 = cls.env.ref('hotel.hotel_room_type_1') + cls.room_type_2 = cls.env.ref('hotel.hotel_room_type_2') + cls.room_type_3 = cls.env.ref('hotel.hotel_room_type_3') - cls.room_0 = cls.env.ref('hotel_room_0') - cls.room_1 = cls.env.ref('hotel_room_1') - cls.room_2 = cls.env.ref('hotel_room_2') - cls.room_3 = cls.env.ref('hotel_room_3') - cls.room_4 = cls.env.ref('hotel_room_4') - cls.room_5 = cls.env.ref('hotel_room_5') - cls.room_6 = cls.env.ref('hotel_room_6') + cls.room_0 = cls.env.ref('hotel.hotel_room_0') + cls.room_1 = cls.env.ref('hotel.hotel_room_1') + cls.room_2 = cls.env.ref('hotel.hotel_room_2') + cls.room_3 = cls.env.ref('hotel.hotel_room_3') + cls.room_4 = cls.env.ref('hotel.hotel_room_4') + cls.room_5 = cls.env.ref('hotel.hotel_room_5') + cls.room_6 = cls.env.ref('hotel.hotel_room_6') diff --git a/hotel/tests/test_hotel_room_model.py b/hotel/tests/test_hotel_room_model.py index 0e3b73071..4c28fdb2c 100644 --- a/hotel/tests/test_hotel_room_model.py +++ b/hotel/tests/test_hotel_room_model.py @@ -20,36 +20,15 @@ # along with this program. If not, see . # ############################################################################## -from datetime import timedelta from .common import TestHotel -from odoo.addons.hotel import date_utils +from odoo.exceptions import ValidationError class TestHotelRoom(TestHotel): - def test_cancel_folio(self): - now_utc_dt = date_utils.now() - - org_reserv_start_utc_dt = now_utc_dt + timedelta(days=3) - org_reserv_end_utc_dt = org_reserv_start_utc_dt + timedelta(days=6) - folio = self.create_folio(self.user_hotel_manager, self.partner_2) - reservation_a = self.create_reservation( - self.user_hotel_manager, - folio, - org_reserv_start_utc_dt, - org_reserv_end_utc_dt, - self.hotel_room_double_200, - "Reservation Test #1") - reservation_b = self.create_reservation( - self.user_hotel_manager, - folio, - org_reserv_start_utc_dt, - org_reserv_end_utc_dt, - self.hotel_room_simple_100, - "Reservation Test #2") - self.assertEqual(len(folio.room_lines), 2, 'Invalid room lines count') - folio.action_cancel() - self.assertEqual(folio.state, 'cancel', 'Invalid folio state') - for rline in folio.room_lines: - self.assertEqual(rline.state, 'cancelled', - 'Invalid reservation state') + def test_check_capacity(self): + # TODO Do the test using different users + with self.assertRaises(ValidationError): + self.room_0.sudo().write({ + 'capacity': 0 + }) diff --git a/hotel/tests/test_hotel_room_type_model.py b/hotel/tests/test_hotel_room_type_model.py index 360b47968..59a417298 100644 --- a/hotel/tests/test_hotel_room_type_model.py +++ b/hotel/tests/test_hotel_room_type_model.py @@ -21,15 +21,14 @@ # ############################################################################## from .common import TestHotel -from odoo.exceptions import ValidationError +from psycopg2 import IntegrityError + class TestHotelRoomType(TestHotel): - def test_change_room_ids(self): - - # Avoid the unconscious change of room type_id from room_type + def test_code_type_unique(self): #TODO: use sudo users hotel - with self.assertRaises(ValidationError): - cls.room_type_0.sudo().write({ - 'room_ids':(4, cls.room_type_3.id) + with self.assertRaises(IntegrityError): + self.room_type_0.sudo().write({ + 'code_type': self.room_type_1.code_type })