Files
project_v19/inherit_progress_pro/models/project_project.py
T

29 lines
966 B
Python
Raw Normal View History

2026-07-01 14:41:49 +07:00
# -*- coding: utf-8 -*-
# models/project_project.py
from odoo import models, fields, api
class Project(models.Model):
_inherit = 'project.project'
progress = fields.Float(
string="Project Progress (%)",
compute="_compute_project_progress",
store=True
)
@api.depends('task_ids.progress', 'task_ids.weight', 'task_ids.parent_id', 'task_ids.task_completed')
def _compute_project_progress(self):
for project in self:
top_level_tasks = project.task_ids.filtered(lambda t: not t.parent_id)
total_weighted_progress = 0.0
total_weight = 0.0
for task in top_level_tasks:
weight = task.weight or 0.0
if weight > 0:
total_weight += weight
total_weighted_progress += weight * (task.progress or 0.0)
project.progress = (total_weighted_progress / total_weight) if total_weight > 0 else 0.0