Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions fleet_vehicle_purchase_link/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/fleet/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 <https://github.com/OCA/fleet/issues/new?body=module:%20fleet_vehicle_purchase_link%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Escodoo

Contributors
~~~~~~~~~~~~

* `Escodoo <https://www.escodoo.com.br>`_:

* Wesley Oliveira <wesley.oliveira@escodoo.com.br>

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-WesleyOliveira98|

This module is part of the `OCA/fleet <https://github.com/OCA/fleet/tree/16.0/fleet_vehicle_purchase_link>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions fleet_vehicle_purchase_link/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions fleet_vehicle_purchase_link/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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""",
Comment on lines +6 to +7

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"summary": """
Link fleet vehicles to purchase order lines""",
"summary": "Link fleet vehicles to purchase order lines",

"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"author": "Escodoo,Odoo Community Association (OCA)",
"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,
}
34 changes: 34 additions & 0 deletions fleet_vehicle_purchase_link/i18n/fleet_vehicle_purchase_link.pot
Original file line number Diff line number Diff line change
@@ -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 ""
1 change: 1 addition & 0 deletions fleet_vehicle_purchase_link/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import fleet_vehicle
33 changes: 33 additions & 0 deletions fleet_vehicle_purchase_link/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2026 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2026 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>
# Copyright 2026 Escodoo - Wesley Oliveira <wesley.oliveira@escodoo.com.br>

Apply this copyright header format across all other files as well.

# 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),
]
)
Comment on lines +15 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 _compute_purchase_line_count(self):
line_model = self.env["purchase.order.line"]
data = line_model.read_group(
[("fleet_vehicle_id", "in", self.ids)],
["fleet_vehicle_id"],
["fleet_vehicle_id"],
)
mapped_data = {
item["fleet_vehicle_id"][0]: item["fleet_vehicle_id_count"]
for item in data
}
for vehicle in self:
vehicle.purchase_line_count = mapped_data.get(vehicle.id, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduces N SQL queries (one per vehicle) to a single read_group() query, improving performance on list views with multiple records.


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},
}
3 changes: 3 additions & 0 deletions fleet_vehicle_purchase_link/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Wesley Oliveira <wesley.oliveira@escodoo.com.br>
3 changes: 3 additions & 0 deletions fleet_vehicle_purchase_link/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions fleet_vehicle_purchase_link/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading