(domain, location_ids, supply_point_ids, ancestor_ids)
Update location fixtures for users given locations
Update location fixtures for users given locations
Update location fixtures for users given locations
def update_users_at_locations(domain, location_ids, supply_point_ids, ancestor_ids):
    """
    Update location fixtures for users given locations
    """
    from corehq.apps.users.models import CouchUser, update_fixture_status_for_users
    from corehq.apps.locations.dbaccessors import mobile_user_ids_at_locations
    from corehq.apps.fixtures.models import UserFixtureType
    from dimagi.utils.couch.database import iter_docs

    # close supply point cases
    for supply_point_id in supply_point_ids:
        close_supply_point_case(domain, supply_point_id)

    # unassign users from locations
    unassign_user_ids = mobile_user_ids_at_locations(location_ids)
    for doc in iter_docs(CouchUser.get_db(), unassign_user_ids):
        user = CouchUser.wrap_correctly(doc)
        for location_id in location_ids:
            if location_id not in user.get_location_ids(domain):
                continue
            if user.is_web_user():
                user.unset_location_by_id(domain, location_id, fall_back_to_next=True)
            elif user.is_commcare_user():
                user.unset_location_by_id(location_id, fall_back_to_next=True)

    # update fixtures for users at ancestor locations
    user_ids = mobile_user_ids_at_locations(ancestor_ids)
    update_fixture_status_for_users(user_ids, UserFixtureType.LOCATION)
def update_users_at_locations ( domain , location_ids , supply_point_ids , ancestor_ids ) : from corehq . apps . users . models import CouchUser , update_fixture_status_for_users from corehq . apps . locations . dbaccessors import mobile_user_ids_at_locations from corehq . apps . fixtures . models import UserFixtureType from dimagi . utils . couch . database import iter_docs # close supply point cases for supply_point_id in supply_point_ids : close_supply_point_case ( domain , supply_point_id ) # unassign users from locations unassign_user_ids = mobile_user_ids_at_locations ( location_ids ) for doc in iter_docs ( CouchUser . get_db ( ) , unassign_user_ids ) : user = CouchUser . wrap_correctly ( doc ) for location_id in location_ids : if location_id not in user . get_location_ids ( domain ) : continue if user . is_web_user ( ) : user . unset_location_by_id ( domain , location_id , fall_back_to_next = True ) elif user . is_commcare_user ( ) : user . unset_location_by_id ( location_id , fall_back_to_next = True ) # update fixtures for users at ancestor locations user_ids = mobile_user_ids_at_locations ( ancestor_ids ) update_fixture_status_for_users ( user_ids , UserFixtureType . LOCATION )