Skip to content

Commit b5c275f

Browse files
committed
[ADD] fleet_vehicle_category_analytic: Set analytic account on invoice line from vehicle, via vehicle categories
1 parent 05f7599 commit b5c275f

15 files changed

Lines changed: 216 additions & 0 deletions

File tree

fleet_vehicle_category/views/fleet_vehicle_views.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<field name="name" />
3030
</h1>
3131
</div>
32+
<group name="main" />
3233
<notebook>
3334
<page name="description_page" string="Description">
3435
<field name="description" type="html" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2026 Arnaud Layec (<arnaud.layec@akretion.com>)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Fleet Vehicle Analytic",
6+
"summary": """
7+
Define Analytic Account per vehicle category
8+
""",
9+
"version": "18.0.1.0.0",
10+
"category": "Human Resources",
11+
"author": "Arnaud Layec, Akretion "
12+
"Odoo Community Association (OCA)",
13+
"website": "https://github.com/OCA/fleet",
14+
"license": "AGPL-3",
15+
"depends": ["account_fleet", "fleet_vehicle_category"],
16+
"data": ["views/fleet_vehicle_category_views.xml"],
17+
"installable": True,
18+
"auto_install": False,
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import account_move_line, fleet_vehicle_category
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2026 - Arnaud LAYEC <arnaud.layec@akretion.com>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, models
5+
6+
class AccountMoveLine(models.Model):
7+
_inherit = ["account.move.line"]
8+
9+
@api.depends("vehicle_id")
10+
def _compute_analytic_distribution(self):
11+
"""Inject the analytic account of the vehicle's category.
12+
When the account is already present in the distribution its
13+
percentage is kept as-is to avoid overriding manual adjustments made
14+
through other sources; otherwise it is added at 100%.
15+
"""
16+
super()._compute_analytic_distribution()
17+
for line in self:
18+
if not line.vehicle_id:
19+
continue
20+
account = line.vehicle_id.vehicle_category_id.analytic_account_id
21+
if not account:
22+
continue
23+
24+
distribution = line.analytic_distribution or {}
25+
account_key = str(account.id)
26+
if account_key not in distribution:
27+
distribution[account_key] = 100
28+
line.analytic_distribution = distribution
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2026 - Arnaud LAYEC <arnaud.layec@akretion.com>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
class FleetVehicleCategory(models.Model):
7+
_inherit = ["fleet.vehicle.category"]
8+
9+
company_id = fields.Many2one(
10+
comodel_name="res.company",
11+
readonly=True,
12+
default=lambda self: self.env.company.root_id,
13+
)
14+
analytic_account_id = fields.Many2one(
15+
comodel_name="account.analytic.account",
16+
string="Analytic Account",
17+
check_company=True,
18+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Arnaud Layec \<<arnaud.layec@akretion.com>\>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module adds analytic account definition per vehicle category.
2+
It define this analytic account on the analytic distribution of account move line.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 18.0.1.0.0 (2026-02-27)
2+
3+
- \[NEW\] Module creation

0 commit comments

Comments
 (0)