From d01c09aea690e152759c123cd3a5e4dbe2033fa7 Mon Sep 17 00:00:00 2001 From: Robin Keunen Date: Thu, 3 Aug 2023 18:13:33 +0200 Subject: [PATCH] [FIX] pms: error trying to access integer property AttributeError: 'int' object has no attribute 'id' --- pms/models/pms_room_type.py | 6 +++++- pms/tests/test_pms_booking_engine.py | 24 ++++++++++++++++++++++-- pms/tests/test_pms_room_type.py | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pms/models/pms_room_type.py b/pms/models/pms_room_type.py index 4338ede30..ff23b3f54 100644 --- a/pms/models/pms_room_type.py +++ b/pms/models/pms_room_type.py @@ -207,8 +207,12 @@ class PmsRoomType(models.Model): # return super().unlink() def get_room_type_capacity(self, pms_property_id): + """ + :param pms_property_id: int + :return: the minimum capacity for rooms of current type + """ self.ensure_one() capacities = self.room_ids.filtered( - lambda r: r.pms_property_id.id == pms_property_id.id + lambda r: not r.pms_property_id or r.pms_property_id.id == pms_property_id ).mapped("capacity") return min(capacities) if any(capacities) else 0 diff --git a/pms/tests/test_pms_booking_engine.py b/pms/tests/test_pms_booking_engine.py index 9ae84220b..c5e073492 100644 --- a/pms/tests/test_pms_booking_engine.py +++ b/pms/tests/test_pms_booking_engine.py @@ -737,7 +737,7 @@ class TestPmsBookingEngine(TestPms): self.assertEqual(room_type_plan_avail, 0, "Quota not applied in Wizard Folio") @freeze_time("2015-05-05") - def _test_price_total_with_board_service(self): + def test_price_total_with_board_service(self): """ In booking engine when in availability results choose a room or several and also choose a board service, the total price is calculated from price of the room, @@ -808,7 +808,7 @@ class TestPmsBookingEngine(TestPms): room_price = self.test_room_type_double.list_price days = (checkout - checkin).days board_service_price = self.board_service_test.amount - room_capacity = self.test_room_type_double.get_capacity() + room_capacity = self.test_room_type_double.get_room_type_capacity(self.pms_property1.id) expected_price = room_price * days + ( board_service_price * room_capacity * days ) @@ -985,3 +985,23 @@ class TestPmsBookingEngine(TestPms): 1, "Reservations of folio are incorrect", ) + + def test_adding_board_services_are_saved_on_lines(self): + checkin = fields.date.today() + checkout = fields.date.today() + datetime.timedelta(days=1) + + booking_engine = self.env["pms.booking.engine"].create( + { + "start_date": checkin, + "end_date": checkout, + "partner_id": self.partner_id.id, + "pricelist_id": self.pricelist1.id, + "pms_property_id": self.pms_property1.id, + "channel_type_id": self.sale_channel_direct1.id, + } + ) + lines_availability_test_double = booking_engine.availability_results.filtered( + lambda r: r.room_type_id.id == self.test_room_type_double.id + ) + lines_availability_test_double + self.assertTrue(False) diff --git a/pms/tests/test_pms_room_type.py b/pms/tests/test_pms_room_type.py index 3413d21d7..cd9410e61 100644 --- a/pms/tests/test_pms_room_type.py +++ b/pms/tests/test_pms_room_type.py @@ -862,7 +862,7 @@ class TestRoomType(TestPms): } ) - def test_rooom_type_creation_consistency_amenity(self): + def test_room_type_creation_consistency_amenity(self): """ Create an amenity belonging to one property. Create a room type belonging to same property.