The OTE (Órdenes de Trabajo Ejecutivo / Work Orders) module manages the complete lifecycle of work orders, from creation to execution and completion. Work orders are derived from PTEs and represent the actual execution phase of marine engineering projects.
Work Orders in SASCOP are categorized into two main types:
Initial Orders (Type 4): Original work orders created from PTEs
Reprogrammed Orders (Type 5): Rescheduled versions of initial orders
The con_sitios class method efficiently loads site information using prefetching:
operaciones/models/ote_models.py
@classmethoddef con_sitios(cls, **filters): """ Clase para filtar por sitio """ ots = list(cls.objects.filter(**filters)) if not ots: return ots sitio_ids = set() for ot in ots: if ot.id_embarcacion: sitio_ids.add(ot.id_embarcacion) if ot.id_plataforma: sitio_ids.add(ot.id_plataforma) if ot.id_intercom: sitio_ids.add(ot.id_intercom) if ot.id_patio: sitio_ids.add(ot.id_patio) sitios_dict = {} if sitio_ids: sitios_dict = {sitio.id: sitio for sitio in Sitio.objects.filter(id__in=sitio_ids)} for ot in ots: ot.embarcacion_obj = sitios_dict.get(ot.id_embarcacion) ot.plataforma_obj = sitios_dict.get(ot.id_plataforma) ot.intercom_obj = sitios_dict.get(ot.id_intercom) ot.patio_obj = sitios_dict.get(ot.id_patio) return ots
This method reduces database queries by fetching all related sites in a single query, then attaching them as attributes to each OTE instance.
Two computed properties track reprogramming relationships:
operaciones/models/ote_models.py
@propertydef tiene_reprogramaciones(self): """Retorna True si esta OT tiene reprogramaciones asociadas""" if self.id_tipo_id != 4: # Solo para OTs iniciales return False return OTE.objects.filter( ot_principal=self.id, id_tipo_id=5, estatus__in=[-1, 1] ).exists()@propertydef count_reprogramaciones(self): """Retorna el número de reprogramaciones asociadas""" if self.id_tipo_id != 4: return 0 return OTE.objects.filter( ot_principal=self.id, id_tipo_id=5, estatus__in=[-1, 1] ).count()
tiene_reprogramaciones
Returns True if the initial work order has active reprogrammed versions
count_reprogramaciones
Returns the number of active reprogrammed work orders linked to this initial order