Hi,
The amount of time (in days) it takes to repair this equipment upon failure. This value updates once a maintenance request is completed for this equipment.
for record in self:
maintenance_requests = record.maintenance_ids.filtered(lambda mr: mr.maintenance_type == 'corrective' and mr.stage_id.done)
record.mttr = len(maintenance_requests) and (sum(int((request.close_date - request.request_date).days) for request in maintenance_requests) / len(maintenance_requests)) or 0
The _compute_maintenance_request method calculates the Mean Time To Repair (MTTR) for each record (typically equipment) by averaging the duration of completed corrective maintenance requests. It first filters the related maintenance requests to include only those with maintenance_type = 'corrective' and in a stage marked as done. For each of these filtered requests, it calculates the time taken to resolve the issue by subtracting the request_date from the close_date, taking only the number of full days (.days) between them. These durations are summed and divided by the total number of such requests to get the average downtime in days. If there are no matching requests, the MTTR is set to 0. Note that this method uses integer days, so any partial days are ignored in the calculation.
Hope it helps.