From fb8f2c99cc9600e90f18206a2ede92cc24c99d55 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 4 May 2016 10:51:27 +0200 Subject: [PATCH] [IMP] hr_holidays: handle UoM in resource calendar In a company, there might be several contract types, e.g.: - 38 Hours/Week, 5 Days/Week - 45 Hours/Week, 5 Days/Week - 24 Hours/Week, 2 Days/Week (work on week-end only) Therefore, it is necessary to be able to define the average number of hours per day on a resource calendar. --- addons/hr_holidays/hr_holidays.py | 18 ++++++++++- addons/hr_holidays/hr_holidays_view.xml | 12 ++++++++ addons/hr_holidays/i18n/hr_holidays.pot | 41 ++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index fdf21b96707..c5298c73748 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -293,7 +293,7 @@ class hr_holidays(osv.osv): resource = resource_obj.browse(cr, uid, resource_ids, context=context) if resource and resource.calendar_id: hours = resource.calendar_id.get_working_hours(from_dt, to_dt, resource_id=resource.id, compute_leaves=True) - uom_hour = model_data_obj.xmlid_to_object(cr, uid, 'product.product_uom_hour') + uom_hour = resource.calendar_id.uom_id uom_day = model_data_obj.xmlid_to_object(cr, uid, 'product.product_uom_day') if uom_hour and uom_day: return uom_obj._compute_qty_obj(cr, uid, uom_hour, hours[0], uom_day, context=context) @@ -548,6 +548,22 @@ class hr_holidays(osv.osv): return res +class resource_calendar(osv.osv): + _inherit = "resource.calendar" + _columns = { + 'uom_id': fields.many2one("product.uom", "Hours per Day", required=True, + help="""Average hours of work per day. + It is used in an employee leave request to compute the number of days consumed based on the resource calendar. + It can be used to handle various contract types, e.g.: + - 38 Hours/Week, 5 Days/Week: 1 Day = 7.6 Hours + - 45 Hours/Week, 5 Days/Week: 1 Day = 9.0 Hours"""), + } + + _defaults = { + 'uom_id': lambda self, cr, uid, c: self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'product.product_uom_hour') + } + + class resource_calendar_leaves(osv.osv): _inherit = "resource.calendar.leaves" _description = "Leave Detail" diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index 68b53cdb74a..05da2b2057a 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -552,6 +552,18 @@ + + + resource.calendar.form.inherit + resource.calendar + + + + + + + + resource.calendar.leaves.form.inherit diff --git a/addons/hr_holidays/i18n/hr_holidays.pot b/addons/hr_holidays/i18n/hr_holidays.pot index f1b2d682777..de22029304f 100644 --- a/addons/hr_holidays/i18n/hr_holidays.pot +++ b/addons/hr_holidays/i18n/hr_holidays.pot @@ -92,6 +92,11 @@ msgstr "" msgid "Absence by Today" msgstr "" +#. module: hr_holidays +#: model:ir.ui.view,arch_db:hr_holidays.hr_department_view_kanban +msgid "Absent Employee(s), Whose leaves request are either confirmed or validated on today" +msgstr "" + #. module: hr_holidays #: model:ir.actions.act_window,name:hr_holidays.hr_employee_action_from_department msgid "Absent Employees" @@ -180,6 +185,11 @@ msgstr "" msgid "Allocation to Approve" msgstr "" +#. module: hr_holidays +#: model:ir.ui.view,arch_db:hr_holidays.view_hr_holidays_filter +msgid "Allocations" +msgstr "" + #. module: hr_holidays #: model:ir.model.fields,field_description:hr_holidays.field_hr_holidays_status_limit msgid "Allow to Override Limit" @@ -225,6 +235,15 @@ msgstr "" msgid "Assign Leaves" msgstr "" +#. module: hr_holidays +#: model:ir.model.fields,help:hr_holidays.field_resource_calendar_uom_id +msgid "Average hours of work per day.\n" +" It is used in an employee leave request to compute the number of days consumed based on the resource calendar.\n" +" It can be used to handle various contract types, e.g.:\n" +" - 38 Hours/Week, 5 Days/Week: 1 Day = 7.6 Hours\n" +" - 45 Hours/Week, 5 Days/Week: 1 Day = 9.0 Hours" +msgstr "" + #. module: hr_holidays #: selection:hr.holidays.status,color_name:0 msgid "Black" @@ -357,6 +376,11 @@ msgstr "" msgid "Created on" msgstr "" +#. module: hr_holidays +#: model:ir.ui.view,arch_db:hr_holidays.view_hr_holidays_filter +msgid "Current" +msgstr "" + #. module: hr_holidays #: model:ir.model.fields,field_description:hr_holidays.field_hr_employee_current_leave_state msgid "Current Leave Status" @@ -518,6 +542,16 @@ msgstr "" msgid "HR Leaves Summary Report By Employee" msgstr "" +#. module: hr_holidays +#: model:ir.model.fields,field_description:hr_holidays.field_resource_calendar_uom_id +msgid "Hours per Day" +msgstr "" + +#. module: hr_holidays +#: model:ir.model,name:hr_holidays.model_hr_department +msgid "Hr Department" +msgstr "" + #. module: hr_holidays #: model:ir.model.fields,field_description:hr_holidays.field_hr_holidays_id #: model:ir.model.fields,field_description:hr_holidays.field_hr_holidays_remaining_leaves_user_id @@ -667,6 +701,7 @@ msgstr "" #: model:ir.ui.menu,name:hr_holidays.menu_open_department_leave_approve #: model:ir.ui.view,arch_db:hr_holidays.hr_department_view_kanban #: model:ir.ui.view,arch_db:hr_holidays.view_employee_form_leave_inherit +#: model:ir.ui.view,arch_db:hr_holidays.view_hr_holidays_filter msgid "Leaves" msgstr "" @@ -1046,6 +1081,11 @@ msgstr "" msgid "Reset to Draft" msgstr "" +#. module: hr_holidays +#: model:ir.model,name:hr_holidays.model_resource_calendar +msgid "Resource Calendar" +msgstr "" + #. module: hr_holidays #: model:ir.ui.view,arch_db:hr_holidays.view_hr_holidays_filter msgid "Search Leave" @@ -1347,4 +1387,3 @@ msgstr "" #: model:ir.ui.view,arch_db:hr_holidays.report_holidayssummary msgid "to" msgstr "" -