diff --git a/fleet_vehicle_purchase_link/README.rst b/fleet_vehicle_purchase_link/README.rst new file mode 100644 index 000000000..9ace19a7d --- /dev/null +++ b/fleet_vehicle_purchase_link/README.rst @@ -0,0 +1,104 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=========================== +Fleet Vehicle Purchase Link +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0bdafb694ee2bf7cb4d2700daabba38fa885ceb18ef56a8feeba48df6cf20e48 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/16.0/fleet_vehicle_purchase_link + :alt: OCA/fleet +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/fleet-16-0/fleet-16-0-fleet_vehicle_purchase_link + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module links fleet vehicles to purchases, allowing a vehicle to be set +on each purchase order line and providing a smart button and menu to navigate +between vehicles and their related purchases. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Go to the Purchase application and open or create a purchase order. +2. On each order line, set the related fleet vehicle. +3. Go to the Fleet application and open a vehicle to see the Purchases smart + button with the count of linked purchase order lines; click it to list them. +4. Go to Fleet > Fleet > Purchases to list the purchase orders that have at + least one line linked to 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 +~~~~~~~ + +* Escodoo + +Contributors +~~~~~~~~~~~~ + +* `Escodoo `_: + + * Wesley Oliveira + +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. + +.. |maintainer-WesleyOliveira98| image:: https://github.com/WesleyOliveira98.png?size=40px + :target: https://github.com/WesleyOliveira98 + :alt: WesleyOliveira98 + +Current `maintainer `__: + +|maintainer-WesleyOliveira98| + +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_purchase_link/__init__.py b/fleet_vehicle_purchase_link/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/fleet_vehicle_purchase_link/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fleet_vehicle_purchase_link/__manifest__.py b/fleet_vehicle_purchase_link/__manifest__.py new file mode 100644 index 000000000..31f90a901 --- /dev/null +++ b/fleet_vehicle_purchase_link/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2026 - TODAY, Escodoo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Fleet Vehicle Purchase Link", + "summary": """ + Link fleet vehicles to purchase order lines""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Escodoo,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/fleet", + "category": "Fleet", + "maintainers": ["WesleyOliveira98"], + "depends": ["fleet_vehicle_purchase"], + "data": [ + "views/fleet_vehicle_views.xml", + ], + "installable": True, +} diff --git a/fleet_vehicle_purchase_link/i18n/fleet_vehicle_purchase_link.pot b/fleet_vehicle_purchase_link/i18n/fleet_vehicle_purchase_link.pot new file mode 100644 index 000000000..831b72158 --- /dev/null +++ b/fleet_vehicle_purchase_link/i18n/fleet_vehicle_purchase_link.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fleet_vehicle_purchase_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: fleet_vehicle_purchase_link +#. odoo-python +#: code:addons/fleet_vehicle_purchase_link/models/fleet_vehicle.py:0 +#: model:ir.model.fields,field_description:fleet_vehicle_purchase_link.field_fleet_vehicle__purchase_line_count +#, python-format +msgid "Purchase Lines" +msgstr "" + +#. module: fleet_vehicle_purchase_link +#: model:ir.actions.act_window,name:fleet_vehicle_purchase_link.purchase_order_with_vehicle_action +#: model:ir.ui.menu,name:fleet_vehicle_purchase_link.fleet_purchase_menu +#: model_terms:ir.ui.view,arch_db:fleet_vehicle_purchase_link.fleet_vehicle_view_form_inherit +msgid "Purchases" +msgstr "" + +#. module: fleet_vehicle_purchase_link +#: model:ir.model,name:fleet_vehicle_purchase_link.model_fleet_vehicle +msgid "Vehicle" +msgstr "" diff --git a/fleet_vehicle_purchase_link/models/__init__.py b/fleet_vehicle_purchase_link/models/__init__.py new file mode 100644 index 000000000..53bbf7bdf --- /dev/null +++ b/fleet_vehicle_purchase_link/models/__init__.py @@ -0,0 +1 @@ +from . import fleet_vehicle diff --git a/fleet_vehicle_purchase_link/models/fleet_vehicle.py b/fleet_vehicle_purchase_link/models/fleet_vehicle.py new file mode 100644 index 000000000..085376316 --- /dev/null +++ b/fleet_vehicle_purchase_link/models/fleet_vehicle.py @@ -0,0 +1,33 @@ +# Copyright 2026 - TODAY, Wesley Oliveira +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class FleetVehicle(models.Model): + _inherit = "fleet.vehicle" + + purchase_line_count = fields.Integer( + string="Purchase Lines", + compute="_compute_purchase_line_count", + ) + + def _compute_purchase_line_count(self): + line_model = self.env["purchase.order.line"] + for vehicle in self: + vehicle.purchase_line_count = line_model.search_count( + [ + ("fleet_vehicle_id", "=", vehicle.id), + ] + ) + + def action_view_purchase_lines(self): + self.ensure_one() + return { + "name": _("Purchase Lines"), + "type": "ir.actions.act_window", + "res_model": "purchase.order.line", + "view_mode": "tree,form", + "domain": [("fleet_vehicle_id", "=", self.id)], + "context": {"default_fleet_vehicle_id": self.id}, + } diff --git a/fleet_vehicle_purchase_link/readme/CONTRIBUTORS.rst b/fleet_vehicle_purchase_link/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2f9bd6d02 --- /dev/null +++ b/fleet_vehicle_purchase_link/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Escodoo `_: + + * Wesley Oliveira diff --git a/fleet_vehicle_purchase_link/readme/DESCRIPTION.rst b/fleet_vehicle_purchase_link/readme/DESCRIPTION.rst new file mode 100644 index 000000000..39701687d --- /dev/null +++ b/fleet_vehicle_purchase_link/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module links fleet vehicles to purchases, allowing a vehicle to be set +on each purchase order line and providing a smart button and menu to navigate +between vehicles and their related purchases. diff --git a/fleet_vehicle_purchase_link/readme/USAGE.rst b/fleet_vehicle_purchase_link/readme/USAGE.rst new file mode 100644 index 000000000..5cb1a23c8 --- /dev/null +++ b/fleet_vehicle_purchase_link/readme/USAGE.rst @@ -0,0 +1,8 @@ +To use this module, you need to: + +1. Go to the Purchase application and open or create a purchase order. +2. On each order line, set the related fleet vehicle. +3. Go to the Fleet application and open a vehicle to see the Purchases smart + button with the count of linked purchase order lines; click it to list them. +4. Go to Fleet > Fleet > Purchases to list the purchase orders that have at + least one line linked to a vehicle. diff --git a/fleet_vehicle_purchase_link/static/description/icon.png b/fleet_vehicle_purchase_link/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/fleet_vehicle_purchase_link/static/description/icon.png differ diff --git a/fleet_vehicle_purchase_link/static/description/index.html b/fleet_vehicle_purchase_link/static/description/index.html new file mode 100644 index 000000000..995df109a --- /dev/null +++ b/fleet_vehicle_purchase_link/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + + +
+ + diff --git a/fleet_vehicle_purchase_link/tests/__init__.py b/fleet_vehicle_purchase_link/tests/__init__.py new file mode 100644 index 000000000..ba0f98bbb --- /dev/null +++ b/fleet_vehicle_purchase_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fleet_vehicle_purchase_link diff --git a/fleet_vehicle_purchase_link/tests/test_fleet_vehicle_purchase_link.py b/fleet_vehicle_purchase_link/tests/test_fleet_vehicle_purchase_link.py new file mode 100644 index 000000000..00e5d9991 --- /dev/null +++ b/fleet_vehicle_purchase_link/tests/test_fleet_vehicle_purchase_link.py @@ -0,0 +1,45 @@ +# Copyright 2026 - TODAY, Wesley Oliveira +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import Form, TransactionCase + + +class TestFleetVehiclePurchaseLink(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + 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.car = cls.env["fleet.vehicle"].create({"model_id": cls.model.id}) + cls.other_car = cls.env["fleet.vehicle"].create({"model_id": cls.model.id}) + cls.product = cls.env["product.product"].create( + {"name": "Test product", "type": "service"} + ) + order_form = Form(cls.env["purchase.order"]) + order_form.partner_id = cls.env.user.partner_id + order_form.fleet_vehicle_id = cls.car + with order_form.order_line.new() as line_form: + line_form.product_id = cls.product + line_form.price_unit = 100 + with order_form.order_line.new() as line_form: + line_form.product_id = cls.product + line_form.price_unit = 200 + cls.order = order_form.save() + + def test_purchase_line_count(self): + self.assertEqual(2, self.car.purchase_line_count) + self.assertEqual(0, self.other_car.purchase_line_count) + + def test_view_purchase_lines(self): + action = self.car.action_view_purchase_lines() + self.assertEqual( + self.order.order_line, + self.env[action["res_model"]].search(action["domain"]), + ) + self.assertEqual(self.car.id, action["context"]["default_fleet_vehicle_id"]) + + def test_view_purchase_lines_without_purchases(self): + action = self.other_car.action_view_purchase_lines() + self.assertFalse(self.env[action["res_model"]].search(action["domain"])) diff --git a/fleet_vehicle_purchase_link/views/fleet_vehicle_views.xml b/fleet_vehicle_purchase_link/views/fleet_vehicle_views.xml new file mode 100644 index 000000000..edf243f6f --- /dev/null +++ b/fleet_vehicle_purchase_link/views/fleet_vehicle_views.xml @@ -0,0 +1,42 @@ + + + + + fleet.vehicle.form.inherit + fleet.vehicle + + + + + + + + + + Purchases + purchase.order + tree,form + [('order_line.fleet_vehicle_id', '!=', False)] + + + + diff --git a/setup/fleet_vehicle_purchase_link/odoo/addons/fleet_vehicle_purchase_link b/setup/fleet_vehicle_purchase_link/odoo/addons/fleet_vehicle_purchase_link new file mode 120000 index 000000000..de74d7963 --- /dev/null +++ b/setup/fleet_vehicle_purchase_link/odoo/addons/fleet_vehicle_purchase_link @@ -0,0 +1 @@ +../../../../fleet_vehicle_purchase_link \ No newline at end of file diff --git a/setup/fleet_vehicle_purchase_link/setup.py b/setup/fleet_vehicle_purchase_link/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/fleet_vehicle_purchase_link/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)