[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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user