Exemple #1
0
def reassign_cases_for_owner(domain, old_location_id, new_location_id,
                             deprecation_time):
    """
    finds relevant case ids and then
    for each household case
        reassign the household case and all its child cases to new location as a group
    and then reassign all other cases as a group
    """

    supervisor_id = get_supervisor_id(domain, old_location_id)
    child_case_ids_per_household_id, other_case_ids = get_case_ids_for_reassignment(
        domain, old_location_id)

    for household_case_id, household_child_case_ids in child_case_ids_per_household_id.items(
    ):
        reassign_household(domain,
                           household_case_id,
                           old_location_id,
                           new_location_id,
                           supervisor_id,
                           deprecation_time=deprecation_time,
                           household_child_case_ids=household_child_case_ids)

    if other_case_ids:
        reassign_cases(domain, other_case_ids, new_location_id)
 def process(self):
     from custom.icds.location_reassignment.utils import reassign_cases
     new_site_codes = set()
     reassignments_by_location_id = defaultdict([])
     for case_id, details in self.reassignments.items():
         new_site_codes.add(details['new_site_code'])
     new_locations_by_site_code = {
         loc.site_code: loc
         for loc in SQLLocation.active_objects.filter(
             domain=self.domain, site_code__in=new_site_codes)
     }
     for case_id, details in self.reassignments.items():
         new_owner_id = new_locations_by_site_code[
             details['new_site_code']].location_id
         reassignments_by_location_id[new_owner_id].append(case_id)
     for new_owner_id, case_ids in reassignments_by_location_id.items():
         reassign_cases(self.domain, case_ids, new_owner_id)