Skip to content

Commit

Permalink
fix: do not remove batch if ahjo automation (#3381)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Oct 4, 2024
1 parent f2e9c37 commit 57e5eca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,11 @@ def handle_status_transition(
if instance.status == ApplicationStatus.CANCELLED:
self._cancel_application(instance)
self._assign_handler_if_needed(instance)
self._remove_batch_if_needed(instance)

if not instance.handled_by_ahjo_automation and instance.ahjo_case_id is None:
# If the application has been handled by the Ahjo automation, we don't want to
# remove the batch, as it's needed for the Ahjo automation
self._remove_batch_if_needed(instance)

def _cancel_application(self, instance):
instance.archived = True
Expand Down
22 changes: 19 additions & 3 deletions backend/benefit/applications/tests/test_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,16 +1463,29 @@ def test_application_accept(
assert handling_application.calculation.granted_as_de_minimis_aid is True


@pytest.mark.parametrize(
"ahjo_case_id, handled_by_ahjo_automation, has_batch,",
[
(None, False, False),
("KISSA123", True, True),
],
)
def test_application_with_batch_back_to_handling(
request,
handler_api_client,
decided_application,
ahjo_case_id,
handled_by_ahjo_automation,
has_batch,
):
"""
When application is moved back to handling, the application
needs to be remvoved from any batch.
needs to be removed from any batch.
"""
decided_application.batch = ApplicationBatchFactory()
batch = ApplicationBatchFactory()
decided_application.batch = batch
decided_application.ahjo_case_id = ahjo_case_id
decided_application.handled_by_ahjo_automation = handled_by_ahjo_automation
decided_application.save()
data = HandlerApplicationSerializer(decided_application).data
data["status"] = ApplicationStatus.HANDLING
Expand All @@ -1483,7 +1496,10 @@ def test_application_with_batch_back_to_handling(
)
assert response.status_code == 200
decided_application.refresh_from_db()
assert decided_application.batch is None
if has_batch:
assert decided_application.batch == batch
else:
assert decided_application.batch is None


@pytest.mark.parametrize(
Expand Down

0 comments on commit 57e5eca

Please sign in to comment.