-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RPSJR
committed
Nov 24, 2023
1 parent
ceedfa5
commit 3ac6afc
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |