diff --git a/fleet_vehicle_ownership/README.rst b/fleet_vehicle_ownership/README.rst new file mode 100644 index 00000000..eb952bd1 --- /dev/null +++ b/fleet_vehicle_ownership/README.rst @@ -0,0 +1,106 @@ +======================= +Fleet Vehicle Ownership +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c10570fb68e2d39efee546647fe22fcfc8b4b8022f384619750d9cd0d8428027 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffleet-lightgray.png?logo=github + :target: https://github.com/OCA/fleet/tree/14.0/fleet_vehicle_ownership + :alt: OCA/fleet +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/fleet-14-0/fleet-14-0-fleet_vehicle_ownership + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/fleet&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of fleet to support vehicle owner +data and to allow you to add vehicle ownership, linking partners to +vehicles + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +This is an extension of the 'fleet.vehicle' model in the Odoo framework. +It introduces a new field, 'owner_id', to track and associate the owner +of a vehicle. + +Fields: + +- owner_id: Many2one field linking to the 'res.partner' model. It + represents the owner of the vehicle. + +Usage: + +- This extension is particularly useful in scenarios where it's + essential to associate each fleet vehicle with a specific owner. +- The 'owner_id' field can be utilized to establish relationships with + partners in the 'res.partner' model, facilitating clear ownership + tracking. + +Usage +===== + +To use this module, you need to: + +1. Go to the veichle form and associate an owner or go to the partner + form and associate a vehicle. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* RPSJR + +Contributors +------------ + +- Raimundo Junior raimundopsjr@gmail.com + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/fleet `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/fleet_vehicle_ownership/__init__.py b/fleet_vehicle_ownership/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/fleet_vehicle_ownership/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fleet_vehicle_ownership/__manifest__.py b/fleet_vehicle_ownership/__manifest__.py new file mode 100644 index 00000000..65f7afb4 --- /dev/null +++ b/fleet_vehicle_ownership/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 RPSJR +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Fleet Vehicle Ownership", + "summary": "Add vehicle ownership, linking partners to vehicles", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "RPSJR,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/fleet", + "depends": ["fleet"], + "data": [ + "views/res_partner.xml", + "views/fleet_vehicle.xml", + ], + "demo": [ + "demo/fleet_vehicle.xml", + ], +} diff --git a/fleet_vehicle_ownership/demo/fleet_vehicle.xml b/fleet_vehicle_ownership/demo/fleet_vehicle.xml new file mode 100644 index 00000000..1e73af42 --- /dev/null +++ b/fleet_vehicle_ownership/demo/fleet_vehicle.xml @@ -0,0 +1,21 @@ + + + + + + 4-LH-44 + 44444 + 1 + Silver + Silverstone + + + kilometers + 44000 + + + diff --git a/fleet_vehicle_ownership/models/__init__.py b/fleet_vehicle_ownership/models/__init__.py new file mode 100644 index 00000000..b82fded7 --- /dev/null +++ b/fleet_vehicle_ownership/models/__init__.py @@ -0,0 +1,2 @@ +from . import fleet_vehicle +from . import res_partner diff --git a/fleet_vehicle_ownership/models/fleet_vehicle.py b/fleet_vehicle_ownership/models/fleet_vehicle.py new file mode 100644 index 00000000..9a3ce6b9 --- /dev/null +++ b/fleet_vehicle_ownership/models/fleet_vehicle.py @@ -0,0 +1,18 @@ +# Copyright 2023 RPSJR +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class FleetVehicle(models.Model): + + _inherit = "fleet.vehicle" + + owner_id = fields.Many2one( + "res.partner", + "Owner", + index=True, + tracking=True, + help="Owner of the vehicle", + copy=False, + ) diff --git a/fleet_vehicle_ownership/models/res_partner.py b/fleet_vehicle_ownership/models/res_partner.py new file mode 100644 index 00000000..8f93beca --- /dev/null +++ b/fleet_vehicle_ownership/models/res_partner.py @@ -0,0 +1,35 @@ +# Copyright 2023 RPSJR +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.depends("vehicle_ids") + def _compute_vehicle_count(self): + for rec in self: + rec.vehicle_count = len(rec.vehicle_ids) + + vehicle_ids = fields.One2many( + "fleet.vehicle", + "owner_id", + required=True, + help="Vehicles owned by this partner", + ) + vehicle_count = fields.Integer( + compute=_compute_vehicle_count, string="Number of Vehicles", store=True + ) + + def action_view_vehicles(self): + xmlid = "fleet.fleet_vehicle_action" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) + if self.vehicle_count > 1: + action["domain"] = [("id", "in", self.vehicle_ids.ids)] + else: + action["views"] = [ + (self.env.ref("fleet.fleet_vehicle_view_form").id, "form") + ] + action["res_id"] = self.vehicle_ids and self.vehicle_ids.ids[0] or False + return action diff --git a/fleet_vehicle_ownership/readme/CONTEXT.md b/fleet_vehicle_ownership/readme/CONTEXT.md new file mode 100644 index 00000000..f0fb63ec --- /dev/null +++ b/fleet_vehicle_ownership/readme/CONTEXT.md @@ -0,0 +1,9 @@ +This is an extension of the 'fleet.vehicle' model in the Odoo framework. +It introduces a new field, 'owner_id', to track and associate the owner of a vehicle. + +Fields: +- owner_id: Many2one field linking to the 'res.partner' model. It represents the owner of the vehicle. + +Usage: +- This extension is particularly useful in scenarios where it's essential to associate each fleet vehicle with a specific owner. +- The 'owner_id' field can be utilized to establish relationships with partners in the 'res.partner' model, facilitating clear ownership tracking. diff --git a/fleet_vehicle_ownership/readme/CONTRIBUTORS.md b/fleet_vehicle_ownership/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..e3fe9dd4 --- /dev/null +++ b/fleet_vehicle_ownership/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Raimundo Junior diff --git a/fleet_vehicle_ownership/readme/DESCRIPTION.md b/fleet_vehicle_ownership/readme/DESCRIPTION.md new file mode 100644 index 00000000..8bfb0f1c --- /dev/null +++ b/fleet_vehicle_ownership/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module extends the functionality of fleet to support vehicle owner data and to allow you to add vehicle ownership, linking partners to vehicles diff --git a/fleet_vehicle_ownership/readme/USAGE.md b/fleet_vehicle_ownership/readme/USAGE.md new file mode 100644 index 00000000..d0e67afd --- /dev/null +++ b/fleet_vehicle_ownership/readme/USAGE.md @@ -0,0 +1,3 @@ +To use this module, you need to: + +1. Go to the veichle form and associate an owner or go to the partner form and associate a vehicle. diff --git a/fleet_vehicle_ownership/static/description/icon.png b/fleet_vehicle_ownership/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/fleet_vehicle_ownership/static/description/icon.png differ diff --git a/fleet_vehicle_ownership/static/description/index.html b/fleet_vehicle_ownership/static/description/index.html new file mode 100644 index 00000000..ac1481ca --- /dev/null +++ b/fleet_vehicle_ownership/static/description/index.html @@ -0,0 +1,452 @@ + + + + + + +Fleet Vehicle Ownership + + + +
+

