huge fix
This commit is contained in:
		
							parent
							
								
									810c87e2e0
								
							
						
					
					
						commit
						b5bf3a5dbe
					
				
					 51 changed files with 2397 additions and 326 deletions
				
			
		| 
						 | 
				
			
			@ -52,16 +52,20 @@ def certificate_step(request, instance_id, step_id):
 | 
			
		|||
    # Ensure all previous steps are completed and invoice settled
 | 
			
		||||
    prior_steps = instance.process.steps.filter(order__lt=instance.current_step.order if instance.current_step else 9999)
 | 
			
		||||
    incomplete = StepInstance.objects.filter(process_instance=instance, step__in=prior_steps).exclude(status='completed').exists()
 | 
			
		||||
    previous_step = instance.process.steps.filter(order__lt=instance.current_step.order).last() if instance.current_step else None
 | 
			
		||||
    prev_si = StepInstance.objects.filter(process_instance=instance, step=previous_step).first() if previous_step else None 
 | 
			
		||||
 | 
			
		||||
    if incomplete:
 | 
			
		||||
    if incomplete and not prev_si.status == 'approved':
 | 
			
		||||
        messages.error(request, 'ابتدا همه مراحل قبلی را تکمیل کنید')
 | 
			
		||||
        return redirect('processes:request_list')
 | 
			
		||||
        
 | 
			
		||||
    inv = Invoice.objects.filter(process_instance=instance).first()
 | 
			
		||||
    if inv:
 | 
			
		||||
        inv.calculate_totals()
 | 
			
		||||
        if inv.remaining_amount != 0:
 | 
			
		||||
            messages.error(request, 'مانده فاکتور باید صفر باشد')
 | 
			
		||||
            return redirect('processes:request_list')
 | 
			
		||||
        if prev_si and not prev_si.status == 'approved':
 | 
			
		||||
            inv.calculate_totals()
 | 
			
		||||
            if inv.remaining_amount != 0:
 | 
			
		||||
                messages.error(request, 'مانده فاکتور باید صفر باشد')
 | 
			
		||||
                return redirect('processes:request_list')
 | 
			
		||||
 | 
			
		||||
    template = CertificateTemplate.objects.filter(is_active=True).order_by('-created').first()
 | 
			
		||||
    if not template:
 | 
			
		||||
| 
						 | 
				
			
			@ -117,6 +121,8 @@ def certificate_step(request, instance_id, step_id):
 | 
			
		|||
        instance.save()
 | 
			
		||||
        return redirect('processes:instance_summary', instance_id=instance.id)
 | 
			
		||||
 | 
			
		||||
    # latest installation report for details
 | 
			
		||||
    latest_report = InstallationReport.objects.filter(assignment__process_instance=instance).order_by('-created').first()
 | 
			
		||||
    return render(request, 'certificates/step.html', {
 | 
			
		||||
        'instance': instance,
 | 
			
		||||
        'template': template,
 | 
			
		||||
| 
						 | 
				
			
			@ -124,6 +130,7 @@ def certificate_step(request, instance_id, step_id):
 | 
			
		|||
        'previous_step': previous_step,
 | 
			
		||||
        'next_step': next_step,
 | 
			
		||||
        'step': step,
 | 
			
		||||
        'latest_report': latest_report,
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -131,11 +138,32 @@ def certificate_step(request, instance_id, step_id):
 | 
			
		|||
def certificate_print(request, instance_id):
 | 
			
		||||
    instance = get_scoped_instance_or_404(request, instance_id)
 | 
			
		||||
    cert = CertificateInstance.objects.filter(process_instance=instance).order_by('-created').first()
 | 
			
		||||
    latest_report = InstallationReport.objects.filter(assignment__process_instance=instance).order_by('-created').first()
 | 
			
		||||
    if request.method == 'POST':
 | 
			
		||||
        # Save/update hologram code then print
 | 
			
		||||
        code = (request.POST.get('hologram_code') or '').strip()
 | 
			
		||||
        if cert:
 | 
			
		||||
            if code:
 | 
			
		||||
                cert.hologram_code = code
 | 
			
		||||
                cert.save(update_fields=['hologram_code'])
 | 
			
		||||
        else:
 | 
			
		||||
            template = CertificateTemplate.objects.filter(is_active=True).order_by('-created').first()
 | 
			
		||||
            if template:
 | 
			
		||||
                title, body = _render_template(template, instance)
 | 
			
		||||
                cert = CertificateInstance.objects.create(process_instance=instance, template=template, rendered_title=title, rendered_body=body, hologram_code=code or None)
 | 
			
		||||
        # proceed to rendering page after saving code
 | 
			
		||||
        return render(request, 'certificates/print.html', {
 | 
			
		||||
            'instance': instance,
 | 
			
		||||
            'cert': cert,
 | 
			
		||||
            'template': cert.template if cert else None,
 | 
			
		||||
            'latest_report': latest_report,
 | 
			
		||||
        })
 | 
			
		||||
    template = cert.template if cert else None
 | 
			
		||||
    return render(request, 'certificates/print.html', {
 | 
			
		||||
        'instance': instance,
 | 
			
		||||
        'cert': cert,
 | 
			
		||||
        'template': template,
 | 
			
		||||
        'latest_report': latest_report,
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue