diff --git a/app/report/service.py b/app/report/service.py index fd1a325..74f1ba5 100644 --- a/app/report/service.py +++ b/app/report/service.py @@ -78,18 +78,17 @@ class ReportService: for cheque in cheques: month_key = cheque.uploaded_at.strftime('%Y-%m') if month_key not in cheques_by_month or \ - cheque.uploaded_at > cheques_by_month[ - month_key].uploaded_at: + cheque.uploaded_at > cheques_by_month[month_key].uploaded_at: cheques_by_month[month_key] = cheque - latest_contract = Contract.objects.filter(user=user).latest( - 'uploaded_at') + latest_contract = Contract.objects.filter(user=user).order_by( + 'uploaded_at').last() user_dict = { "id": user.id, "name": user.get_name(), "visits_count": user_circles_count, - "contract": f'{host_url}{latest_contract.file.url}', + "contract": f'{host_url}{latest_contract.file.url}' if user_has_contract else None, "cheques": [ { "month": f"{months_names[cheque.uploaded_at.strftime('%m')]} " diff --git a/app/report/templates/report/report.html b/app/report/templates/report/report.html index 1d3000e..3d8dd8f 100644 --- a/app/report/templates/report/report.html +++ b/app/report/templates/report/report.html @@ -100,18 +100,20 @@ Количество посещений: {{ not_accessed.visits_count }}/{{ required_count }}

- Договор + {% if not_accessed.contract %} + Договор + {% endif %} {% for cheque in not_accessed.cheques %} Чек за {{ cheque.month }} {% endfor %}
Причины отказа: