Skip to content

Commit

Permalink
Merge pull request #57 from openimis/feature/CM-710
Browse files Browse the repository at this point in the history
CM-710: Backend Development for Program Selection and Filter Application
  • Loading branch information
jdolkowski authored Feb 19, 2024
2 parents 450cfde + b6ce03b commit 2f798cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions social_protection/signals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from core.signals import bind_service_signal
from social_protection.services import BenefitPlanService, BeneficiaryService, GroupBeneficiaryService
from social_protection.signals.on_benefit_plan_data_upload import on_benefit_plan_data_upload
from social_protection.signals.on_confirm_enrollment_of_individual import on_confirm_enrollment_of_individual
from social_protection.signals.on_validation_import_valid_items import on_task_complete_validation_import_valid_items
from tasks_management.services import on_task_complete_service_handler

Expand Down Expand Up @@ -36,3 +37,8 @@ def bind_service_signals():
on_task_complete_validation_import_valid_items,
bind_type=ServiceSignalBindType.AFTER
)
bind_service_signal(
'individual_service.select_individuals_to_benefit_plan',
on_confirm_enrollment_of_individual,
bind_type=ServiceSignalBindType.AFTER
)
26 changes: 26 additions & 0 deletions social_protection/signals/on_confirm_enrollment_of_individual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging

from django.core.exceptions import ValidationError
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']
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:
beneficiary.save(username=user.username)
except ValidationError as e:
logger.error(f"Validation error occurred: {e}")

0 comments on commit 2f798cf

Please sign in to comment.