From c54f0952438b170f949e2d6dd682e776af8a27e1 Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Fri, 27 Jul 2018 10:04:41 +0200 Subject: [PATCH] [IMP] hr_timesheet: warning when AA inactive to log timesheet If the project does not allow timesheets, the 'timesheet' tab on task should be hidden. If the project allows timesheet but its related analytic account is inactive, the warning message will be displayed to avoid user to record timesheets. Task #1857652 --- addons/hr_timesheet/models/project.py | 9 ++------- addons/hr_timesheet/views/project_views.xml | 12 ++++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 6a68665dc04..e662b4366cf 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -94,8 +94,8 @@ class Project(models.Model): class Task(models.Model): _inherit = "project.task" - analytic_account_id = fields.Many2one('account.analytic.account', string="Analytic Account", related='project_id.analytic_account_id', readonly=True) - allow_timesheets = fields.Boolean("Allow timesheets", compute='_compute_allow_timesheets', help="Timesheets can be logged on this task.") + analytic_account_active = fields.Boolean("Analytic Account", related='project_id.analytic_account_id.active', readonly=True) + allow_timesheets = fields.Boolean("Allow timesheets", related='project_id.allow_timesheets', help="Timesheets can be logged on this task.") remaining_hours = fields.Float("Remaining Hours", compute='_compute_remaining_hours', inverse='_inverse_remaining_hours', help="Total remaining time, can be re-estimated periodically by the assignee of the task.") effective_hours = fields.Float("Hours Spent", compute='_compute_effective_hours', compute_sudo=True, store=True, help="Computed using the sum of the task work done.") total_hours_spent = fields.Float("Total Hours", compute='_compute_total_hours_spent', store=True, help="Computed as: Time Spent + Sub-tasks Hours.") @@ -103,11 +103,6 @@ class Task(models.Model): subtask_effective_hours = fields.Float("Sub-tasks Hours Spent", compute='_compute_subtask_effective_hours', store=True, help="Sum of actually spent hours on the subtask(s)", oldname='children_hours') timesheet_ids = fields.One2many('account.analytic.line', 'task_id', 'Timesheets') - @api.depends('project_id.allow_timesheets', 'project_id.analytic_account_id') - def _compute_allow_timesheets(self): - for task in self: - task.allow_timesheets = task.project_id.allow_timesheets and task.project_id.analytic_account_id.active - @api.depends('timesheet_ids.unit_amount') def _compute_effective_hours(self): for task in self: diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index a98fd8e4624..a7b8bf0a74f 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -61,9 +61,9 @@ - + - + @@ -76,12 +76,12 @@ - + - + @@ -91,7 +91,7 @@ - +