-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] fleet_vehicle_log_fuel: Migration to 16.0
TT48096
- Loading branch information
1 parent
cebfffa
commit 4ae834a
Showing
15 changed files
with
185 additions
and
74 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
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
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
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
* Miquel Raïch <miquel.raich@forgeflow.com> | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Víctor Martínez |
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
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 @@ | ||
from . import test_fleet_vehicle_log_fuel |
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,24 @@ | ||
# Copyright 2024 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl | ||
from odoo.addons.base.tests.common import BaseCommon | ||
|
||
|
||
class TestFleetVehicleLogFuelBase(BaseCommon): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.driver = cls.env["res.partner"].create({"name": "Test Driver"}) | ||
cls.brand = cls.env["fleet.vehicle.model.brand"].create({"name": "Test brand"}) | ||
cls.model = cls.env["fleet.vehicle.model"].create( | ||
{ | ||
"name": "Test model", | ||
"brand_id": cls.brand.id, | ||
} | ||
) | ||
cls.vehicle = cls.env["fleet.vehicle"].create( | ||
{ | ||
"model_id": cls.model.id, | ||
"driver_id": cls.driver.id, | ||
"license_plate": "TEST123", | ||
} | ||
) |
92 changes: 92 additions & 0 deletions
92
fleet_vehicle_log_fuel/tests/test_fleet_vehicle_log_fuel.py
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,92 @@ | ||
# Copyright 2024 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl | ||
from odoo.exceptions import UserError | ||
from odoo.tests import Form | ||
|
||
from .common import TestFleetVehicleLogFuelBase | ||
|
||
|
||
class TestFleetVehicleLogFuelMisc(TestFleetVehicleLogFuelBase): | ||
def test_fleet_vehicle_log_fuel_process(self): | ||
fuel_form = Form( | ||
self.env["fleet.vehicle.log.fuel"].with_context( | ||
default_vehicle_id=self.vehicle.id | ||
) | ||
) | ||
with self.assertRaises(UserError): | ||
fuel_form.odometer = 0 | ||
fuel_form.save() | ||
fuel_form.odometer = 5000 | ||
fuel = fuel_form.save() | ||
self.assertTrue(fuel.odometer_id) | ||
self.assertEqual(self.vehicle.odometer, 5000) | ||
self.assertEqual(self.vehicle.fuel_count, 1) | ||
res = self.vehicle.action_view_log_fuel() | ||
items = self.env[res["res_model"]].search(res["domain"]) | ||
self.assertIn(fuel, items) | ||
|
||
def test_fleet_vehicle_log_fuel_onchange(self): | ||
# Check amount | ||
fuel_form_1 = Form( | ||
self.env["fleet.vehicle.log.fuel"].with_context( | ||
default_vehicle_id=self.vehicle.id | ||
) | ||
) | ||
fuel_form_1.liter = 50 | ||
fuel_form_1.price_per_liter = 1.5 | ||
self.assertEqual(fuel_form_1.amount, 75) | ||
# Check price_per_liter | ||
fuel_form_2 = Form( | ||
self.env["fleet.vehicle.log.fuel"].with_context( | ||
default_vehicle_id=self.vehicle.id | ||
) | ||
) | ||
fuel_form_2.amount = 75 | ||
fuel_form_2.liter = 50 | ||
self.assertEqual(fuel_form_2.price_per_liter, 1.5) | ||
# Check liter | ||
fuel_form_2 = Form( | ||
self.env["fleet.vehicle.log.fuel"].with_context( | ||
default_vehicle_id=self.vehicle.id | ||
) | ||
) | ||
fuel_form_2.amount = 75 | ||
fuel_form_2.price_per_liter = 1.5 | ||
self.assertEqual(fuel_form_2.liter, 50) | ||
|
||
|
||
class TestFleetVehicleLogFuelReport(TestFleetVehicleLogFuelBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
# Create log fuel + log service to check report after | ||
cls.service_type = cls.env["fleet.service.type"].create( | ||
{"name": "Test fuel", "category": "fuel"} | ||
) | ||
cls.env["fleet.vehicle.log.fuel"].create( | ||
{ | ||
"vehicle_id": cls.vehicle.id, | ||
"service_type_id": cls.service_type.id, | ||
"date": "2024-01-01", | ||
"amount": 75, | ||
"price_per_liter": 1.5, | ||
"liter": 50, | ||
} | ||
) | ||
cls.env["fleet.vehicle.log.services"].create( | ||
{ | ||
"vehicle_id": cls.vehicle.id, | ||
"service_type_id": cls.service_type.id, | ||
"amount": 75, | ||
"date": "2024-01-01", | ||
} | ||
) | ||
|
||
def test_fleet_vehicle_cost_report(self): | ||
items = self.env["fleet.vehicle.cost.report"].search( | ||
[("vehicle_id", "=", self.vehicle.id), ("date_start", "=", "2024-01-01")] | ||
) | ||
self.assertIn("fuel", items.mapped("cost_type")) | ||
self.assertEqual( | ||
sum(items.filtered(lambda x: x.cost_type == "fuel").mapped("cost")), 75 | ||
) |
Oops, something went wrong.