(domain, username, app_id, profile_id, location_flag_enabled)
return latest_enabled_build
:return: enabled build for the app for a location or profile on basis of feature flag enabled with
    location flag taking precedence
:return: enabled build for the app for a location or profile on basis of feature flag enabled with
    location flag taking precedence
: return : enabled build for the app for a location or profile on basis of feature flag enabled with location flag taking precedence
def _get_latest_enabled_build(domain, username, app_id, profile_id, location_flag_enabled):
    """
    :return: enabled build for the app for a location or profile on basis of feature flag enabled with
    location flag taking precedence
    """
    latest_enabled_build = None
    if location_flag_enabled:
        user = CommCareUser.get_by_username(normalize_username(username, domain))
        user_location_id = user.location_id
        if user_location_id:
            parent_app_id = get_app(domain, app_id).copy_of
            latest_enabled_build = get_latest_app_release_by_location(domain, user_location_id, parent_app_id)
    if not latest_enabled_build:
        # Fall back to the old logic to support migration
        # ToDo: Remove this block once migration is complete
        if profile_id and toggles.RELEASE_BUILDS_PER_PROFILE.enabled(domain):
            latest_enabled_build = get_latest_enabled_build_for_profile(domain, profile_id)
    return latest_enabled_build
def _get_latest_enabled_build ( domain , username , app_id , profile_id , location_flag_enabled ) : latest_enabled_build = None if location_flag_enabled : user = CommCareUser . get_by_username ( normalize_username ( username , domain ) ) user_location_id = user . location_id if user_location_id : parent_app_id = get_app ( domain , app_id ) . copy_of latest_enabled_build = get_latest_app_release_by_location ( domain , user_location_id , parent_app_id ) if not latest_enabled_build : # Fall back to the old logic to support migration # ToDo: Remove this block once migration is complete if profile_id and toggles . RELEASE_BUILDS_PER_PROFILE . enabled ( domain ) : latest_enabled_build = get_latest_enabled_build_for_profile ( domain , profile_id ) return latest_enabled_build