summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjem-odoo <jem@openerp.com>2018-04-09 16:46:57 +0200
committerjem-odoo <jem@openerp.com>2018-08-13 14:33:48 +0200
commit772bebede53ce75f4cc8682c8502920610d1d66f (patch)
tree55cf310a673bf1189113bc6ab649bcf139aa6334
parent5f1d32f3fb89f40740b25491caafb9a5710d555a (diff)
[MOV] project,hr_timesheet: move project_time_mode_id field
'project_time_mode_id' is the field used to determined the UoM to use when logging timesheets. It is not used in project alone, but in timesheet. Moving it make sense, and does not cause any problems. For now, no UI allow the end user to change it: it is set with the Hours UoM (hardcoded). This is a technical move to prepare the feature that will allow people timesheeting in Days or Hours. Task #39079
-rw-r--r--addons/hr_timesheet/models/__init__.py1
-rw-r--r--addons/hr_timesheet/models/project.py42
-rw-r--r--addons/hr_timesheet/models/res_company.py (renamed from addons/project/models/res_company.py)0
-rw-r--r--addons/hr_timesheet/models/res_config_settings.py5
-rw-r--r--addons/hr_timesheet/views/res_config_settings_views.xml11
-rw-r--r--addons/project/models/__init__.py1
-rw-r--r--addons/project/models/project.py42
-rw-r--r--addons/project/models/res_config_settings.py5
-rw-r--r--addons/project/views/res_config_settings_views.xml2
9 files changed, 60 insertions, 49 deletions
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
index afad6d1b54e..afad6d1b54e 100644
--- a/addons/project/models/res_company.py
+++ b/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 @@
<div class="app_settings_block" data-string="Timesheets" string="Timesheets" data-key="hr_timesheet" groups="hr_timesheet.group_timesheet_manager">
<h2>Timesheet Apps</h2>
<div class="row mt16 o_settings_container">
+ <div class="col-12 col-lg-6 o_setting_box" attrs="{'invisible':[('project_time_mode_id', '!=', False)]}">
+ <div class="o_setting_right_pane">
+ <label for="project_time_mode_id"/>
+ <span class="fa fa-lg fa-building-o" title="Values set here are company-specific." groups="base.group_multi_company"/>
+ <div class="content-group">
+ <div class="mt16">
+ <field name="project_time_mode_id" options="{'no_create': True, 'no_open': True}"/>
+ </div>
+ </div>
+ </div>
+ </div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_project_timesheet_synchro" widget="upgrade_boolean"/>
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 @@
</div>
</div>
<h2>Time Management</h2>
- <div class="row mt16 o_settings_container">
+ <div class="row mt16 o_settings_container" name="project_time">
<div class="col-12 col-lg-6 o_setting_box" name="project_time_management">
<div class="o_setting_left_pane">
<field name="module_project_forecast" widget="upgrade_boolean"/>