Skip to content

Commit

Permalink
chore: fixed representative update
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshmcg committed Jan 16, 2025
1 parent 247a457 commit 319edcd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bc_obps/service/report_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 319edcd

Please sign in to comment.