Skip to content

Commit

Permalink
project_workload: add view to see load, automatically set done load w…
Browse files Browse the repository at this point in the history
…hen the task is closed
  • Loading branch information
sebastienbeau committed Sep 23, 2024
1 parent 7955d70 commit b5e414b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
1 change: 1 addition & 0 deletions project_workload/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"views/project_task_workload_view.xml",
"views/project_task_view.xml",
"views/project_project_view.xml",
"views/project_task_workload_unit_view.xml",
"views/menu_view.xml",
],
}
17 changes: 15 additions & 2 deletions project_workload/models/project_workload_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @author Florian Mounier <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class ProjectWorkloadUnit(models.Model):
Expand All @@ -18,8 +18,21 @@ class ProjectWorkloadUnit(models.Model):
)
task_id = fields.Many2one("project.task", "Task", related="workload_id.task_id")
project_id = fields.Many2one(
"project.project", "Project", related="workload_id.project_id"
"project.project",
"Project",
related="workload_id.project_id",
store=True,
)
done = fields.Boolean(compute="_compute_done", store=True)

def is_done(self):
self.ensure_one()
return self.task_id.stage_id.is_closed

@api.depends("task_id.stage_id.is_closed")
def _compute_done(self):
for record in self:
record.done = record.is_done()

def name_get(self):
result = []
Expand Down
8 changes: 8 additions & 0 deletions project_workload/views/menu_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@
groups="project_workload.group_project_workload"
/>

<menuitem
id="project_task_workload_menu"
name="Workload"
parent="project_workload.project_workload_menu"
sequence="10"
action="project_workload_unit_action"
/>

</odoo>
66 changes: 66 additions & 0 deletions project_workload/views/project_task_workload_unit_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="project_workload_unit_view_tree" model="ir.ui.view">
<field name="model">project.workload.unit</field>
<field name="arch" type="xml">
<tree string="Workload">
<field name="week" />
<field name="user_id" />
<field name="hours" />
<field name="project_id" />
<field name="task_id" optional="hide" />
<field name="workload_id" optional="hide" />
</tree>
</field>
</record>

<record id="project_workload_unit_view_search" model="ir.ui.view">
<field name="model">project.workload.unit</field>
<field name="arch" type="xml">
<search string="Workload">
<field name="week" />
<field name="user_id" />
<field name="project_id" />
<filter
string="My load"
name="my_load"
domain="[('user_id', '=', uid), ('done', '=', False)]"
/>
<group expand="0" string="Group By">
<filter
string="Week"
name="groupby_week"
domain="[]"
context="{'group_by': 'week'}"
/>
<filter
string="User"
name="groupby_user"
domain="[]"
context="{'group_by': 'user_id'}"
/>
<filter
string="Project"
name="groupby_project"
domain="[]"
context="{'group_by': 'project_id'}"
/>
</group>
</search>
</field>
</record>

<record model="ir.actions.act_window" id="project_workload_unit_action">
<field name="name">Workload</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">project.workload.unit</field>
<field name="view_mode">tree</field>
<field name="search_view_id" ref="project_workload_unit_view_search" />
<field name="domain">[]</field>
<field
name="context"
>{'search_default_my_load': 1, 'search_default_groupby_week': 1}</field>
</record>

</odoo>
9 changes: 6 additions & 3 deletions project_workload_timesheet/models/project_workload_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ class ProjectWorkloadUnit(models.Model):
compute="_compute_progress",
help="The progress of the task",
)
done = fields.Boolean(
"Done",
force_done = fields.Boolean(
"Force Done",
)
task_stage_id = fields.Many2one(
related="task_id.stage_id", string="Task Stage", readonly=False
)

def is_done(self):
return super().is_done() or self.force_done

@api.depends("timesheet_ids.unit_amount")
def _compute_timesheeted_hours(self):
for record in self:
Expand Down Expand Up @@ -82,7 +85,7 @@ def action_timesheet_time(self):
return True

def action_timesheet_done(self):
self.done = True
self.force_done = True

def _get_timesheeting_task(self):
# For overrides
Expand Down

0 comments on commit b5e414b

Please sign in to comment.