Skip to main content

Introduction

The PTE (Proyectos de Trabajo Especial) module is a core component of SASCOP BME SubTec that manages special work projects from initial request through completion. PTEs represent work orders that go through a defined workflow with multiple status stages and detailed step tracking.
PTEs serve as the foundation for creating OTEs (Órdenes de Trabajo Especial) once all workflow steps are completed.

Core Components

PTEHeader Model

The PTEHeader model represents the main PTE record and contains essential project information:
class PTEHeader(models.Model):
    ESTATUS_CHOICES = [
        (1, 'Activo'),
        (2, 'En Proceso'),
        (3, 'Terminado'),
        (4, 'Cancelado'),
    ]
    
    id_tipo = models.ForeignKey(Tipo, on_delete=models.CASCADE, limit_choices_to={'nivel_afectacion': 1})
    oficio_pte = models.CharField(max_length=100)
    oficio_solicitud = models.CharField(max_length=100)
    descripcion_trabajo = models.TextField()
    fecha_solicitud = models.DateField(blank=True, null=True)
    fecha_entrega = models.DateField(blank=True, null=True)
    plazo_dias = models.FloatField()
    id_orden_trabajo = models.CharField(max_length=100, blank=True, null=True)
    id_responsable_proyecto = models.ForeignKey(ResponsableProyecto, on_delete=models.CASCADE, blank=True, null=True)
    total_homologado = models.DecimalField(max_digits=15, decimal_places=2, default=0)
    estatus = models.IntegerField(choices=ESTATUS_CHOICES, default=1)
    prioridad = models.IntegerField(blank=True, null=True)
    id_cliente = models.ForeignKey(Cliente, on_delete=models.CASCADE, blank=True, null=True)
    comentario = models.TextField(blank=True, null=True)
The estatus field uses integer choices to track the PTE lifecycle, while fecha_entrega is automatically set when the status changes to “Terminado” (3).

PTEDetalle Model

Each PTE contains multiple detail records tracking individual workflow steps:
class PTEDetalle(models.Model):
    id_pte_header = models.ForeignKey(PTEHeader, on_delete=models.CASCADE, related_name='detalles')
    estatus_paso = models.ForeignKey(Estatus, on_delete=models.CASCADE, limit_choices_to={'nivel_afectacion': 4})
    id_paso = models.ForeignKey(Paso, on_delete=models.CASCADE)
    fecha_entrega = models.DateField(null=True, blank=True)
    fecha_inicio = models.DateField(null=True, blank=True)
    fecha_termino = models.DateField(null=True, blank=True)
    comentario = models.TextField(blank=True, null=True)
    archivo = models.TextField(blank=True, null=True)

Paso Model

Workflow steps are defined in the Paso model with ordering and type classification:
class Paso(models.Model):
    descripcion = models.CharField(max_length=200)
    orden = models.CharField(blank=True, null=True, max_length=10)
    activo = models.BooleanField(default=True)
    importancia = models.FloatField(default=0)
    tipo = models.IntegerField(blank=True, null=True, default=1)
    comentario = models.TextField(blank=True, null=True)
    id_tipo_cliente = models.ForeignKey(Tipo, on_delete=models.CASCADE, null=True, blank=True)

Key Features

Status Tracking

Track PTEs through four distinct statuses: Activo, En Proceso, Terminado, and Cancelado

Step Management

Manage detailed workflow steps with individual status tracking and progress calculation

Client-Based Workflows

Automatically assign workflow steps based on client type for customized processes

OT Generation

Convert completed PTEs into OTs (Órdenes de Trabajo) with automated data transfer

Status Flow

1

Activo

PTE has been created and is ready to begin
2

En Proceso

Work is actively being performed on the PTE
3

Terminado

All steps completed, PTE is ready for OT generation
4

Cancelado

PTE has been cancelled and will not proceed

URL Endpoints

The PTE module provides the following key endpoints:
EndpointView FunctionPurpose
/pte/lista_pteList all PTEs
/pte/<id>/detalle_pteView PTE details
/pte/crear/crear_pteCreate new PTE
/pte/editar/editar_pteEdit existing PTE
/pte/eliminar/eliminar_pteLogical deletion
/pte/datatable/datatable_ptesDataTables JSON
/pte/cambiar_estatus_pte/cambiar_estatus_pteUpdate PTE status
/pte/cambiar_estatus_paso/cambiar_estatus_pasoUpdate step status
The eliminar_pte function performs a logical deletion by setting estatus=0, not a physical database deletion. This preserves historical data.

Progress Calculation

PTE progress is calculated based on completed steps:
detalles = PTEDetalle.objects.filter(id_pte_header_id=pte_id)
total_pasos = detalles.count()
pasos_completados = detalles.filter(estatus_paso__in=[3, 14]).count()

progreso = 0
if total_pasos > 0:
    progreso = (pasos_completados / total_pasos) * 100
Steps with status 3 (Completado) or 14 (No Aplica) are both counted as completed for progress calculation.

Next Steps

Creating PTEs

Learn how to create and configure new PTEs

Workflow Steps

Understand the detailed workflow step management

Status Tracking

Master PTE and step status tracking

Build docs developers (and LLMs) love