[IMP] hr_timesheet,helpdesk: Display remaining hours on a task
Show the remaining hours to timesheet on tasks. Allows to quickly evaluate task's state. This is done in the name_get of a task through a context key, because we need this different name on some views, not all. related task #1856139 closes odoo/odoo#33586 Related: odoo/enterprise#4400 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
committed by
Yannick Tivisse
parent
824b6cf02e
commit
028768f288
@@ -120,6 +120,17 @@ class Task(models.Model):
|
||||
raise UserError(_('This task must be part of a project because there are some timesheets linked to it.'))
|
||||
return super(Task, self).write(values)
|
||||
|
||||
def name_get(self):
|
||||
if self.env.context.get('hr_timesheet_display_remaining_hours'):
|
||||
name_mapping = dict(super().name_get())
|
||||
for task in self:
|
||||
if task.allow_timesheets and task.planned_hours > 0:
|
||||
hours, mins = (str(int(duration)).rjust(2, '0') for duration in divmod(abs(task.remaining_hours) * 60, 60))
|
||||
hours_left = _("(%s%s:%s remaining)") % ('-' if task.remaining_hours < 0 else '', hours, mins)
|
||||
name_mapping[task.id] = name_mapping.get(task.id, '') + " ‒ " + hours_left
|
||||
return list(name_mapping.items())
|
||||
return super().name_get()
|
||||
|
||||
@api.model
|
||||
def _fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
|
||||
""" Set the correct label for `unit_amount`, depending on company UoM """
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
odoo.define('hr_timesheet.task_with_hours', function (require) {
|
||||
"use strict";
|
||||
|
||||
var field_registry = require('web.field_registry');
|
||||
var relational_fields = require('web.relational_fields');
|
||||
var FieldMany2One = relational_fields.FieldMany2One;
|
||||
|
||||
var TaskWithHours = FieldMany2One.extend({
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.additionalContext.hr_timesheet_display_remaining_hours = true;
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_getDisplayNameWithoutHours: function (value) {
|
||||
return value.split(' ‒ ')[0];
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_renderEdit: function (){
|
||||
this.m2o_value = this._getDisplayNameWithoutHours(this.m2o_value);
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
field_registry.add('task_with_hours', TaskWithHours);
|
||||
|
||||
return TaskWithHours;
|
||||
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
<template id="assets_backend" name="timesheet assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/hr_timesheet/static/src/js/timesheet_uom.js"></script>
|
||||
<script type="text/javascript" src="/hr_timesheet/static/src/js/task_with_hours.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<field name="date"/>
|
||||
<field name="name"/>
|
||||
<field name="project_id" required="1" context="{'form_view_ref': 'project.project_project_view_form_simplified',}"/>
|
||||
<field name="task_id" context="{'default_project_id': project_id}" domain="[('project_id', '=', project_id)]"/>
|
||||
<field name="task_id" widget="task_with_hours" context="{'default_project_id': project_id}" domain="[('project_id', '=', project_id)]"/>
|
||||
<field name="unit_amount" widget="timesheet_uom" sum="Total"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
</tree>
|
||||
@@ -83,7 +83,7 @@
|
||||
<group>
|
||||
<field name="date"/>
|
||||
<field name="project_id" required="1" context="{'form_view_ref': 'project.project_project_view_form_simplified',}"/>
|
||||
<field name="task_id"/>
|
||||
<field name="task_id" widget="task_with_hours"/>
|
||||
<field name="name"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user