diff --git a/fleet_vehicle_ownership/tests/__init__.py b/fleet_vehicle_ownership/tests/__init__.py index a9afeec5..e3f32ac3 100644 --- a/fleet_vehicle_ownership/tests/__init__.py +++ b/fleet_vehicle_ownership/tests/__init__.py @@ -2,3 +2,5 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import test_owner + +from . import test_partner diff --git a/fleet_vehicle_ownership/tests/test_partner.py b/fleet_vehicle_ownership/tests/test_partner.py new file mode 100644 index 00000000..d3f43cdb --- /dev/null +++ b/fleet_vehicle_ownership/tests/test_partner.py @@ -0,0 +1,46 @@ +from odoo.tests import common + + +class TestResPartner(common.TransactionCase): + + def setUp(self): + super(TestResPartner, self).setUp() + + # Create necessary test data here, such as a partner and vehicles + self.partner = self.env['res.partner'].create({ + 'name': 'Lewis Hamilton', + }) + self.vehicle1 = self.env['fleet.vehicle'].create({ + 'name': 'W14', + 'owner_id': self.partner.id, + }) + self.vehicle2 = self.env['fleet.vehicle'].create({ + 'name': 'W13', + 'owner_id': self.partner.id, + }) + + def test_compute_vehicle_count(self): + # Check if the vehicle count is computed correctly + self.partner._compute_vehicle_count() + self.assertEqual(self.partner.vehicle_count, 2, "Vehicle count is incorrect") + + def test_action_view_vehicles(self): + # Check if action_view_vehicles method returns the correct action + action = self.partner.action_view_vehicles() + + # Assert that the action is correctly configured + self.assertEqual(action['res_model'], 'fleet.vehicle', "Incorrect res_model in action") + self.assertEqual(action['name'], 'Vehicles', "Incorrect name in action") + + # Test when there is more than one vehicle + self.partner.vehicle_count = 2 + action = self.partner.action_view_vehicles() + self.assertTrue(action['domain'], [("id", "in", self.partner.vehicle_ids.ids)], + "Incorrect domain when multiple vehicles") + + # Test when there is only one vehicle + self.partner.vehicle_count = 1 + action = self.partner.action_view_vehicles() + self.assertEqual(action['views'], [(self.env.ref("fleet.fleet_vehicle_view_form").id, "form")], + "Incorrect views when only one vehicle") + self.assertEqual(action['res_id'], self.partner.vehicle_ids.ids[0], "Incorrect res_id when only one vehicle")