Skip to content

Conversation

@jajjibhai008
Copy link
Contributor

@jajjibhai008 jajjibhai008 commented Sep 11, 2025

Description:
Added BNR bulk approval endpoint

http://localhost:18270/api/v1/learner-credit-requests/bulk-approve/
  • Payload for selected requests approval

{ 
    "policy_uuid": "a12d4d9b-3d3b-4e5a-902d-a36d18a3fc82",
    "enterprise_customer_uuid": "7af27a1d-8012-4985-b89f-9c8bdd46b3a2",
    "subsidy_request_uuids": [ "0b887544-103a-4916-9929-9c256ea012d5", "131e4d6a-3674-4941-a9b6-d0f8a14d912d"]
}
  • Payload for All requests approval

{ 
    "policy_uuid": "a12d4d9b-3d3b-4e5a-902d-a36d18a3fc82",
    "enterprise_customer_uuid": "7af27a1d-8012-4985-b89f-9c8bdd46b3a2",
    "approve_all": true
}

Expected Response

{
    "approved": [
        {
            "uuid": "0b887544-103a-4916-9929-9c256ea012d4",
            "state": "approved",
            "detail": "Successfully approved"
        },
        {
            "uuid": "131e4d6a-3674-4941-a9b6-d0f8a14d912d",
            "state": "approved",
            "detail": "Successfully approved"
        }
    ],
    "failed": [],
    "not_found": [],
    "skipped": []
}

Jira:
ENT-XXXX

Merge checklist:

  • ./manage.py makemigrations has been run
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.

Post merge:

  • Ensure that your changes went out to the stage instance
  • Deploy to prod instance

@jajjibhai008 jajjibhai008 force-pushed the eahmadjaved/ENT-10854 branch 2 times, most recently from 4ed17e3 to d16b484 Compare September 12, 2025 08:11
@sameenfatima78
Copy link
Member

@jajjibhai008 [Question] Is there a limit to how many bulk requests can admins approve at a time? Also, wouldn't it be better to create a separate utility to create/update assignments in bulk using Django's bulk_update() as it will be more efficient in handling updates in batches?

@jajjibhai008 jajjibhai008 force-pushed the eahmadjaved/ENT-10854 branch 4 times, most recently from 488681e to 165fe7a Compare September 17, 2025 12:49
Copy link
Member

@sameenfatima78 sameenfatima78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments/minor suggestion.
Also, curious how the code will handle re-requests for the same course?

SubsidyRequestStates.ERROR,
]
assert skipped_req.state == SubsidyRequestStates.APPROVED

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a unit test for approve_all as well.

for request in approved_requests:
request.state = SubsidyRequestStates.APPROVED
request.reviewer = reviewer
request.reviewed_at = localized_utcnow()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] let's take this statement outside of loop

now = localized_utcnow()
for request in approved_requests:
    request.state = SubsidyRequestStates.APPROVED
    request.reviewer = reviewer
    request.reviewed_at = now

successful_request_data.append({
'uuid': uuid_val,
'state': SubsidyRequestStates.APPROVED,
'message': "Successfully approved",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field can be left empty for approvals. In fact, it’s better to rename it to “error,” so the frontend can safely assume it only appears for failed requests.

Comment on lines +1147 to +1168
with transaction.atomic():
LearnerCreditRequest.bulk_approve_requests(approved_requests, request.user)

# Send notifications and record results
for request_data in successful_request_data:
send_learner_credit_bnr_request_approve_task.delay(request_data['assignment_uuid'])
add_bulk_approve_operation_result(
results,
"approved",
request_data['uuid'],
request_data['state'],
request_data['message'],
)

except (ValidationError, IntegrityError, DatabaseError) as exc:
error_msg = f"[LC REQUEST BULK APPROVAL] Bulk update failed: {exc}"
logger.exception(error_msg)
for request_data in successful_request_data:
add_bulk_approve_operation_result(
results, "failed", request_data['uuid'],
SubsidyRequestStates.REQUESTED, str(exc)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this indicate that we are either going to process all requests or none in case of failures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants