Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: BI View Editor
Entity: bve.view
Compute Method: _compute_sql_query
| Inputs | Method | Outputs |
|---|---|---|
|
- for bve_view in self: - tables_map = {} - select_str = "\n CAST(row_number() OVER ({}) as integer) AS id".format( - bve_view.over_condition or "" - ) - for line in bve_view.field_ids: - table = line.table_alias - select = line.field_id.name - as_name = line.name - select_str += f",\n {table}.{select} AS {as_name}" - - if line.table_alias not in tables_map: - table = self.env[line.field_id.model_id.model]._table - tables_map[line.table_alias] = table - seen = set() - from_str = "" - if not bve_view.relation_ids and bve_view.field_ids: - first_line = bve_view.field_ids[0] - table = tables_map[first_line.table_alias] - from_str = f"{table} AS {first_line.table_alias}" - for line in bve_view.relation_ids: - table = tables_map[line.table_alias] - table_format = f"{table} AS {line.table_alias}" - if not from_str: - from_str += table_format - seen.add(line.table_alias) - if line.table_alias not in seen: - seen.add(line.table_alias) - join_type = " LEFT" if line.left_join else "" - join_clause = ( - f"{join_type} JOIN {table_format} " - f"ON {line.join_node}.id = " - f"{line.table_alias}.{line.field_id.name}" - ) - from_str += f"\n{join_clause}" - if line.join_node not in seen: - from_str += "\n" - seen.add(line.join_node) - from_str += " LEFT" if line.left_join else "" - from_str += ( - f" JOIN {tables_map[line.join_node]} AS " - f"{line.join_node} " - f"ON {line.table_alias}.{line.field_id.name} = " - f"{line.join_node}.id" - ) - bve_view.query = f"""SELECT {select_str}\n\nFROM {from_str}""" |
|
