def has_variable(formula, variable):
    """
    Function that detects if a formula contains an ID. It traverses the
    recursive structure checking for the field "id" in the dictionaries.

    :param formula: node element at the top of the formula
    :param variable: ID to search for
    :return: Boolean encoding if formula has id.
    """

    if 'condition' in formula:
        # Node is a condition, get the values of the sub classes and take a
        # disjunction of the results.

        return any([has_variable(x, variable) for x in formula['rules']])

    return formula['id'] == variable