Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17.0 imp bi sql editor allow form view port 839 #908

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
)

# 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 @@
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_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 @@
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 @@
"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 @@
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

Check warning on line 503 in bi_sql_editor/models/bi_sql_view.py

View check run for this annotation

Codecov / codecov/patch

bi_sql_editor/models/bi_sql_view.py#L503

Added line #L503 was not covered by tests
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 @@
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 @@
elif self.tree_visibility == "optional_show":
visibility_text = 'optional="show"'

operator_text = ""
if self.group_operator == "sum":
operator_text = f'sum="{_("Total")}"'

Check warning on line 260 in bi_sql_editor/models/bi_sql_view_field.py

View check run for this annotation

Codecov / codecov/patch

bi_sql_editor/models/bi_sql_view_field.py#L260

Added line #L260 was not covered by tests
elif self.group_operator == "avg":
operator_text = f'avg="{_("Average")}"'

Check warning on line 262 in bi_sql_editor/models/bi_sql_view_field.py

View check run for this annotation

Codecov / codecov/patch

bi_sql_editor/models/bi_sql_view_field.py#L262

Added line #L262 was not covered by tests

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
Loading