[IMP] bi_sql_editor : Allow to use sum / avg operator on tree view

This commit is contained in:
Sylvain LE GAL
2024-01-12 01:12:26 +01:00
parent b2d4e1f3b3
commit 58aa10b900
2 changed files with 10 additions and 1 deletions

View File

@@ -8,4 +8,7 @@ from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
for view in env["bi.sql.view"].search([("state", "=", "ui_valid")]):
# create new Form view
view.form_view_id = env["ir.ui.view"].create(view._prepare_form_view()).id
# Update tree view, to add sum / avg option
view.tree_view_id.write(view._prepare_tree_view())

View File

@@ -255,8 +255,14 @@ class BiSQLViewField(models.Model):
elif self.tree_visibility == "optional_show":
visibility_text = 'optional="show"'
operator_text = ""
if self.group_operator == "sum":
operator_text = f'sum="{_("Total")}"'
elif self.group_operator == "avg":
operator_text = f'avg="{_("Average")}"'
return (
f"""<field name="{self.name}" {visibility_text}"""
f"""<field name="{self.name}" {visibility_text} {operator_text}"""
f""" context="{self.field_context}"/>\n"""
)