Exemplo n.º 1
0
    def test_uses_balance_column(self):
        c_simple = qe.BalanceColumn()
        self.assertTrue(qx.uses_balance_column(c_simple))

        c_simple_not = qe.AccountColumn()
        self.assertFalse(qx.uses_balance_column(c_simple_not))

        c_subexpr = qc.EvalEqual(qe.BalanceColumn(), qc.EvalConstant(2012))
        self.assertTrue(qx.uses_balance_column(c_subexpr))

        c_subexpr_not = qc.EvalEqual(qe.AccountColumn(), qc.EvalConstant('Assets'))
        self.assertFalse(qx.uses_balance_column(c_subexpr_not))
Exemplo n.º 2
0
def get_matching_entries(entries, options_map, query):
    query_text = 'SELECT * ' + query
    parser = query_parser.Parser()
    parsed_query = parser.parse(query_text)
    c_from = None
    if parsed_query.from_clause:
        c_from = query_compile.compile_from(parsed_query.from_clause, query_env.FilterEntriesEnvironment())
    c_where = None
    if parsed_query.where_clause:
        c_where = query_compile.compile_expression(parsed_query.where_clause, query_env.FilterPostingsEnvironment())

    # Figure out if we need to compute balance.
    balance = None
    if c_where and query_execute.uses_balance_column(c_where):
        balance = inventory.Inventory()

    context = query_execute.RowContext()
    context.balance = balance
    

    # Initialize some global properties for use by some of the accessors.
    context.options_map = options_map
    context.account_types = options.get_account_types(options_map)
    context.open_close_map = getters.get_account_open_close(entries)
    #context.commodity_map = getters.get_commodity_map(entries)
    context.price_map = prices.build_price_map(entries) 

    if c_from is not None:
        filtered_entries = query_execute.filter_entries(c_from, entries, options_map)
    else:
        filtered_entries = entries
    return filtered_entries