Skip to content

Commit

Permalink
Merge PR #908 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Nov 24, 2024
2 parents f25baf7 + 58aa10b commit 9b910a5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bi_sql_editor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "BI SQL Editor",
"summary": "BI Views builder, based on Materialized or Normal SQL Views",
"version": "17.0.1.1.0",
"version": "17.0.2.0.0",
"license": "AGPL-3",
"category": "Reporting",
"author": "GRAP,Odoo Community Association (OCA)",
Expand Down
14 changes: 14 additions & 0 deletions bi_sql_editor/migrations/17.0.2.0.0/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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())
30 changes: 27 additions & 3 deletions bi_sql_editor/models/bi_sql_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class BiSQLView(models.Model):
view_order = fields.Char(
required=True,
default="pivot,graph,tree",
help="Comma-separated text. Possible values:" ' "graph", "pivot" or "tree"',
help="Comma-separated text. Possible values:"
' "graph", "pivot", "tree" or "form"',
)

query = fields.Text(
Expand Down Expand Up @@ -114,6 +115,7 @@ class BiSQLView(models.Model):
model_id = fields.Many2one(
string="Odoo Model", comodel_name="ir.model", readonly=True
)

# UI related fields
# 1. Editable fields, which can be set by the user (optional) before
# creating the UI elements
Expand All @@ -133,6 +135,11 @@ def _default_parent_menu_id(self):
)

# 2. Readonly fields, non editable by the user

form_view_id = fields.Many2one(
string="Odoo Form View", comodel_name="ir.ui.view", readonly=True
)

tree_view_id = fields.Many2one(
string="Odoo Tree View", comodel_name="ir.ui.view", readonly=True
)
Expand Down Expand Up @@ -183,9 +190,9 @@ def _check_view_order(self):
for rec in self:
if rec.view_order:
for vtype in rec.view_order.split(","):
if vtype not in ("graph", "pivot", "tree"):
if vtype not in ("graph", "pivot", "tree", "form"):
raise UserError(
_("Only graph, pivot or tree views are supported")
_("Only graph, pivot, tree or form views are supported")
)

# Compute Section
Expand Down Expand Up @@ -294,6 +301,7 @@ def button_create_sql_view_and_model(self):

def button_reset_to_model_valid(self):
views = self.filtered(lambda x: x.state == "ui_valid")
views.mapped("form_view_id").unlink()
views.mapped("tree_view_id").unlink()
views.mapped("graph_view_id").unlink()
views.mapped("pivot_view_id").unlink()
Expand Down Expand Up @@ -321,6 +329,7 @@ def button_set_draft(self):
return super().button_set_draft()

def button_create_ui(self):
self.form_view_id = self.env["ir.ui.view"].create(self._prepare_form_view()).id
self.tree_view_id = self.env["ir.ui.view"].create(self._prepare_tree_view()).id
self.graph_view_id = (
self.env["ir.ui.view"].create(self._prepare_graph_view()).id
Expand Down Expand Up @@ -412,6 +421,19 @@ def _prepare_rule(self):
"global": True,
}

def _prepare_form_view(self):
self.ensure_one()
return {
"name": self.name,
"type": "form",
"model": self.model_id.model,
"arch": """<?xml version="1.0"?>"""
"""<form><sheet><group string="Data" col="4">{}"""
"""</group></sheet></form>""".format(
"".join([x._prepare_form_field() for x in self.bi_sql_view_field_ids])
),
}

def _prepare_tree_view(self):
self.ensure_one()
return {
Expand Down Expand Up @@ -477,6 +499,8 @@ def _prepare_action(self):
self.ensure_one()
view_mode = self.view_order
first_view = view_mode.split(",")[0]
if first_view == "form":
view_id = self.form_view_id.id
if first_view == "tree":
view_id = self.tree_view_id.id
elif first_view == "pivot":
Expand Down
12 changes: 11 additions & 1 deletion bi_sql_editor/models/bi_sql_view_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def _prepare_model_field(self):
or False,
}

def _prepare_form_field(self):
self.ensure_one()
return f"""<field name="{self.name}" context="{self.field_context}"/>\n"""

def _prepare_tree_field(self):
self.ensure_one()
if self.tree_visibility == "unavailable":
Expand All @@ -251,8 +255,14 @@ def _prepare_tree_field(self):
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"""
)

Expand Down
1 change: 1 addition & 0 deletions bi_sql_editor/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
1 change: 1 addition & 0 deletions bi_sql_editor/views/view_bi_sql_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
/>
</group>
<group string="UI Instances">
<field name="form_view_id" />
<field name="tree_view_id" />
<field name="graph_view_id" />
<field name="pivot_view_id" />
Expand Down

0 comments on commit 9b910a5

Please sign in to comment.