diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_fleet/wizard | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/hr_fleet/wizard')
| -rw-r--r-- | addons/hr_fleet/wizard/__init__.py | 4 | ||||
| -rw-r--r-- | addons/hr_fleet/wizard/hr_departure_wizard.py | 27 | ||||
| -rw-r--r-- | addons/hr_fleet/wizard/hr_departure_wizard_views.xml | 13 |
3 files changed, 44 insertions, 0 deletions
diff --git a/addons/hr_fleet/wizard/__init__.py b/addons/hr_fleet/wizard/__init__.py new file mode 100644 index 00000000..ea671ff9 --- /dev/null +++ b/addons/hr_fleet/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import hr_departure_wizard diff --git a/addons/hr_fleet/wizard/hr_departure_wizard.py b/addons/hr_fleet/wizard/hr_departure_wizard.py new file mode 100644 index 00000000..73311599 --- /dev/null +++ b/addons/hr_fleet/wizard/hr_departure_wizard.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class HrDepartureWizard(models.TransientModel): + _inherit = 'hr.departure.wizard' + + release_campany_car = fields.Boolean("Release Company Car", default=True) + + def action_register_departure(self): + super(HrDepartureWizard, self).action_register_departure() + if self.release_campany_car: + self._free_campany_car() + + def _free_campany_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}) + cars = self.env['fleet.vehicle'].search([('driver_id', 'in', drivers.ids)]) + cars.write({'driver_id': False}) diff --git a/addons/hr_fleet/wizard/hr_departure_wizard_views.xml b/addons/hr_fleet/wizard/hr_departure_wizard_views.xml new file mode 100644 index 00000000..72c38a78 --- /dev/null +++ b/addons/hr_fleet/wizard/hr_departure_wizard_views.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record id="hr_departure_wizard_view_form" model="ir.ui.view"> + <field name="name">hr.departure.wizard.view.form.extend2</field> + <field name="model">hr.departure.wizard</field> + <field name="inherit_id" ref="hr.hr_departure_wizard_view_form" /> + <field name="arch" type="xml"> + <xpath expr="//field[@name='archive_private_address']" position="after"> + <field name="release_campany_car"/> + </xpath> + </field> + </record> +</odoo> |
