Skip to content
Snippets Groups Projects
Commit 0655e3c1 authored by Kevin Baptiste's avatar Kevin Baptiste
Browse files

[FIX] hr_holidays_attendance: delete overtime on leave cancelation


When a leave was canceled, the overtime record linked to it was not
deleted resulting in a wrong count of available overtimes.

Whatever the config of the time off type used to deduct extra-hours, its
total should be displayed in "hours" instead of "days" on the dashboard.

task-3097259

closes odoo/odoo#107712

Signed-off-by: default avatarKevin Baptiste <kba@odoo.com>
parent 77412276
No related branches found
No related tags found
No related merge requests found
......@@ -105,3 +105,7 @@ class HRLeave(models.Model):
# TODO master change to ondelete
self.sudo().overtime_id.unlink()
return super().unlink()
def _force_cancel(self, *args, **kwargs):
super()._force_cancel(*args, **kwargs)
self.sudo().overtime_id.unlink()
......@@ -8,6 +8,9 @@
<xpath expr="//t[@t-set='show_popover']" position="replace">
<t t-set="show_popover" t-value="!props.data['overtime_deductible']"/>
</xpath>
<xpath expr="//t[@name='duration_unit']" position="attributes">
<attribute name="t-if">props.data.request_unit == 'hour' || props.data['overtime_deductible']</attribute>
</xpath>
<xpath expr="//t[@name='duration_type']" position="attributes">
<attribute name="t-if">props.requires_allocation || props.data['overtime_deductible']</attribute>
</xpath>
......
......@@ -6,6 +6,8 @@ from odoo.tests import new_test_user
from odoo.tests.common import TransactionCase, tagged
from odoo.exceptions import AccessError, ValidationError
from freezegun import freeze_time
import time
@tagged('post_install', '-at_install', 'holidays_attendance')
......@@ -226,3 +228,26 @@ class TestHolidaysOvertime(TransactionCase):
alloc.number_of_days = 2
self.assertEqual(self.employee.total_overtime, 0)
@freeze_time('2022-1-1')
def test_leave_check_cancel(self):
self.new_attendance(check_in=datetime(2021, 1, 2, 8), check_out=datetime(2021, 1, 2, 16))
self.new_attendance(check_in=datetime(2021, 1, 3, 8), check_out=datetime(2021, 1, 3, 16))
self.assertEqual(self.employee.total_overtime, 16)
leave = self.env['hr.leave'].create({
'name': 'no overtime',
'employee_id': self.employee.id,
'holiday_status_id': self.leave_type_no_alloc.id,
'number_of_days': 1,
'date_from': datetime(2022, 1, 6),
'date_to': datetime(2022, 1, 6),
})
leave.with_user(self.user_manager).action_validate()
self.assertEqual(self.employee.total_overtime, 8)
self.assertTrue(leave.with_user(self.user).can_cancel)
self.env['hr.holidays.cancel.leave'].with_user(self.user).with_context(default_leave_id=leave.id) \
.new({'reason': 'Test remove holiday'}) \
.action_cancel_leave()
self.assertFalse(leave.overtime_id.exists())
......@@ -8,7 +8,21 @@
<field name="overtime_deductible" invisible="1" />
<field name="employee_overtime" invisible="1" />
<div attrs="{'invisible': ['|', '|', ('employee_id', '=', False), ('overtime_deductible', '=', False), ('employee_overtime', '&lt;=', 0)]}">
<field name="employee_overtime" nolabel="1" widget="float_time" class="text-success" /> Extra Hours Available
<field name="employee_overtime" nolabel="1" widget="float_time" class="text-success" style="width: 6rem;" /> Extra Hours Available
</div>
</xpath>
</field>
</record>
<record id="hr_leave_view_form_overtime" model="ir.ui.view">
<field name="model">hr.leave</field>
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form" />
<field name="arch" type="xml">
<xpath expr="(//div[@name='duration_display']/div)[last()]" position="after">
<field name="overtime_deductible" invisible="1" />
<field name="employee_overtime" invisible="1" />
<div attrs="{'invisible': ['|', '|', ('employee_id', '=', False), ('overtime_deductible', '=', False), ('employee_overtime', '&lt;=', 0)]}">
<field name="employee_overtime" nolabel="1" widget="float_time" class="text-success" style="max-width: 6rem;" /> Extra Hours Available
</div>
</xpath>
</field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment