The Maintenance module tracks preventive and corrective maintenance performed on equipment deployed at project sites. Each maintenance operation generates a SheetMaintenance record that documents the work performed, parts replaced, and costs incurred.
# Technical staff who performed the workperformed_by = CharField(max_length=255)performed_by_position = CharField(max_length=255)# Supervisor who approved the workapproved_by = CharField(max_length=255)approved_by_position = CharField(max_length=255)
While the system tracks the assigned responsible_technical, the performed_by and approved_by fields record the actual names for the maintenance report document.
# Create corrective maintenancemaintenance = SheetMaintenance.objects.create( id_sheet_project=sheet_project, maintenance_type='CORRECTIVO', resource_item=resource, responsible_technical=technical, requested_by='Cliente - Emergencia', rig='RIG-23', code='PTRTAR-005', location='Campamento Sur', start_date=date(2026, 3, 18), end_date=date(2026, 3, 19), total_days=2, cost_day=200.00, cost_total=400.00, cost_logistics=100.00, fault_description='Motor del blower no arranca. Sin funcionamiento de aireación.', possible_causes='''- Falla eléctrica en relay del motor - Daño en el motor eléctrico - Problema en panel de control''', maintenance_description='''Reparación realizada: - Diagnóstico eléctrico completo - Reemplazo de relay del motor - Pruebas de funcionamiento - Ajustes finales''', replaced_parts='''- Relay del motor (marca Schneider, ref. LRD10) - Fusibles 10A (cantidad: 3)''', observations='Motor funcionando correctamente. Se recomienda revisión del panel de control en 30 días.', performed_by='Pedro Electricista', performed_by_position='Técnico Eléctrico', approved_by='María Ingeniera', approved_by_position='Ingeniera de Mantenimiento')
# Finalize maintenancemaintenance.status = 'CLOSED'maintenance.save()# It will now appear in the SheetProject for billing# The cost_total + cost_logistics will be added as line items
Maintenance frequency is defined at the ProjectResourceItem level:
from projects.models import ProjectResourceItem# Get resources due for maintenanceresources = ProjectResourceItem.objects.filter( project=project, is_retired=False, operation_start_date__lte=today, operation_end_date__gte=today)# Check each resource's frequencyfor resource in resources: if resource.frequency_type == 'DAY': # Check if interval_days has passed since last maintenance pass elif resource.frequency_type == 'WEEK': # Check if today is in weekdays list if today.weekday() in resource.weekdays: # Schedule maintenance pass elif resource.frequency_type == 'MONTH': # Check if today's day is in monthdays list if today.day in resource.monthdays: # Schedule maintenance pass