'Returns (query_from, query_where, query_params).'

def get_sql(self):

    from odoo.osv.expression import get_alias_from_query
    tables_to_process = list(self.tables)
    alias_mapping = self._get_alias_mapping()
    from_clause = []
    from_params = []
    def add_joins_for_table(lhs):
        for (rhs, lhs_col, rhs_col, join) in self.joins.get(lhs, []):
            tables_to_process.remove(alias_mapping[rhs])
            from_clause.append(('    %s    %s    ON    ("%s"."%s"    =    "%s"."%s"' % (join, alias_mapping[rhs], lhs, lhs_col, rhs, rhs_col)))
            extra = self.extras.get((lhs, (rhs, lhs_col, rhs_col, join)))
            if extra:
                if extra[0]:
                    from_clause.append('    AND    ')
                    from_clause.append(extra[0])
                if extra[1]:
                    from_params.extend(extra[1])
            from_clause.append(')')
            add_joins_for_table(rhs)
    for (pos, table) in enumerate(tables_to_process):
        if (pos > 0):
            from_clause.append(',')
        from_clause.append(table)
        table_alias = get_alias_from_query(table)[1]
        if (table_alias in self.joins):
            add_joins_for_table(table_alias)
    return (''.join(from_clause), '    AND    '.join(self.where_clause), (from_params + self.where_clause_params))
