Skip to content

Commit 0c597eb

Browse files
committed
[IMP] bi_sql_editor : Allow to use sum / avg operator on tree view
1 parent 99e67ed commit 0c597eb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

bi_sql_editor/migrations/16.0.2.0.0/post-migration.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
@openupgrade.migrate()
99
def migrate(env, version):
1010
for view in env["bi.sql.view"].search([("state", "=", "ui_valid")]):
11+
# create new Form view
1112
view.form_view_id = env["ir.ui.view"].create(view._prepare_form_view()).id
13+
# Update tree view, to add sum / avg option
14+
view.tree_view_id.write(view._prepare_tree_view())

bi_sql_editor/models/bi_sql_view_field.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,14 @@ def _prepare_tree_field(self):
265265
elif self.tree_visibility == "optional_show":
266266
visibility_text = 'optional="show"'
267267

268+
operator_text = ""
269+
if self.group_operator == "sum":
270+
operator_text = f'sum="{_("Total")}"'
271+
elif self.group_operator == "avg":
272+
operator_text = f'avg="{_("Average")}"'
273+
268274
return (
269-
f"""<field name="{self.name}" {visibility_text}"""
275+
f"""<field name="{self.name}" {visibility_text} {operator_text}"""
270276
f""" context="{self.field_context}"/>\n"""
271277
)
272278

0 commit comments

Comments
 (0)