diff --git a/addons/hr_timesheet/models/__init__.py b/addons/hr_timesheet/models/__init__.py index b8bfb2333b9..4b66a96b171 100644 --- a/addons/hr_timesheet/models/__init__.py +++ b/addons/hr_timesheet/models/__init__.py @@ -4,6 +4,7 @@ from . import analytic_account from . import hr from . import hr_timesheet +from . import res_company from . import res_config_settings from . import project from . import res_users diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 7976df1defb..ed555772fb3 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from lxml import etree + from odoo import models, fields, api, _ from odoo.exceptions import UserError, ValidationError @@ -151,3 +153,43 @@ class Task(models.Model): 'company_id': account_id.company_id.id, }) return result + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + # read uom as admin to avoid access rights issues, e.g. for portal/share users, + # this should be safe (no context passed to avoid side-effects) + obj_tm = self.env.user.company_id.project_time_mode_id + tm = obj_tm and obj_tm.name or 'Hours' + + res = super(Task, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + + # read uom as admin to avoid access rights issues, e.g. for portal/share users, + # this should be safe (no context passed to avoid side-effects) + obj_tm = self.env.user.company_id.project_time_mode_id + # using get_object to get translation value + uom_hour = self.env.ref('uom.product_uom_hour', False) + if not obj_tm or not uom_hour or obj_tm.id == uom_hour.id: + return res + + eview = etree.fromstring(res['arch']) + + # if the project_time_mode_id is not in hours (so in days), display it as a float field + def _check_rec(eview): + if eview.attrib.get('widget', '') == 'float_time': + eview.set('widget', 'float') + for child in eview: + _check_rec(child) + return True + + _check_rec(eview) + + res['arch'] = etree.tostring(eview, encoding='unicode') + + # replace reference of 'Hours' to 'Day(s)' + for f in res['fields']: + # TODO this NOT work in different language than english + # the field 'Initially Planned Hours' should be replaced by 'Initially Planned Days' + # but string 'Initially Planned Days' is not available in translation + if 'Hours' in res['fields'][f]['string']: + res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours', obj_tm.name) + return res diff --git a/addons/project/models/res_company.py b/addons/hr_timesheet/models/res_company.py similarity index 100% rename from addons/project/models/res_company.py rename to addons/hr_timesheet/models/res_company.py diff --git a/addons/hr_timesheet/models/res_config_settings.py b/addons/hr_timesheet/models/res_config_settings.py index 7200bc5c21f..164b23b4f71 100644 --- a/addons/hr_timesheet/models/res_config_settings.py +++ b/addons/hr_timesheet/models/res_config_settings.py @@ -9,3 +9,8 @@ class ResConfigSettings(models.TransientModel): module_project_timesheet_synchro = fields.Boolean("Awesome Timesheet") module_project_timesheet_holidays = fields.Boolean("Leaves") + project_time_mode_id = fields.Many2one( + 'uom.uom', related='company_id.project_time_mode_id', string='Project Time Unit', + help="This will set the unit of measure used in projects and tasks.\n" + "If you use the timesheet linked to projects, don't " + "forget to setup the right unit of measure in your employees.") diff --git a/addons/hr_timesheet/views/res_config_settings_views.xml b/addons/hr_timesheet/views/res_config_settings_views.xml index 19d21fac97c..39f98a5374d 100644 --- a/addons/hr_timesheet/views/res_config_settings_views.xml +++ b/addons/hr_timesheet/views/res_config_settings_views.xml @@ -13,6 +13,17 @@