Skip to content

Commit 65c373a

Browse files
committed
feat(project_phase_estimate): add validated hours metrics and progress calculation for project estimates
- Add effective_hours_validated, remaining_hours_validated, and progress_validated computed fields to track validated timesheet data - Refactor _compute_progress_hours to use shared _calculate_progress method for both regular and validated metrics - Filter validated timesheets in _compute_effective_hours and update remaining_hours_validated accordingly - Remove redundant validated filter from action_open_timesheets as it's now handled in computed fields - Maintain existing functionality while enhancing reporting with validated hours metrics for more accurate progress tracking
1 parent 469f955 commit 65c373a

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

project_phase_estimate/models/project_estimate.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class ProjectEstimate(models.Model):
2929
effective_hours = fields.Float(compute="_compute_effective_hours", compute_sudo=True, store=True)
3030
remaining_hours = fields.Float(compute="_compute_remaining_hours", store=True)
3131
progress = fields.Float(compute="_compute_progress_hours", store=True, group_operator="avg")
32+
effective_hours_validated = fields.Float(compute="_compute_effective_hours", compute_sudo=True, store=True)
33+
remaining_hours_validated = fields.Float(compute="_compute_remaining_hours", store=True)
34+
progress_validated = fields.Float(compute="_compute_progress_hours", store=True, group_operator="avg")
3235

3336
@api.depends("start_date", "end_date")
3437
def _compute_is_in_progress(self):
@@ -66,9 +69,6 @@ def _compute_effective_hours(self):
6669
)
6770
effective_hours = task_ids.timesheet_ids
6871

69-
if self.env.context.get("validated_hours_only", False):
70-
effective_hours = effective_hours.filtered(lambda line: line.validated)
71-
7272
if estimate.start_date:
7373
effective_hours = effective_hours.filtered(lambda line: line.date >= estimate.start_date)
7474

@@ -77,33 +77,46 @@ def _compute_effective_hours(self):
7777

7878
estimate.effective_hours = sum(effective_hours.mapped("unit_amount"))
7979

80+
effective_hours_validated = effective_hours.filtered(lambda line: line.validated)
81+
estimate.effective_hours_validated = sum(effective_hours_validated.mapped("unit_amount"))
82+
8083
@api.depends("planned_hours", "effective_hours")
8184
def _compute_remaining_hours(self):
8285
for estimate in self:
8386
estimate.remaining_hours = estimate.planned_hours - estimate.effective_hours
87+
estimate.remaining_hours_validated = estimate.planned_hours - estimate.effective_hours_validated
8488

85-
@api.depends("remaining_hours")
86-
def _compute_progress_hours(self):
89+
@api.model
90+
def _calculate_progress(self, planned_hours, effective_hours):
8791
"""
8892
Compare effective hours with planned hours.
8993
If planned hours is zero then set progress to 100%.
9094
When effective hours exceeds planned hours set progress to 100%.
9195
"""
92-
for estimate in self:
93-
if estimate.planned_hours > 0.0:
94-
if (
95-
float_compare(
96-
estimate.effective_hours,
97-
estimate.planned_hours,
98-
precision_digits=2,
99-
)
100-
>= 0
101-
):
102-
estimate.progress = 100
103-
else:
104-
estimate.progress = round(100.0 * estimate.effective_hours / estimate.planned_hours, 2)
96+
progress = 0
97+
if planned_hours > 0.0:
98+
if (
99+
float_compare(
100+
effective_hours,
101+
planned_hours,
102+
precision_digits=2,
103+
)
104+
>= 0
105+
):
106+
progress = 100
105107
else:
106-
estimate.progress = 100
108+
progress = round(100.0 * effective_hours / planned_hours, 2)
109+
else:
110+
progress = 100
111+
return progress
112+
113+
@api.depends("remaining_hours")
114+
def _compute_progress_hours(self):
115+
for estimate in self:
116+
estimate.progress = self._calculate_progress(estimate.planned_hours, estimate.effective_hours)
117+
estimate.progress_validated = self._calculate_progress(
118+
estimate.planned_hours, estimate.effective_hours_validated
119+
)
107120

108121
def action_open_timesheets(self):
109122
self.ensure_one()
@@ -120,8 +133,6 @@ def action_open_timesheets(self):
120133
timesheet_domain.append(("date", ">=", self.start_date))
121134
if self.end_date:
122135
timesheet_domain.append(("date", "<=", self.end_date))
123-
if self.env.context.get("validated_hours_only", False):
124-
timesheet_domain.append(("validated", "=", True))
125136

126137
return {
127138
"type": "ir.actions.act_window",

0 commit comments

Comments
 (0)