Files
odoo_source/addons/fleet_account/models/fleet_vehicle.py
T
jbm-odoo df44538a8b [IMP] fleet: Add analytic account and mobility card
Create analytic account from fleet (and link it to vehicle) based
on the plate and the fiscal deduction rate (if l10n_hr_payroll_fleet
is installed).

Add on employee a Mobility Card number. This number is set on vehicle
when we put a partner linked to employee on a vehicle.

taskID: 2127641
2019-11-28 10:39:49 +00:00

23 lines
1022 B
Python

# -*- coding:utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
from odoo.exceptions import AccessError
class FleetVehicle(models.Model):
_inherit = 'fleet.vehicle'
analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', copy=False, ondelete='set null',
check_company=True, help="Analytic account to which this vehicle is linked for financial management.")
def action_generate_analytic_account(self):
if not self.env.user.has_group('fleet.fleet_group_user'):
raise AccessError(_("Sorry, you must be at least a fleet user to make this action."))
for vehicle in self:
analytic_account = self.env['account.analytic.account'].sudo().create([{
'name': self._get_analytic_name(),
'company_id': self.company_id.id or self.env.company.id,
}])
vehicle.write({'analytic_account_id': analytic_account.id})