fix auto complete final invoice

This commit is contained in:
aminhashemi92 2025-10-09 14:37:59 +03:30
parent 23f50aacd4
commit 6367d34f0c
7 changed files with 160 additions and 39 deletions

View file

@ -94,6 +94,17 @@ def request_list(request):
reports_map[pid] = row['visited_date']
except Exception:
reports_map = {}
# Build a map to check if installation reports exist (for approval status logic)
has_installation_report_map = {}
if instance_ids:
try:
report_exists_qs = InstallationReport.objects.filter(
assignment__process_instance_id__in=instance_ids
).values_list('assignment__process_instance_id', flat=True).distinct()
has_installation_report_map = {pid: True for pid in report_exists_qs}
except Exception:
has_installation_report_map = {}
# Calculate progress for each instance and attach install schedule info
instances_with_progress = []
@ -140,43 +151,51 @@ def request_list(request):
try:
current_step_instance = instance.step_instances.filter(step=instance.current_step).first()
if current_step_instance:
# Check if this step requires approvals
required_roles = current_step_instance.required_roles()
if required_roles:
# Get approvals by role
approvals_by_role = current_step_instance.approvals_by_role()
# Check for rejections
latest_rejection = current_step_instance.get_latest_rejection()
if latest_rejection and current_step_instance.status == 'rejected':
role_name = latest_rejection.role.name if latest_rejection.role else 'نامشخص'
current_step_approval_status = {
'status': 'rejected',
'role': role_name,
'display': f'رد شده توسط {role_name}'
}
else:
# Check approval status
pending_roles = []
approved_roles = []
for role in required_roles:
if approvals_by_role.get(role.id) == 'approved':
approved_roles.append(role.name)
else:
pending_roles.append(role.name)
# Special check: For installation report step (order=6), only show approval status if report exists
should_show_approval_status = True
if instance.current_step.order == 6:
# Check if installation report exists
if not has_installation_report_map.get(instance.id, False):
should_show_approval_status = False
if should_show_approval_status:
# Check if this step requires approvals
required_roles = current_step_instance.required_roles()
if required_roles:
# Get approvals by role
approvals_by_role = current_step_instance.approvals_by_role()
if pending_roles:
# Check for rejections
latest_rejection = current_step_instance.get_latest_rejection()
if latest_rejection and current_step_instance.status == 'rejected':
role_name = latest_rejection.role.name if latest_rejection.role else 'نامشخص'
current_step_approval_status = {
'status': 'pending',
'roles': pending_roles,
'display': f'در انتظار تایید {" و ".join(pending_roles)}'
}
elif approved_roles and not pending_roles:
current_step_approval_status = {
'status': 'approved',
'roles': approved_roles,
'display': f'تایید شده توسط {" و ".join(approved_roles)}'
'status': 'rejected',
'role': role_name,
'display': f'رد شده توسط {role_name}'
}
else:
# Check approval status
pending_roles = []
approved_roles = []
for role in required_roles:
if approvals_by_role.get(role.id) == 'approved':
approved_roles.append(role.name)
else:
pending_roles.append(role.name)
if pending_roles:
current_step_approval_status = {
'status': 'pending',
'roles': pending_roles,
'display': f'در انتظار تایید {" و ".join(pending_roles)}'
}
elif approved_roles and not pending_roles:
current_step_approval_status = {
'status': 'approved',
'roles': approved_roles,
'display': f'تایید شده توسط {" و ".join(approved_roles)}'
}
except Exception:
current_step_approval_status = None