-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM-710: added signal to connect with individual enrollment process
- Loading branch information
1 parent
450cfde
commit b62ab7f
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
social_protection/signals/on_confirm_enrollment_of_individual.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
|
||
from django.core.exceptions import ValidationError | ||
|
||
from individual.models import IndividualDataSourceUpload | ||
from social_protection.models import Beneficiary | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def on_confirm_enrollment_of_individual(**kwargs): | ||
result = kwargs.get('result', None) | ||
benefit_plan_id = result['benefit_plan_id'] | ||
status = result['status'] | ||
user = result['user'] | ||
individuals_to_upload = result['individuals_not_assigned_to_selected_programme'] | ||
print(status) | ||
print(individuals_to_upload) | ||
print(benefit_plan_id) | ||
for individual in individuals_to_upload: | ||
# Create a new Beneficiary instance | ||
beneficiary = Beneficiary( | ||
individual=individual, | ||
benefit_plan_id=benefit_plan_id, | ||
status=status, | ||
json_ext=individual.json_ext | ||
) | ||
try: | ||
b = beneficiary.save(username=user.username) | ||
print(b) | ||
except ValidationError as e: | ||
print(f"Validation error occurred: {e}") |