mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
@@ -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)",
|
||||
|
||||
14
bi_sql_editor/migrations/17.0.2.0.0/end-migration.py
Normal file
14
bi_sql_editor/migrations/17.0.2.0.0/end-migration.py
Normal file
@@ -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())
|
||||
@@ -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(
|
||||
@@ -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
|
||||
@@ -133,6 +135,11 @@ class BiSQLView(models.Model):
|
||||
)
|
||||
|
||||
# 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
|
||||
)
|
||||
@@ -183,9 +190,9 @@ class BiSQLView(models.Model):
|
||||
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
|
||||
@@ -294,6 +301,7 @@ class BiSQLView(models.Model):
|
||||
|
||||
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()
|
||||
@@ -321,6 +329,7 @@ class BiSQLView(models.Model):
|
||||
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
|
||||
@@ -412,6 +421,19 @@ class BiSQLView(models.Model):
|
||||
"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 {
|
||||
@@ -477,6 +499,8 @@ class BiSQLView(models.Model):
|
||||
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":
|
||||
|
||||
@@ -239,6 +239,10 @@ class BiSQLViewField(models.Model):
|
||||
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":
|
||||
@@ -251,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"""
|
||||
)
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user