Add confirmation and summary

This commit is contained in:
aminhashemi92 2025-09-05 13:35:33 +03:30
parent 9b3973805e
commit 35799b7754
25 changed files with 1419 additions and 265 deletions

View file

@ -41,32 +41,36 @@
<div class="bs-stepper-content">
<div class="card border">
<div class="card-body">
{% if template.company.logo %}
<div class="text-center mb-3">
<img src="{{ template.company.logo.url }}" alt="لوگوی شرکت" style="max-height:80px;">
<h4 class="text-muted">{{ contract.template.company.name }}</h4>
<h5 class="text-muted">{{ contract.template.name }}</h5>
</div>
{% endif %}
{% if can_view_contract_body %}
{% if template.company.logo %}
<div class="text-center mb-3">
<img src="{{ template.company.logo.url }}" alt="لوگوی شرکت" style="max-height:80px;">
<h4 class="text-muted">{{ contract.template.company.name }}</h4>
<h5 class="text-muted">{{ contract.template.name }}</h5>
</div>
{% endif %}
<div class="small text-muted mb-2">تاریخ: {{ contract.jcreated }}</div>
<hr>
<div class="contract-body" style="white-space: pre-line; line-height:1.9;">{{ contract.rendered_body|safe }}</div>
<hr>
<div class="row mt-4">
<div class="col-6 text-center">
<div>امضای مشترک</div>
<div style="height:90px;border:1px dashed #ccc; margin-top:10px;"></div>
</div>
<div class="col-6 text-center">
<div>امضای شرکت</div>
<div style="height:90px;border:1px dashed #ccc; margin-top:10px;">
{% if template.company.signature %}
<img src="{{ template.company.signature.url }}" alt="امضای شرکت" style="max-height:80px;">
{% endif %}
<div class="small text-muted mb-2">تاریخ: {{ contract.jcreated }}</div>
<hr>
<div class="contract-body" style="white-space: pre-line; line-height:1.9;">{{ contract.rendered_body|safe }}</div>
<hr>
<div class="row mt-4">
<div class="col-6 text-center">
<div>امضای مشترک</div>
<div style="height:90px;border:1px dashed #ccc; margin-top:10px;"></div>
</div>
<div class="col-6 text-center">
<div>امضای شرکت</div>
<div style="height:90px;border:1px dashed #ccc; margin-top:10px;">
{% if template.company.signature %}
<img src="{{ template.company.signature.url }}" alt="امضای شرکت" style="max-height:80px;">
{% endif %}
</div>
</div>
</div>
</div>
{% else %}
<div class="alert alert-warning mb-0">شما دسترسی به مشاهده متن قرارداد را ندارید.</div>
{% endif %}
</div>
</div>
<form method="post" class="d-flex justify-content-between mt-3">
@ -77,9 +81,17 @@
<span></span>
{% endif %}
{% if next_step %}
<button type="submit" class="btn btn-primary">بعدی</button>
{% if is_broker %}
<button type="submit" class="btn btn-primary">تایید و بعدی</button>
{% else %}
<a href="{% url 'processes:step_detail' instance.id next_step.id %}" class="btn btn-primary">بعدی</a>
{% endif %}
{% else %}
<button class="btn btn-success" type="button">اتمام</button>
{% if is_broker %}
<button class="btn btn-success" type="submit">اتمام</button>
{% else %}
<button class="btn btn-success" type="button" disabled>اتمام</button>
{% endif %}
{% endif %}
</form>
</div>

View file

@ -4,6 +4,7 @@ from django.urls import reverse
from django.utils import timezone
from django.template import Template, Context
from processes.models import ProcessInstance, StepInstance
from common.consts import UserRoles
from .models import ContractTemplate, ContractInstance
from _helpers.utils import jalali_converter2
@ -34,6 +35,20 @@ def contract_step(request, instance_id, step_id):
step = get_object_or_404(instance.process.steps, id=step_id)
previous_step = instance.process.steps.filter(order__lt=step.order).last()
next_step = instance.process.steps.filter(order__gt=step.order).first()
# Access control:
# - INSTALLER: can open step but cannot view contract body (show inline message)
# - Others: can view
# - Only BROKER can submit/complete this step
profile = getattr(request.user, 'profile', None)
is_broker = False
can_view_contract_body = True
try:
is_broker = bool(profile and profile.has_role(UserRoles.BROKER))
if profile and profile.has_role(UserRoles.INSTALLER):
can_view_contract_body = False
except Exception:
pass
template_obj = ContractTemplate.objects.first()
if not template_obj:
return render(request, 'contracts/contract_missing.html', {'instance': instance})
@ -54,8 +69,11 @@ def contract_step(request, instance_id, step_id):
contract.rendered_body = rendered
contract.save()
# If user submits to go next, mark this step completed and go to next
# If user submits to go next, only broker can complete and go to next
if request.method == 'POST':
if not is_broker:
from django.http import JsonResponse
return JsonResponse({'success': False, 'message': 'شما مجوز تایید این مرحله را ندارید'}, status=403)
StepInstance.objects.update_or_create(
process_instance=instance,
step=step,
@ -74,6 +92,8 @@ def contract_step(request, instance_id, step_id):
'template': template_obj,
'previous_step': previous_step,
'next_step': next_step,
'is_broker': is_broker,
'can_view_contract_body': can_view_contract_body,
})