66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
from odoo import _, api, fields, models
|
|
|
|
|
|
class ProjectProject(models.Model):
|
|
_inherit = "project.project"
|
|
|
|
timeline_color_hex = fields.Char(
|
|
string="Timeline Color",
|
|
default="#5794dd",
|
|
help="Custom color used for this project's timeline bars.",
|
|
)
|
|
timeline_entry_ids = fields.One2many(
|
|
"user.timeline.entry",
|
|
"project_id",
|
|
string="Timeline Entries",
|
|
readonly=True,
|
|
)
|
|
timeline_entry_count = fields.Integer(
|
|
compute="_compute_timeline_metrics",
|
|
string="Timeline Entries",
|
|
)
|
|
timeline_member_count = fields.Integer(
|
|
compute="_compute_timeline_metrics",
|
|
string="Team Members in Timeline",
|
|
)
|
|
timeline_leave_count = fields.Integer(
|
|
compute="_compute_timeline_metrics",
|
|
string="Leave Blocks",
|
|
)
|
|
timeline_task_count = fields.Integer(
|
|
compute="_compute_timeline_metrics",
|
|
string="Task Blocks",
|
|
)
|
|
|
|
@api.depends("timeline_entry_ids")
|
|
def _compute_timeline_metrics(self):
|
|
grouped = {}
|
|
if self.ids:
|
|
entries = self.env["user.timeline.entry"].search([("project_id", "in", self.ids)])
|
|
for project in self:
|
|
project_entries = entries.filtered(lambda entry: entry.project_id.id == project.id)
|
|
grouped[project.id] = project_entries
|
|
for project in self:
|
|
project_entries = grouped.get(project.id, self.env["user.timeline.entry"])
|
|
project.timeline_entry_count = len(project_entries)
|
|
project.timeline_member_count = len(project_entries.mapped("user_id"))
|
|
project.timeline_leave_count = len(project_entries.filtered(lambda entry: entry.entry_type == "leave"))
|
|
project.timeline_task_count = len(project_entries.filtered(lambda entry: entry.entry_type == "task"))
|
|
|
|
def action_open_team_timelines(self):
|
|
self.ensure_one()
|
|
action = self.env["ir.actions.act_window"]._for_xml_id(
|
|
"user_timelines.action_user_timeline_entries"
|
|
)
|
|
action["name"] = _("Team Timelines: %s", self.name)
|
|
action["domain"] = [("project_id", "=", self.id)]
|
|
action["context"] = {
|
|
"search_default_group_employee": 1,
|
|
"search_default_group_user": 0,
|
|
"search_default_group_project": 0,
|
|
"search_default_public_holidays_remove": 1,
|
|
"default_is_public_holiday": 0,
|
|
"default_project_id": self.id,
|
|
}
|
|
return action
|