'Computes the WHERE clause needed to implement an OpenERP domain.
:param domain: the domain to compute
:type domain: list
:param active_test: whether the default filtering of records with ``active``
field set to ``False`` should be applied.
:return: the query expressing the given domain as provided in domain
:rtype: osv.query.Query'

@api.model
def _where_calc(self, domain, active_test=True):

    if (('active' in self._fields) and active_test and self._context.get('active_test', True)):
        if (not any(((item[0] == 'active') for item in domain))):
            domain = ([('active', '=', 1)] + domain)
    if domain:
        e = expression.expression(domain, self)
        tables = e.get_tables()
        (where_clause, where_params) = e.to_sql()
        where_clause = ([where_clause] if where_clause else [])
    else:
        (where_clause, where_params, tables) = ([], [], [('"%s"' % self._table)])
    return Query(tables, where_clause, where_params)
