diff --git a/addons/fleet/__init__.py b/addons/fleet/__init__.py index 8484f21c236ee279e05a9a042ad341920d129692..2609681a9385ba488511c320e9b8f873c55e1b39 100644 --- a/addons/fleet/__init__.py +++ b/addons/fleet/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. + from . import models from . import report diff --git a/addons/fleet/models/fleet_vehicle.py b/addons/fleet/models/fleet_vehicle.py index c40ead0361753f498d2be0b201c675849f68d73d..eab2be4834ff7b66b4be1b8f48473be0c4b19152 100644 --- a/addons/fleet/models/fleet_vehicle.py +++ b/addons/fleet/models/fleet_vehicle.py @@ -158,6 +158,10 @@ class FleetVehicle(models.Model): record.contract_renewal_total = total - 1 # we remove 1 from the real total for display purposes record.contract_renewal_name = name + def _get_analytic_name(self): + # This function is used in fleet_account and is overrided in l10n_be_hr_payroll_fleet + return self.license_plate or _('No plate') + def _search_contract_renewal_due_soon(self, operator, value): params = self.env['ir.config_parameter'].sudo() delay_alert_contract = int(params.get_param('hr_fleet.delay_alert_contract', default=30)) diff --git a/addons/fleet/models/res_config_settings.py b/addons/fleet/models/res_config_settings.py index 6e750044e395a3cdc02c40ee85dde5794276fa20..59b725d877b4c494397a0f5fefcc78b328e7a83d 100644 --- a/addons/fleet/models/res_config_settings.py +++ b/addons/fleet/models/res_config_settings.py @@ -8,3 +8,4 @@ class ResConfigSettings(models.TransientModel): _inherit = ['res.config.settings'] delay_alert_contract = fields.Integer(string='Delay alert contract outdated', default=30, config_parameter='hr_fleet.delay_alert_contract') + module_fleet_account = fields.Boolean(string="Analytic Accounting Fleet") diff --git a/addons/fleet/views/fleet_vehicle_views.xml b/addons/fleet/views/fleet_vehicle_views.xml index b685a12ebf8c6613397dfda9c60658c3124b2569..25c25b2932dcad2d7e05b79a2c8b510c1e847e1b 100644 --- a/addons/fleet/views/fleet_vehicle_views.xml +++ b/addons/fleet/views/fleet_vehicle_views.xml @@ -87,7 +87,7 @@ <field name="residual_value" widget="monetary"/> <field name="company_id" groups="base.group_multi_company"/> </group> - <group string="Contract"> + <group string="Contract" name="contract"> <field name="manager_id"/> <field name="first_contract_date"/> </group> diff --git a/addons/fleet/views/res_config_settings_views.xml b/addons/fleet/views/res_config_settings_views.xml index 05c4adf4d425cf01e1af452f00a1b81de9d081d0..eddce7ccd0d9da1dc4ea55bf7a3e1db796a17547 100644 --- a/addons/fleet/views/res_config_settings_views.xml +++ b/addons/fleet/views/res_config_settings_views.xml @@ -22,6 +22,17 @@ </div> </div> </div> + <div class="col-12 col-lg-6 o_setting_box"> + <div class="o_setting_left_pane"> + <field name="module_fleet_account" widget="upgrade_boolean"/> + </div> + <div class="o_setting_right_pane"> + <label for="module_fleet_account" string="Analytic Accounting"/> + <div class="text-muted"> + Manage analytic account for vehicle + </div> + </div> + </div> </div> </div> </xpath> diff --git a/addons/fleet_account/__init__.py b/addons/fleet_account/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..dc5e6b693d19dcacd224b7ab27b26f75e66cb7b2 --- /dev/null +++ b/addons/fleet_account/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/fleet_account/__manifest__.py b/addons/fleet_account/__manifest__.py new file mode 100644 index 0000000000000000000000000000000000000000..2508edd96b5c1f2ad9132ef86ed32954e4737777 --- /dev/null +++ b/addons/fleet_account/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +{ + 'name': 'Fleet - Account', + 'version': '1.0', + 'sequence': 165, + 'category': 'Human Resources/Fleet', + 'website': 'https://www.odoo.com/page/fleet', + 'summary': 'Manage your accounting for fleet', + 'depends': [ + 'fleet', + 'account', + ], + 'data': [ + 'views/fleet_views.xml', + ], + 'application': False, +} diff --git a/addons/fleet_account/models/__init__.py b/addons/fleet_account/models/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..7891f2c7108e9059a1d8921ea05c68e5752a84b9 --- /dev/null +++ b/addons/fleet_account/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import fleet_vehicle diff --git a/addons/fleet_account/models/fleet_vehicle.py b/addons/fleet_account/models/fleet_vehicle.py new file mode 100644 index 0000000000000000000000000000000000000000..0f6be4e50b54bf5530e7041dd6151b8cf783e70e --- /dev/null +++ b/addons/fleet_account/models/fleet_vehicle.py @@ -0,0 +1,22 @@ +# -*- 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}) diff --git a/addons/fleet_account/views/fleet_views.xml b/addons/fleet_account/views/fleet_views.xml new file mode 100644 index 0000000000000000000000000000000000000000..25463950d9cf77921c5525a91d638681b28820a1 --- /dev/null +++ b/addons/fleet_account/views/fleet_views.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + + <record id="fleet_vehicle_view_form_inherit_account" model="ir.ui.view"> + <field name="name">fleet.vehicle.form.inherit.account</field> + <field name="model">fleet.vehicle</field> + <field name="inherit_id" ref="fleet.fleet_vehicle_view_form"/> + <field name="arch" type="xml"> + <xpath expr="//group[@name='contract']" position="after"> + <group string="Accounting"> + <label for="analytic_account_id" string="Analytic Account"/> + <div> + <field name="analytic_account_id" class="oe_inline"/> + <button string="Generate Analytic Account" name="action_generate_analytic_account" type="object" class="btn-link oe_inline" attrs="{'invisible': [('analytic_account_id', '!=', False)]}"/> + </div> + </group> + </xpath> + </field> + </record> + +</odoo> diff --git a/addons/hr_fleet/models/__init__.py b/addons/hr_fleet/models/__init__.py index 71ad0b812ff3d3937fa223de4d7db2ee7d54ecf4..8e8d38df02f86572304a39c4507606a2f6cf109c 100644 --- a/addons/hr_fleet/models/__init__.py +++ b/addons/hr_fleet/models/__init__.py @@ -4,3 +4,4 @@ from . import employee from . import res_users from . import fleet_vehicle_assignation_log +from . import fleet_vehicle diff --git a/addons/hr_fleet/models/employee.py b/addons/hr_fleet/models/employee.py index 1d964ad35d342e641b6197ab34350dcee9abe085..68214db160e219d41942fadf1028cf427bfbe3ab 100644 --- a/addons/hr_fleet/models/employee.py +++ b/addons/hr_fleet/models/employee.py @@ -8,6 +8,7 @@ class Employee(models.Model): _inherit = 'hr.employee' employee_cars_count = fields.Integer(compute="_compute_employee_cars_count", string="Cars", groups="fleet.fleet_group_manager") + mobility_card = fields.Char(groups="fleet.fleet_group_user") def action_open_employee_cars(self): self.ensure_one() diff --git a/addons/hr_fleet/models/fleet_vehicle.py b/addons/hr_fleet/models/fleet_vehicle.py new file mode 100644 index 0000000000000000000000000000000000000000..9774d23b499eda7ed58c862e1984a52e329bd66d --- /dev/null +++ b/addons/hr_fleet/models/fleet_vehicle.py @@ -0,0 +1,15 @@ +# -*- coding:utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class FleetVehicle(models.Model): + _inherit = 'fleet.vehicle' + + mobility_card = fields.Char(compute='_compute_mobility_card', store=True) + + @api.depends('driver_id') + def _compute_mobility_card(self): + for vehicle in self: + vehicle.mobility_card = vehicle.driver_id.user_ids[:1].employee_id.mobility_card diff --git a/addons/hr_fleet/views/employee_views.xml b/addons/hr_fleet/views/employee_views.xml index 66d09498fe9712c113d96eb927e65b08fc83076b..b3637e2c8ae6a55aee92e987cd91e97ad18f5369 100644 --- a/addons/hr_fleet/views/employee_views.xml +++ b/addons/hr_fleet/views/employee_views.xml @@ -19,6 +19,11 @@ <field name="employee_cars_count" widget="statinfo" /> </button> </div> + <xpath expr="//group[@name='identification_group']" position="after"> + <group string="Fleet"> + <field name="mobility_card"/> + </group> + </xpath> </field> </record> diff --git a/addons/hr_fleet/views/fleet_vehicle_views.xml b/addons/hr_fleet/views/fleet_vehicle_views.xml index d1f9b41a7480eaa98ad5d9f726d62a2d4a34ff4a..26c7ef13bc5e570cb146439652d64f65d762866e 100644 --- a/addons/hr_fleet/views/fleet_vehicle_views.xml +++ b/addons/hr_fleet/views/fleet_vehicle_views.xml @@ -11,4 +11,26 @@ </xpath> </field> </record> + + <record id="fleet_vehicle_view_form_inherit_hr" model="ir.ui.view"> + <field name="name">fleet.vehicle.form.inherit.hr</field> + <field name="model">fleet.vehicle</field> + <field name="inherit_id" ref="fleet.fleet_vehicle_view_form"/> + <field name="arch" type="xml"> + <xpath expr="//field[@name='driver_id']" position="after"> + <field name="mobility_card" readonly="1"/> + </xpath> + </field> + </record> + + <record id="fleet_vehicle_view_search_inherit_hr" model="ir.ui.view"> + <field name="name">fleet.vehicle.search.inherit.hr</field> + <field name="model">fleet.vehicle</field> + <field name="inherit_id" ref="fleet.fleet_vehicle_view_search"/> + <field name="arch" type="xml"> + <xpath expr="//field[@name='driver_id']" position="after"> + <field name="mobility_card"/> + </xpath> + </field> + </record> </odoo>