[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
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -61,9 +61,9 @@
|
||||
<field name="groups_id" eval="[(6,0, (ref('hr_timesheet.group_hr_timesheet_user'),))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook/page[@name='description_page']" position="after">
|
||||
<field name="analytic_account_id" invisible="1"/>
|
||||
<field name="analytic_account_active" invisible="1"/>
|
||||
<field name="allow_timesheets" invisible="1"/>
|
||||
<page string="Timesheets" attrs="{'invisible': [('analytic_account_id', '=', False)]}">
|
||||
<page string="Timesheets" attrs="{'invisible': [('allow_timesheets', '=', False)]}">
|
||||
<group>
|
||||
<group>
|
||||
<field name="planned_hours" widget="float_time"/>
|
||||
@@ -76,12 +76,12 @@
|
||||
<field name="progress" widget="progressbar"/>
|
||||
</group>
|
||||
</group>
|
||||
<group name="timesheet_error" attrs="{'invisible': [('allow_timesheets', '!=', False)]}">
|
||||
<group name="timesheet_error" attrs="{'invisible': [('analytic_account_active', '!=', False)]}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
Your project is linked to an inactive analytic account. Change it, or reactivate the current one to timesheet on the project.
|
||||
You can not log timesheets on this project since is linked to an inactive analytic account. Please change it, or reactivate the current one to timesheet on the project.
|
||||
</div>
|
||||
</group>
|
||||
<field name="timesheet_ids" attrs="{'invisible': [('allow_timesheets', '=', False)]}" context="{'default_project_id': project_id, 'default_name':'', 'default_analytic_account_id': analytic_account_id}">
|
||||
<field name="timesheet_ids" attrs="{'invisible': [('analytic_account_active', '=', False)]}" context="{'default_project_id': project_id, 'default_name':''}">
|
||||
<tree editable="bottom" string="Timesheet Activities" default_order="date">
|
||||
<field name="date"/>
|
||||
<field name="user_id" invisible="1"/>
|
||||
@@ -91,7 +91,7 @@
|
||||
<field name="project_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<group attrs="{'invisible': [('allow_timesheets', '=', False)]}">
|
||||
<group attrs="{'invisible': [('analytic_account_active', '=', False)]}">
|
||||
<group class="oe_subtotal_footer oe_right" name="project_hours">
|
||||
<field name="effective_hours" widget="float_time" />
|
||||
<field name="subtask_effective_hours" widget="float_time" attrs="{'invisible' : [('subtask_effective_hours', '=', 0.0)]}" />
|
||||
|
||||
Reference in New Issue
Block a user