Доделал журнал ошибок

This commit is contained in:
2025-12-16 10:19:21 +03:00
parent 1a953cc558
commit 0b34fbd720
7 changed files with 318 additions and 47 deletions

View File

@@ -31,6 +31,9 @@ class ErrorsReportAPIView(View, LoginRequiredMixin, PermissionRequiredMixin):
# Получаем параметры фильтрации
date_from = request.GET.get('date_from')
date_to = request.GET.get('date_to')
location_places = request.GET.getlist('location_place')
error_filters = request.GET.getlist('error_filter')
malfunction_filters = request.GET.getlist('malfunction_filter')
reports = DailyReport.objects.all()
@@ -38,8 +41,16 @@ class ErrorsReportAPIView(View, LoginRequiredMixin, PermissionRequiredMixin):
reports = reports.filter(date__gte=date_from)
if date_to:
reports = reports.filter(date__lte=date_to)
if location_places:
reports = reports.filter(location_place__in=location_places)
reports = reports.prefetch_related('downtime_periods', 'issue_marks__issue_type')
# Фильтрация по ошибкам/неисправностям
if error_filters:
reports = reports.filter(issue_marks__issue_type_id__in=error_filters, issue_marks__is_present=True)
if malfunction_filters:
reports = reports.filter(issue_marks__issue_type_id__in=malfunction_filters, issue_marks__is_present=True)
reports = reports.prefetch_related('downtime_periods', 'issue_marks__issue_type').distinct()
# Получаем все типы ошибок/неисправностей
issue_types = IssueType.objects.all().order_by('category', 'name')
@@ -68,6 +79,8 @@ class ErrorsReportAPIView(View, LoginRequiredMixin, PermissionRequiredMixin):
'weekly_work_hours': float(report.weekly_work_hours),
'explanation': report.explanation or '',
'comment': report.comment or '',
'location_place': report.location_place or '',
'location_place_display': report.get_location_place_display() if report.location_place else '',
}
# Добавляем отметки по каждому типу
@@ -129,6 +142,7 @@ class ErrorsReportSaveAPIView(View):
report.daily_work_hours = Decimal(str(data.get('daily_work_hours', 0)))
report.explanation = data.get('explanation', '')
report.comment = data.get('comment', '')
report.location_place = data.get('location_place', 'kr')
report.save()
except DailyReport.DoesNotExist:
return JsonResponse({'success': False, 'error': 'Запись не найдена'}, status=404)
@@ -139,6 +153,7 @@ class ErrorsReportSaveAPIView(View):
daily_work_hours=Decimal(str(data.get('daily_work_hours', 0))),
explanation=data.get('explanation', ''),
comment=data.get('comment', ''),
location_place=data.get('location_place', 'kr'),
created_by=request.user if request.user.is_authenticated else None,
)