From 75ef4686ffd7b0124fb747a43c63fe8292aa037e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Mon, 7 Jan 2019 08:06:45 +0000 Subject: [PATCH] [IMP] hr_payroll: Add notion of full time/part time on resource calendar Purpose ======= In order to be able to manage payroll, we need to know if a resource calendar is a full time or a part time. For instance, in belgium, 23h a week is a full time for a teacher but in cp 200 it is 38h. In belgium every employee can take a parental leave in part time but he cannot take it in part time if they are not full time. Having a field indicating if the contract is full time or not is useful for computing salary rules. Specification ============= On the calendar model - Display a computed field with the number of hours in the calendar - Display a field with the required number of hours to be full time - Display a computed checkbox, ticked if full time or not On the contract model - Add a related on these fields, to ease the access on the salary rules computation. closes odoo/odoo#30034 --- addons/hr_payroll/data/hr_payroll_data.xml | 13 +++++++++++++ addons/hr_payroll/models/hr_contract.py | 4 ++++ addons/hr_payroll/models/resource.py | 19 +++++++++++++++++-- addons/hr_payroll/views/resource_views.xml | 21 +++++++++++++++++++-- addons/resource/models/resource.py | 2 +- addons/resource/views/resource_views.xml | 12 +++++++----- 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/addons/hr_payroll/data/hr_payroll_data.xml b/addons/hr_payroll/data/hr_payroll_data.xml index 87d00a5c6fc..72c2b198699 100644 --- a/addons/hr_payroll/data/hr_payroll_data.xml +++ b/addons/hr_payroll/data/hr_payroll_data.xml @@ -1,6 +1,19 @@ + + + 40 + + + + 35 + + + + 38 + + Employees diff --git a/addons/hr_payroll/models/hr_contract.py b/addons/hr_payroll/models/hr_contract.py index 92131667af3..3fb14c8988f 100644 --- a/addons/hr_payroll/models/hr_contract.py +++ b/addons/hr_payroll/models/hr_contract.py @@ -21,6 +21,10 @@ class HrContract(models.Model): help="Defines the frequency of the wage payment.") resource_calendar_id = fields.Many2one(required=True, help="Employee's working schedule.") + hours_per_week = fields.Float(related='resource_calendar_id.hours_per_week') + full_time_required_hours = fields.Float(related='resource_calendar_id.full_time_required_hours') + is_fulltime = fields.Boolean(related='resource_calendar_id.is_fulltime') + @api.multi def get_all_structures(self): """ diff --git a/addons/hr_payroll/models/resource.py b/addons/hr_payroll/models/resource.py index 440820f2017..6102a56d414 100644 --- a/addons/hr_payroll/models/resource.py +++ b/addons/hr_payroll/models/resource.py @@ -1,12 +1,16 @@ # -*- coding:utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import models, fields +from odoo import models, fields, api from odoo.osv.expression import AND, OR - +from odoo.tools import float_compare class ResourceCalendar(models.Model): _inherit = 'resource.calendar' + hours_per_week = fields.Float(compute="_compute_hours_per_week", string="Hours per Week") + full_time_required_hours = fields.Float(string="Fulltime Hours", help="Number of hours to work to be considered as fulltime.") + is_fulltime = fields.Boolean(compute='_compute_is_fulltime', string="Is Full Time") + # UI fields normal_attendance_ids = fields.One2many( 'resource.calendar.attendance', 'calendar_id', 'Normal working Time', @@ -16,6 +20,15 @@ class ResourceCalendar(models.Model): 'resource.calendar.attendance', 'calendar_id', 'Employees working Time', domain=[('resource_id', '!=', False)]) + @api.depends('normal_attendance_ids.hour_from', 'normal_attendance_ids.hour_to') + def _compute_hours_per_week(self): + for calendar in self: + calendar.hours_per_week = sum((attendance.hour_to - attendance.hour_from) for attendance in calendar.normal_attendance_ids) + + def _compute_is_fulltime(self): + for calendar in self: + calendar.is_fulltime = not float_compare(calendar.full_time_required_hours, calendar.hours_per_week, 3) + class ResourceCalendarAttendance(models.Model): _inherit = 'resource.calendar.attendance' @@ -25,8 +38,10 @@ class ResourceCalendarAttendance(models.Model): benefit_type_id = fields.Many2one('hr.benefit.type', 'Benefit Type', default=_default_benefit_type_id) + class ResourceCalendarLeave(models.Model): _inherit = 'resource.calendar.leaves' + benefit_type_id = fields.Many2one('hr.benefit.type', 'Benefit Type') diff --git a/addons/hr_payroll/views/resource_views.xml b/addons/hr_payroll/views/resource_views.xml index 5fe67b67128..c4c29dd78e0 100644 --- a/addons/hr_payroll/views/resource_views.xml +++ b/addons/hr_payroll/views/resource_views.xml @@ -7,21 +7,38 @@ resource.calendar + + + + + + - + + - diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py index 0caafc4e88c..54575a6c354 100644 --- a/addons/resource/models/resource.py +++ b/addons/resource/models/resource.py @@ -179,7 +179,7 @@ class ResourceCalendar(models.Model): 'resource.calendar.leaves', 'calendar_id', 'Global Leaves', domain=[('resource_id', '=', False)] ) - hours_per_day = fields.Float("Average hour per day", default=HOURS_PER_DAY, + hours_per_day = fields.Float("Average Hour per Day", default=HOURS_PER_DAY, help="Average hours per day a resource is supposed to work with this calendar.") tz = fields.Selection( _tz_get, string='Timezone', required=True, diff --git a/addons/resource/views/resource_views.xml b/addons/resource/views/resource_views.xml index 8e1a5ecb18d..ded427f2901 100644 --- a/addons/resource/views/resource_views.xml +++ b/addons/resource/views/resource_views.xml @@ -189,11 +189,11 @@ + - @@ -241,7 +241,7 @@