From 72953c318a099145829584153a1036563ce6b728 Mon Sep 17 00:00:00 2001 From: dx-tan Date: Wed, 7 Feb 2024 13:38:04 +0700 Subject: [PATCH] Fix: skip create auto daily report --- cope2n-api/fwd_api/api/accuracy_view.py | 14 ++++++++------ cope2n-api/fwd_api/utils/accuracy.py | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index d5e9df2..164c979 100644 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -349,14 +349,15 @@ class AccuracyViewSet(viewsets.ViewSet): @action(detail=False, url_path="report_list", methods=["GET"]) def get_report_list(self, request): if request.method == 'GET': - daily_report_only = request.GET.get('daily_report_only', False) + exclude_daily_report = request.GET.get('exclude_daily_report', True) start_date_str = request.GET.get('start_date', "") end_date_str = request.GET.get('end_date', "") page_number = int(request.GET.get('page', 1)) page_size = int(request.GET.get('page_size', 10)) + reports = None if not start_date_str or not end_date_str: - reports = Report.objects.all().order_by('created_at').reverse() + reports = Report.objects else: try: start_date = timezone.datetime.strptime(start_date_str, '%Y-%m-%dT%H:%M:%S%z') @@ -364,14 +365,15 @@ class AccuracyViewSet(viewsets.ViewSet): except ValueError: raise InvalidException(excArgs="Date format") base_query = Q(created_at__range=(start_date, end_date)) - if daily_report_only: - base_query &= Q(is_daily_report=True) - reports = Report.objects.filter(base_query).order_by('created_at').reverse() + reports = Report.objects.filter(base_query) + + if exclude_daily_report: + reports = Report.objects.filter(is_daily_report=False) + reports = reports.order_by('created_at').reverse() paginator = Paginator(reports, page_size) page = paginator.get_page(page_number) - data = [] for report in page: acc_keys = ["purchase_date", "retailername", "imei_number", "avg"] diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py index a1ab5e0..1d78331 100644 --- a/cope2n-api/fwd_api/utils/accuracy.py +++ b/cope2n-api/fwd_api/utils/accuracy.py @@ -252,7 +252,8 @@ class ReportAccumulateByRequest: feedback_accuracy=acumulated_acc["feedback_accuracy"], reviewed_accuracy=acumulated_acc["reviewed_accuracy"], ) - new_report.save() + if is_daily_report: + new_report.save() data = extract_report_detail_list(self.data[month][1][day]["report_files"], lower=True) data_workbook = dict2xlsx(data, _type='report_detail') local_workbook = save_workbook_file(report_id + ".xlsx", new_report, data_workbook)