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 @@

Timesheet Apps

+
+
+
+
diff --git a/addons/project/models/__init__.py b/addons/project/models/__init__.py index 081d29b8d4e..5a94820d26e 100644 --- a/addons/project/models/__init__.py +++ b/addons/project/models/__init__.py @@ -3,7 +3,6 @@ from . import project from . import res_config_settings -from . import res_company from . import res_partner from . import res_users from . import digest diff --git a/addons/project/models/project.py b/addons/project/models/project.py index c5c5370d78a..bddeff7d218 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -2,7 +2,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import timedelta -from lxml import etree from odoo import api, fields, models, tools, SUPERUSER_ID, _ from odoo.exceptions import UserError, AccessError, ValidationError @@ -620,47 +619,6 @@ class Task(models.Model): if not task._check_recursion(): raise ValidationError(_('Error! You cannot create recursive hierarchy of task(s).')) - # Override view according to the company definition - @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 - @api.model def get_empty_list_help(self, help): tname = _("task") diff --git a/addons/project/models/res_config_settings.py b/addons/project/models/res_config_settings.py index bf8f890d968..c6815aaae90 100644 --- a/addons/project/models/res_config_settings.py +++ b/addons/project/models/res_config_settings.py @@ -10,8 +10,3 @@ class ResConfigSettings(models.TransientModel): module_project_forecast = fields.Boolean(string="Forecasts") group_subtask_project = fields.Boolean("Sub-tasks", implied_group="project.group_subtask_project") group_project_rating = fields.Boolean("Use Rating on Project", implied_group='project.group_project_rating') - 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/project/views/res_config_settings_views.xml b/addons/project/views/res_config_settings_views.xml index da472468e96..d052efeac6f 100644 --- a/addons/project/views/res_config_settings_views.xml +++ b/addons/project/views/res_config_settings_views.xml @@ -50,7 +50,7 @@

Time Management

-
+