diff --git a/hotel/tests/__init__.py b/hotel/tests/__init__.py index 2dec7c131..4428c2cc2 100644 --- a/hotel/tests/__init__.py +++ b/hotel/tests/__init__.py @@ -25,3 +25,4 @@ from . import test_inherited_ir_http from . import test_hotel_room_type from . import test_hotel_room +from . import test_massive_changes diff --git a/hotel/tests/common.py b/hotel/tests/common.py index dcab954e2..be7844f90 100644 --- a/hotel/tests/common.py +++ b/hotel/tests/common.py @@ -98,3 +98,8 @@ class TestHotel(common.SavepointCase): cls.room_5 = cls.env.ref('hotel.hotel_room_5') cls.room_6 = cls.env.ref('hotel.hotel_room_6') + cls.list0 = cls.env.ref('product.list0') + cls.list1 = cls.env['product.pricelist'].create({ + 'name': 'Test Pricelist', + 'pricelist_type': '' + }) diff --git a/hotel/tests/test_massive_changes.py b/hotel/tests/test_massive_changes.py new file mode 100644 index 000000000..83b0a3ee9 --- /dev/null +++ b/hotel/tests/test_massive_changes.py @@ -0,0 +1,70 @@ +from .common import TestHotel +from odoo import fields +from odoo.exceptions import ValidationError + + +class TestMassiveChanges(TestHotel): + + # be aware using self.env.user.hotel_id because it is the value configure for the user running the tests + + # base massive change record + def base_massive_change_vals(self, hotel_id=None): + return { + 'hotel_id': hotel_id and hotel_id.id or self.main_hotel_property.id, + 'date_start': fields.Date.today(), + 'date_end': fields.Date.today(), + } + + def pricelist_massive_change_vals(self, pricelist_id=None): + return { + 'pricelist_id': pricelist_id and pricelist_id.id or self.list0.id, + 'price': 50.0, + } + + def test_daily_pricelist(self): + # Only daily pricelist can be manage by a massive change + self.list0.pricelist_type = '' + with self.assertRaises(ValidationError): + vals = self.base_massive_change_vals() + vals.update( + self.pricelist_massive_change_vals() + ) + self.env['hotel.wizard.massive.changes'].create(vals) + + # create a valid record using a daily pricelist + self.list0.pricelist_type = 'daily' + test_result = self.env['hotel.wizard.massive.changes'].create(vals) + self.assertEqual(test_result.pricelist_id, self.list0) + + def test_pricelist_by_hotel(self): + # Ensure the pricelist plan belongs to the current hotel #1 + with self.assertRaises(ValidationError): + vals = self.base_massive_change_vals(self.demo_hotel_property) + vals.update( + self.pricelist_massive_change_vals() + ) + self.env['hotel.wizard.massive.changes'].create(vals) + + # Ensure the pricelist plan belongs to the current hotel #2 + with self.assertRaises(ValidationError): + vals = self.base_massive_change_vals() + vals.update( + self.pricelist_massive_change_vals(self.list1) + ) + self.list1.hotel_ids = self.demo_hotel_property + self.list1.pricelist_type = 'daily' + self.env['hotel.wizard.massive.changes'].create(vals) + + # create a valid record using the current hotel + vals = self.base_massive_change_vals() + vals.update( + self.pricelist_massive_change_vals(self.list1) + ) + self.list1.hotel_ids = self.main_hotel_property + self.list1.pricelist_type = 'daily' + test_result = self.env['hotel.wizard.massive.changes'].create(vals) + self.assertEqual(test_result.pricelist_id.hotel_ids, self.main_hotel_property) + + def test_do_massive_change(self): + # check the result of a massive change + pass