mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
bi_view_editor: window functions without ORDER BY clause do not have reliable behavior
This commit is contained in:
@@ -98,6 +98,19 @@ class BveView(models.Model):
|
||||
compute='_compute_users',
|
||||
store=True)
|
||||
query = fields.Text(compute='_compute_sql_query')
|
||||
over_condition = fields.Text(
|
||||
states={
|
||||
'draft': [
|
||||
('readonly', False),
|
||||
],
|
||||
},
|
||||
readonly=True,
|
||||
help="Condition to be inserted in the OVER part "
|
||||
"of the ID's row_number function.\n"
|
||||
"For instance, 'ORDER BY t1.id' would create "
|
||||
"IDs ordered in the same way as t1's IDs; otherwise "
|
||||
"IDs are assigned with no specific order.",
|
||||
)
|
||||
er_diagram_image = fields.Binary(compute='_compute_er_diagram_image')
|
||||
|
||||
_sql_constraints = [
|
||||
@@ -285,11 +298,12 @@ class BveView(models.Model):
|
||||
self.env.cr.execute('CREATE or REPLACE VIEW %s as (%s)', (
|
||||
AsIs(view_name), AsIs(query), ))
|
||||
|
||||
@api.depends('line_ids', 'state')
|
||||
@api.depends('line_ids', 'state', 'over_condition')
|
||||
def _compute_sql_query(self):
|
||||
for bve_view in self:
|
||||
tables_map = {}
|
||||
select_str = '\n CAST(row_number() OVER () as integer) AS id'
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user