Fleet Vehicle Ownership

+ + +

Beta License: AGPL-3 OCA/fleet Translate me on Weblate Try me on Runboat

+

This module extends the functionality of fleet to support vehicle owner +data and to allow you to add vehicle ownership, linking partners to +vehicles

+

Table of contents

+ +
+

Use Cases / Context

+

This is an extension of the ‘fleet.vehicle’ model in the Odoo framework. +It introduces a new field, ‘owner_id’, to track and associate the owner +of a vehicle.

+

Fields:

+
    +
  • owner_id: Many2one field linking to the ‘res.partner’ model. It +represents the owner of the vehicle.
  • +
+

Usage:

+
    +
  • This extension is particularly useful in scenarios where it’s +essential to associate each fleet vehicle with a specific owner.
  • +
  • The ‘owner_id’ field can be utilized to establish relationships with +partners in the ‘res.partner’ model, facilitating clear ownership +tracking.
  • +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to the veichle form and associate an owner or go to the partner +form and associate a vehicle.
  2. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • RPSJR
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/fleet project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/fleet_vehicle_ownership/tests/__init__.py b/fleet_vehicle_ownership/tests/__init__.py new file mode 100644 index 00000000..e739f779 --- /dev/null +++ b/fleet_vehicle_ownership/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fleet_vehicle_owner diff --git a/fleet_vehicle_ownership/tests/test_fleet_vehicle_owner.py b/fleet_vehicle_ownership/tests/test_fleet_vehicle_owner.py new file mode 100644 index 00000000..4edaaaef --- /dev/null +++ b/fleet_vehicle_ownership/tests/test_fleet_vehicle_owner.py @@ -0,0 +1,78 @@ +from odoo.tests import SavepointCase + + +class TestFleetVehicleOwner(SavepointCase): + def setUp(self): + super(TestFleetVehicleOwner, 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( + { + "license_plate": "1-ACK-554", + "vin_sn": "8833334", + "color": "Black", + "location": "Grand-Rosiere", + "doors": 5, + "driver_id": self.partner.id, + "owner_id": self.partner.id, + "odometer_unit": "kilometers", + "car_value": 20000, + "model_id": self.env.ref("fleet.model_astra").id, + } + ) + self.vehicle2 = self.env["fleet.vehicle"].create( + { + "license_plate": "1-ACK-544", + "vin_sn": "8833332", + "color": "Black", + "location": "Grand-Rosiere", + "doors": 5, + "driver_id": self.partner.id, + "owner_id": self.partner.id, + "odometer_unit": "kilometers", + "car_value": 30000, + "model_id": self.env.ref("fleet.model_astra").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"], + "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", + ) diff --git a/fleet_vehicle_ownership/views/fleet_vehicle.xml b/fleet_vehicle_ownership/views/fleet_vehicle.xml new file mode 100644 index 00000000..901ae1f7 --- /dev/null +++ b/fleet_vehicle_ownership/views/fleet_vehicle.xml @@ -0,0 +1,23 @@ + + + + fleet.vehicle.form.inherited + fleet.vehicle + + + + + + + + + fleet.vehicle.tree.inherited + fleet.vehicle + + + + + + + + diff --git a/fleet_vehicle_ownership/views/res_partner.xml b/fleet_vehicle_ownership/views/res_partner.xml new file mode 100644 index 00000000..086703f9 --- /dev/null +++ b/fleet_vehicle_ownership/views/res_partner.xml @@ -0,0 +1,24 @@ + + + + + res.partner + + +
+ +
+
+
+
diff --git a/setup/fleet_vehicle_ownership/odoo/addons/fleet_vehicle_ownership b/setup/fleet_vehicle_ownership/odoo/addons/fleet_vehicle_ownership new file mode 120000 index 00000000..8b421aab --- /dev/null +++ b/setup/fleet_vehicle_ownership/odoo/addons/fleet_vehicle_ownership @@ -0,0 +1 @@ +../../../../fleet_vehicle_ownership \ No newline at end of file diff --git a/setup/fleet_vehicle_ownership/setup.py b/setup/fleet_vehicle_ownership/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/fleet_vehicle_ownership/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)