From 319edcd308b3413f6657f7219f1fcc6ce57f3051 Mon Sep 17 00:00:00 2001 From: ayeshmcg Date: Thu, 16 Jan 2025 15:03:24 -0800 Subject: [PATCH] chore: fixed representative update --- bc_obps/service/report_service.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bc_obps/service/report_service.py b/bc_obps/service/report_service.py index d7fc75280f..326d4931ae 100644 --- a/bc_obps/service/report_service.py +++ b/bc_obps/service/report_service.py @@ -1,7 +1,7 @@ from uuid import UUID from django.db import transaction from django.db.models import QuerySet - +from django.db.models import Case, When, Value, BooleanField from registration.models import Activity, RegulatedProduct from registration.models.operation import Operation from reporting.models import ReportOperationRepresentative @@ -93,9 +93,13 @@ def save_report_operation(cls, report_version_id: int, data: ReportOperationIn) # Update the selected_for_report field based on the provided data representative_ids_in_data = data.operation_representative_name # List of IDs from input - ReportOperationRepresentative.objects.filter( - report_version_id=report_version_id, id__in=representative_ids_in_data - ).update(selected_for_report=True) + ReportOperationRepresentative.objects.filter(report_version_id=report_version_id).update( + selected_for_report=Case( + When(id__in=representative_ids_in_data, then=Value(True)), + default=Value(False), + output_field=BooleanField(), + ) + ) # Update fields from data report_operation.operator_legal_name = data.operator_legal_name report_operation.operator_trade_name = data.operator_trade_name