From f9b7079b95c5abcb833ecd6343a082a6f47024b3 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 3 May 2018 10:49:38 +0200 Subject: [PATCH] [IMP] l10n_be_hr_payroll_fleet: Add company car information on employee contracts It makes sense to display this piece of information on the employee contract. It allows HR users to see users information about the employee company car without having access to the whole fleet module. --- .../models/hr_contract.py | 32 +++++++++++++++++++ .../views/hr_contract_views.xml | 13 +++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/addons/l10n_be_hr_payroll_fleet/models/hr_contract.py b/addons/l10n_be_hr_payroll_fleet/models/hr_contract.py index 012cc24ce56..70fb251436f 100644 --- a/addons/l10n_be_hr_payroll_fleet/models/hr_contract.py +++ b/addons/l10n_be_hr_payroll_fleet/models/hr_contract.py @@ -18,6 +18,15 @@ class HrContract(models.Model): new_car = fields.Boolean('Request a new car') new_car_model_id = fields.Many2one('fleet.vehicle.model', string="Model", domain=lambda self: self._get_possible_model_domain()) max_unused_cars = fields.Integer(compute='_compute_max_unused_cars') + acquisition_date = fields.Date(related='car_id.acquisition_date') + car_value = fields.Float(related="car_id.car_value") + fuel_type = fields.Selection(related="car_id.fuel_type") + co2 = fields.Float(related="car_id.co2") + driver_id = fields.Many2one('res.partner', related="car_id.driver_id") + car_open_contracts_count = fields.Integer(compute='_compute_car_open_contracts_count') + recurring_cost_amount_depreciated = fields.Float( + compute='_compute_recurring_cost_amount_depreciated', + inverse="_inverse_recurring_cost_amount_depreciated") @api.depends('car_id', 'new_car', 'new_car_model_id', 'car_id.total_depreciated_cost', 'car_id.atn', 'new_car_model_id.default_atn', 'new_car_model_id.default_total_depreciated_cost', @@ -32,6 +41,29 @@ class HrContract(models.Model): contract.car_atn = contract.new_car_model_id.default_atn contract.company_car_total_depreciated_cost = contract.new_car_model_id.default_total_depreciated_cost + @api.depends('car_id.log_contracts.state') + def _compute_car_open_contracts_count(self): + for contract in self: + contract.car_open_contracts_count = len(contract.car_id.log_contracts.filtered( + lambda c: c.state == 'open').ids) + + @api.depends('car_open_contracts_count', 'car_id.log_contracts.recurring_cost_amount_depreciated') + def _compute_recurring_cost_amount_depreciated(self): + for contract in self: + if contract.car_open_contracts_count == 1: + contract.recurring_cost_amount_depreciated = contract.car_id.log_contracts.filtered( + lambda c: c.state == 'open' + ).recurring_cost_amount_depreciated + else: + contract.recurring_cost_amount_depreciated = 0.0 + + def _inverse_recurring_cost_amount_depreciated(self): + for contract in self: + if contract.car_open_contracts_count == 1: + contract.car_id.log_contracts.filtered( + lambda c: c.state == 'open' + ).recurring_cost_amount_depreciated = contract.recurring_cost_amount_depreciated + @api.depends('name') def _compute_available_cars_amount(self): for contract in self: diff --git a/addons/l10n_be_hr_payroll_fleet/views/hr_contract_views.xml b/addons/l10n_be_hr_payroll_fleet/views/hr_contract_views.xml index 184772fc1e5..1701a79b3f6 100644 --- a/addons/l10n_be_hr_payroll_fleet/views/hr_contract_views.xml +++ b/addons/l10n_be_hr_payroll_fleet/views/hr_contract_views.xml @@ -18,7 +18,18 @@ - + + + + + + + + + + + +