mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-24 18:32:05 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -1,27 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class HrDepartureWizard(models.TransientModel):
|
||||
_inherit = 'hr.departure.wizard'
|
||||
|
||||
release_campany_car = fields.Boolean("Release Company Car", default=lambda self: self.env.user.user_has_groups('fleet.fleet_group_user'))
|
||||
release_campany_car = fields.Boolean("Release Company Car", default=lambda self: self.env.user.has_group('fleet.fleet_group_user'))
|
||||
|
||||
def action_register_departure(self):
|
||||
super(HrDepartureWizard, self).action_register_departure()
|
||||
action = super().action_register_departure()
|
||||
if self.release_campany_car:
|
||||
self._free_campany_car()
|
||||
self._free_company_car()
|
||||
return action
|
||||
|
||||
def _free_campany_car(self):
|
||||
def _free_company_car(self):
|
||||
"""Find all fleet.vehichle.assignation.log records that link to the employee, if there is no
|
||||
end date or end date > departure date, update the date. Also check fleet.vehicle to see if
|
||||
there is any record with its dirver_id to be the employee, set them to False."""
|
||||
drivers = self.employee_id.user_id.partner_id | self.employee_id.sudo().address_home_id
|
||||
assignations = self.env['fleet.vehicle.assignation.log'].search([('driver_id', 'in', drivers.ids)])
|
||||
for assignation in assignations:
|
||||
if self.departure_date and (not assignation.date_end or assignation.date_end > self.departure_date):
|
||||
assignation.write({'date_end': self.departure_date})
|
||||
there is any record with its driver_id to be the employee, set them to False."""
|
||||
drivers = self.employee_ids.user_id.partner_id | self.employee_ids.sudo().work_contact_id
|
||||
assignations = self.env['fleet.vehicle.assignation.log'].search([
|
||||
('driver_id', 'in', drivers.ids),
|
||||
'|',
|
||||
('date_end', '=', False),
|
||||
('date_end', '>', self.departure_date),
|
||||
])
|
||||
assignations.write({'date_end': self.departure_date})
|
||||
cars = self.env['fleet.vehicle'].search([('driver_id', 'in', drivers.ids)])
|
||||
cars.write({'driver_id': False, 'driver_employee_id': False})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue