Skip to content
Draft
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
120 changes: 120 additions & 0 deletions fleet_vehicle_analytic_purchase/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
===============================
Fleet Vehicle Analytic Purchase
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:701e9ec0a02919199987496264b1b75d1a12413369d3d3fefe9306a5adae49d0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/18.0/fleet_vehicle_analytic_purchase
:alt: OCA/fleet
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/fleet-18-0/fleet-18-0-fleet_vehicle_analytic_purchase
: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=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of fleet management to link each
vehicle to one or more analytic accounts (cost centers), using the same
analytic distribution field used everywhere else in Odoo accounting. It
also gives direct access, from the vehicle form, to every purchase order
that shares an analytic account with the vehicle.

It also makes the analytic accounts of a purchase order searchable from
the user interface, reusing the ``analytic_distribution`` field that the
OCA ``purchase_analytic`` module already adds on the purchase order
header. In Odoo that field is stored as JSON, which is not searchable
from a regular search view out of the box; the ``analytic.mixin`` it
relies on already solves that by exposing a computed and searchable
``distribution_analytic_account_ids`` field, which this module simply
adds to the Requests for Quotation and Purchase Orders search views.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module you need to:

1. Go to *Fleet > Vehicles* and open a vehicle.
2. In the *Vehicle* group, set the **Analytic Distribution** of the
vehicle (its cost center or centers, with the percentage of each
one).
3. A **Purchase Orders** smart button appears at the top of the form. It
shows how many purchase orders have at least one line whose analytic
distribution shares an analytic account with the vehicle, and opens
them when clicked.

To filter purchase orders by analytic account:

1. Go to *Purchase > Orders > Purchase Orders* (or *Requests for
Quotation*).
2. Type the name of an analytic account in the search box and pick the
**Analytic Account** entry, or add it from the filter dropdown.

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_analytic_purchase%0Aversion:%2018.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>`__:

- Cristiano Mafra Junior <cristiano.mafra@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-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px
:target: https://github.com/marcelsavegnago
:alt: marcelsavegnago

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-marcelsavegnago|

This module is part of the `OCA/fleet <https://github.com/OCA/fleet/tree/18.0/fleet_vehicle_analytic_purchase>`_ 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_analytic_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
27 changes: 27 additions & 0 deletions fleet_vehicle_analytic_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2026 - TODAY, Cristiano Mafra Junior <cristiano.mafra@escodoo.com.br>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Fleet Vehicle Analytic Purchase",
"summary": """
Link vehicles to analytic accounts (cost centers) and browse the
purchase orders of those cost centers from the vehicle form.""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"category": "Human Resources/Fleet",
"author": "Escodoo,Odoo Community Association (OCA)",
"maintainers": ["marcelsavegnago"],
"website": "https://github.com/OCA/fleet",
"depends": [
"analytic",
"fleet",
"purchase",
"purchase_analytic",
],
"data": [
"views/fleet_vehicle.xml",
"views/purchase_order.xml",
],
"installable": True,
"auto_install": False,
}
1 change: 1 addition & 0 deletions fleet_vehicle_analytic_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import fleet_vehicle
59 changes: 59 additions & 0 deletions fleet_vehicle_analytic_purchase/models/fleet_vehicle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2026 - TODAY, Cristiano Mafra Junior <cristiano.mafra@escodoo.com.br>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from collections import defaultdict

from odoo import api, fields, models


class FleetVehicle(models.Model):
_name = "fleet.vehicle"
_inherit = ["fleet.vehicle", "analytic.mixin"]

purchase_order_count = fields.Integer(
string="Purchase Orders",
compute="_compute_purchase_order_count",
)

@api.depends("distribution_analytic_account_ids")
def _compute_purchase_order_count(self):
self.purchase_order_count = 0
vehicles = self.filtered("distribution_analytic_account_ids")
if not vehicles:
return
lines = self.env["purchase.order.line"].search(
[
(
"distribution_analytic_account_ids",
"in",
vehicles.distribution_analytic_account_ids.ids,
)
]
)
orders_per_account = defaultdict(set)
for line in lines:
for account in line.distribution_analytic_account_ids:
orders_per_account[account.id].add(line.order_id.id)
for vehicle in vehicles:
order_ids = set()
for account in vehicle.distribution_analytic_account_ids:
order_ids |= orders_per_account[account.id]
vehicle.purchase_order_count = len(order_ids)

def action_view_purchase_orders(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"purchase.purchase_form_action"
)
action.update(
{
"domain": [
(
"order_line.distribution_analytic_account_ids",
"in",
self.distribution_analytic_account_ids.ids,
)
],
}
)
return action
3 changes: 3 additions & 0 deletions fleet_vehicle_analytic_purchase/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions fleet_vehicle_analytic_purchase/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Escodoo](https://www.escodoo.com.br):
- Cristiano Mafra Junior \<<cristiano.mafra@escodoo.com.br>\>
14 changes: 14 additions & 0 deletions fleet_vehicle_analytic_purchase/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This module extends the functionality of fleet management to link each vehicle
to one or more analytic accounts (cost centers), using the same analytic
distribution field used everywhere else in Odoo accounting. It also gives
direct access, from the vehicle form, to every purchase order that shares an
analytic account with the vehicle.

It also makes the analytic accounts of a purchase order searchable from the
user interface, reusing the `analytic_distribution` field that the OCA
`purchase_analytic` module already adds on the purchase order header. In Odoo
that field is stored as JSON, which is not searchable from a regular search
view out of the box; the `analytic.mixin` it relies on already solves that by
exposing a computed and searchable `distribution_analytic_account_ids` field,
which this module simply adds to the Requests for Quotation and Purchase
Orders search views.
15 changes: 15 additions & 0 deletions fleet_vehicle_analytic_purchase/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
To use this module you need to:

1. Go to *Fleet > Vehicles* and open a vehicle.
2. In the *Vehicle* group, set the **Analytic Distribution** of the vehicle
(its cost center or centers, with the percentage of each one).
3. A **Purchase Orders** smart button appears at the top of the form. It shows
how many purchase orders have at least one line whose analytic
distribution shares an analytic account with the vehicle, and opens them
when clicked.

To filter purchase orders by analytic account:

1. Go to *Purchase > Orders > Purchase Orders* (or *Requests for Quotation*).
2. Type the name of an analytic account in the search box and pick the
**Analytic Account** entry, or add it from the filter dropdown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading