Add progress to req_list
This commit is contained in:
		
							parent
							
								
									7a153c46e6
								
							
						
					
					
						commit
						5ce94214d5
					
				
					 6 changed files with 29261 additions and 27 deletions
				
			
		| 
						 | 
				
			
			@ -18,16 +18,32 @@ from wells.models import WaterMeterManufacturer
 | 
			
		|||
@login_required
 | 
			
		||||
def request_list(request):
 | 
			
		||||
    """نمایش لیست درخواستها با جدول و مدال ایجاد"""
 | 
			
		||||
    instances = ProcessInstance.objects.select_related('well', 'representative', 'requester').filter(is_deleted=False).order_by('-created')
 | 
			
		||||
    instances = ProcessInstance.objects.select_related('well', 'representative', 'requester').prefetch_related('step_instances__step').filter(is_deleted=False).order_by('-created')
 | 
			
		||||
    processes = Process.objects.filter(is_active=True)
 | 
			
		||||
    manufacturers = WaterMeterManufacturer.objects.all().order_by('name')
 | 
			
		||||
    
 | 
			
		||||
    # Calculate progress for each instance
 | 
			
		||||
    instances_with_progress = []
 | 
			
		||||
    for instance in instances:
 | 
			
		||||
        total_steps = instance.process.steps.count()
 | 
			
		||||
        completed_steps = instance.step_instances.filter(status='completed').count()
 | 
			
		||||
        progress_percentage = (completed_steps / total_steps * 100) if total_steps > 0 else 0
 | 
			
		||||
        
 | 
			
		||||
        instances_with_progress.append({
 | 
			
		||||
            'instance': instance,
 | 
			
		||||
            'progress_percentage': round(progress_percentage),
 | 
			
		||||
            'completed_steps': completed_steps,
 | 
			
		||||
            'total_steps': total_steps,
 | 
			
		||||
        })
 | 
			
		||||
    
 | 
			
		||||
    # Summary stats for header cards
 | 
			
		||||
    total_count = instances.count()
 | 
			
		||||
    completed_count = instances.filter(status='completed').count()
 | 
			
		||||
    in_progress_count = instances.filter(status='in_progress').count()
 | 
			
		||||
    pending_count = instances.filter(status='pending').count()
 | 
			
		||||
    
 | 
			
		||||
    return render(request, 'processes/request_list.html', {
 | 
			
		||||
        'instances': instances,
 | 
			
		||||
        'instances_with_progress': instances_with_progress,
 | 
			
		||||
        'customer_form': CustomerForm(),
 | 
			
		||||
        'well_form': WellForm(),
 | 
			
		||||
        'processes': processes,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue