first push message
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# -*- 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
|
||||
Reference in New Issue
Block a user