diff --git a/bi_sql_editor/__manifest__.py b/bi_sql_editor/__manifest__.py index 7158a635b6..63a56db780 100644 --- a/bi_sql_editor/__manifest__.py +++ b/bi_sql_editor/__manifest__.py @@ -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)", diff --git a/bi_sql_editor/migrations/17.0.2.0.0/end-migration.py b/bi_sql_editor/migrations/17.0.2.0.0/end-migration.py new file mode 100644 index 0000000000..2503c9c596 --- /dev/null +++ b/bi_sql_editor/migrations/17.0.2.0.0/end-migration.py @@ -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()) diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index e1b38f71d2..b24b20290d 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/bi_sql_editor/models/bi_sql_view.py @@ -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 @@ 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 ) @@ -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 @@ -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() @@ -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 @@ -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": """""" + """
""".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 @@ 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": diff --git a/bi_sql_editor/models/bi_sql_view_field.py b/bi_sql_editor/models/bi_sql_view_field.py index f098f20c28..59fab39b3a 100644 --- a/bi_sql_editor/models/bi_sql_view_field.py +++ b/bi_sql_editor/models/bi_sql_view_field.py @@ -239,6 +239,10 @@ def _prepare_model_field(self): or False, } + def _prepare_form_field(self): + self.ensure_one() + return f"""