diff --git a/hr_holidays_partial/__init__.py b/hr_holidays_partial/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/hr_holidays_partial/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_holidays_partial/__manifest__.py b/hr_holidays_partial/__manifest__.py new file mode 100644 index 00000000..5449da9e --- /dev/null +++ b/hr_holidays_partial/__manifest__.py @@ -0,0 +1,18 @@ +{ + 'name': 'HR Holidays Partial', + 'author': 'Hibou Corp. ', + 'version': '11.0.0.0.0', + 'category': 'Human Resources', + 'sequence': 95, + 'summary': 'Partial day leave requests displau hours', + 'description': """ +Create and display leave requests in hours for partial days. + """, + 'website': 'https://hibou.io/', + 'depends': ['hr_holidays'], + 'data': [ + 'views/hr_holidays_views.xml', + ], + 'installable': True, + 'application': False, +} diff --git a/hr_holidays_partial/models/__init__.py b/hr_holidays_partial/models/__init__.py new file mode 100644 index 00000000..8730acb1 --- /dev/null +++ b/hr_holidays_partial/models/__init__.py @@ -0,0 +1 @@ +from . import hr_holiday diff --git a/hr_holidays_partial/models/hr_holiday.py b/hr_holidays_partial/models/hr_holiday.py new file mode 100644 index 00000000..8350212d --- /dev/null +++ b/hr_holidays_partial/models/hr_holiday.py @@ -0,0 +1,30 @@ +from odoo import api, fields, models +from math import ceil +from odoo.addons.hr_holidays.models.hr_holidays import HOURS_PER_DAY + + +class HRHoliday(models.Model): + _inherit = 'hr.holidays' + + days_in_hours = fields.Float(string="Hours", compute='_get_days_in_hours') + + def _get_number_of_days(self, date_from, date_to, employee_id): + from_dt = fields.Datetime.from_string(date_from) + to_dt = fields.Datetime.from_string(date_to) + + if employee_id: + employee = self.env['hr.employee'].browse(employee_id) + num_days = employee.get_work_days_count(from_dt, to_dt) + if num_days == 0: + time_delta = to_dt - from_dt + hours = (time_delta.seconds / 3600) + return hours / HOURS_PER_DAY + else: + return employee.get_work_days_count(from_dt, to_dt) + + time_delta = to_dt - from_dt + return ceil(time_delta.days + float(time_delta.seconds) / 86400) + + @api.depends('number_of_days_temp') + def _get_days_in_hours(self): + self.days_in_hours = self.number_of_days_temp * 8 diff --git a/hr_holidays_partial/views/hr_holidays_views.xml b/hr_holidays_partial/views/hr_holidays_views.xml new file mode 100644 index 00000000..30a93a33 --- /dev/null +++ b/hr_holidays_partial/views/hr_holidays_views.xml @@ -0,0 +1,14 @@ + + + + hr.holidays.edit.holiday.new.inherit + hr.holidays + 20 + + + + + + + + \ No newline at end of file