def call_center_location_owner(user, ancestor_level):
    if user.location_id is None:
        return ""
    if ancestor_level == 0:
        owner_id = user.location_id
    else:
        location = SQLLocation.objects.get(location_id=user.location_id)
        ancestors = location.get_ancestors(ascending=True, include_self=True).only("location_id")
        try:
            owner_id = ancestors[ancestor_level].location_id
        except __HOLE__:
            owner_id = ancestors.last().location_id
    return owner_id
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/callcenter/utils.py/call_center_location_owner