From 11deda8af902f9c61915882386c56c502367cecd Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Mon, 6 Jan 2025 16:50:17 -0500 Subject: [PATCH] [MIG] bi_view_editor: Migration to 18.0 --- bi_view_editor/__manifest__.py | 7 +-- bi_view_editor/models/bve_view.py | 45 +++++++-------- bi_view_editor/models/bve_view_line.py | 4 +- .../bi_view_editor/bi_view_editor.esm.js | 27 +++++---- bi_view_editor/tests/test_bi_view.py | 2 +- bi_view_editor/views/bve_view.xml | 56 +++++++++---------- requirements.txt | 1 + 7 files changed, 69 insertions(+), 73 deletions(-) diff --git a/bi_view_editor/__manifest__.py b/bi_view_editor/__manifest__.py index a20cc978b7..5186610d73 100644 --- a/bi_view_editor/__manifest__.py +++ b/bi_view_editor/__manifest__.py @@ -9,14 +9,13 @@ "license": "AGPL-3", "website": "https://github.com/OCA/reporting-engine", "category": "Productivity", - "version": "16.0.1.1.0", + "version": "18.0.1.1.0", "development_status": "Beta", "depends": [ + "spreadsheet_dashboard", "web", ], - "external_dependencies": { - "deb": ["graphviz"], - }, + "external_dependencies": {"deb": ["graphviz"], "python": ["pydot"]}, "data": [ "security/res_groups.xml", "security/ir.model.access.csv", diff --git a/bi_view_editor/models/bve_view.py b/bi_view_editor/models/bve_view.py index b6a12faf84..df914db6e5 100644 --- a/bi_view_editor/models/bve_view.py +++ b/bi_view_editor/models/bve_view.py @@ -100,7 +100,6 @@ def _inverse_serialized_data(self): ) query = fields.Text(compute="_compute_sql_query") over_condition = fields.Text( - states={"draft": [("readonly", False)]}, readonly=True, help="Condition to be inserted in the OVER part " "of the ID's row_number function.\n" @@ -111,7 +110,7 @@ def _inverse_serialized_data(self): er_diagram_image = fields.Binary(compute="_compute_er_diagram_image") _sql_constraints = [ - ("name_uniq", "unique(name)", _("Custom BI View names must be unique!")), + ("name_uniq", "unique(name)", "Custom BI View names must be unique!"), ] @api.depends("line_ids") @@ -190,7 +189,7 @@ def _get_field_attrs(line): res = attr and f'{attr}="{line.description}"' or "" return f'' - bve_field_lines = self.field_ids.filtered(lambda l: l.in_list) + bve_field_lines = self.field_ids.filtered(lambda line: line.in_list) return list(map(_get_field_attrs, bve_field_lines.sorted("sequence"))) def _create_bve_view(self): @@ -244,18 +243,16 @@ def _create_bve_view(self): tree_view = View.create( { "name": "Tree Analysis", - "type": "tree", + "type": "list", "model": self.model_name, "priority": 16, - "arch": """ - - {} - + "arch": """ + {} """.format("".join(self._create_tree_view_arch())), } ) - # set the Tree view as the default one + # set the List view as the default one action = ( self.env["ir.actions.act_window"] .sudo() @@ -264,9 +261,9 @@ def _create_bve_view(self): "name": self.name, "res_model": self.model_name, "type": "ir.actions.act_window", - "view_mode": "tree,graph,pivot", + "view_mode": "list,graph,pivot", "view_id": tree_view.id, - "context": "{'service_name': '%s'}" % self.name, + "context": "{'service_name': '" + self.name + "'}", } ) ) @@ -357,17 +354,13 @@ def _compute_sql_query(self): seen.add(line.table_alias) from_str += "\n" from_str += " LEFT" if line.left_join else "" - from_str += f" JOIN {table_format} ON {line.join_node}.id = {line.table_alias}.{line.field_id.name}" + from_str += f" JOIN {table_format} ON {line.join_node}.id = {line.table_alias}.{line.field_id.name}" # noqa: E501 if line.join_node not in seen: from_str += "\n" seen.add(line.join_node) from_str += " LEFT" if line.left_join else "" - from_str += f" JOIN {tables_map[line.join_node]} AS {line.join_node} ON {line.table_alias}.{line.field_id.name} = {line.join_node}.id" - bve_view.query = """SELECT %s\n\nFROM %s - """ % ( - AsIs(select_str), - AsIs(from_str), - ) + from_str += f" JOIN {tables_map[line.join_node]} AS {line.join_node} ON {line.table_alias}.{line.field_id.name} = {line.join_node}.id" # noqa: E501 + bve_view.query = f"""SELECT {AsIs(select_str)}\n\nFROM {AsIs(from_str)}""" def action_create(self): self.ensure_one() @@ -383,7 +376,7 @@ def action_create(self): self._create_sql_view() # create model and fields - bve_fields = self.line_ids.filtered(lambda l: not l.join_node) + bve_fields = self.line_ids.filtered(lambda line: not line.join_node) model = ( self.env["ir.model"] .sudo() @@ -440,7 +433,8 @@ def _check_groups_consistency(self): for group in access_records.mapped("group_id"): group_list += f" * {group.full_name}\n" msg_title = _( - 'The model "%s" cannot be accessed by users with the selected groups only.' + 'The model "%s" cannot be accessed ' + "by users with the selected groups only." ) % (line_model.name,) msg_details = _("At least one of the following groups must be added:") raise UserError( @@ -457,16 +451,17 @@ def _check_invalid_lines(self): if not self.line_ids: raise ValidationError(_("No data to process.")) - invalid_lines = self.line_ids.filtered(lambda l: not l.model_id) + invalid_lines = self.line_ids.filtered(lambda line: not line.model_id) if invalid_lines: missing_models = ", ".join(set(invalid_lines.mapped("model_name"))) raise ValidationError( _( - "Following models are missing: %s.\nProbably some modules were uninstalled." + "Following models are missing: %(missing_models)s.\n" + "Probably some modules were uninstalled." ) - % (missing_models,) + % {"missing_models": missing_models} ) - invalid_lines = self.line_ids.filtered(lambda l: not l.field_id) + invalid_lines = self.line_ids.filtered(lambda line: not line.field_id) if invalid_lines: missing_fields = ", ".join(set(invalid_lines.mapped("field_name"))) raise ValidationError( @@ -584,7 +579,7 @@ def _constraint_line_ids(self): @api.model def get_clean_list(self, data_dict): serialized_data = data_dict - if type(data_dict) == str: + if isinstance(data_dict, str): serialized_data = json.loads(data_dict) table_alias_list = set() for item in serialized_data: diff --git a/bi_view_editor/models/bve_view_line.py b/bi_view_editor/models/bve_view_line.py index 02f1a791bf..af993cf2df 100644 --- a/bi_view_editor/models/bve_view_line.py +++ b/bi_view_editor/models/bve_view_line.py @@ -44,11 +44,11 @@ def _compute_view_field_type(self): @api.constrains("row", "column", "measure") def _constrains_options_check(self): measure_types = ["float", "integer", "monetary"] - for line in self.filtered(lambda l: l.row or l.column): + for line in self.filtered(lambda x: x.row or x.column): if line.join_model_id or line.ttype in measure_types: err_msg = _("This field cannot be a row or a column.") raise ValidationError(err_msg) - for line in self.filtered(lambda l: l.measure): + for line in self.filtered(lambda x: x.measure): if line.join_model_id or line.ttype not in measure_types: err_msg = _("This field cannot be a measure.") raise ValidationError(err_msg) diff --git a/bi_view_editor/static/src/components/bi_view_editor/bi_view_editor.esm.js b/bi_view_editor/static/src/components/bi_view_editor/bi_view_editor.esm.js index a5110b456e..21dc3590d3 100644 --- a/bi_view_editor/static/src/components/bi_view_editor/bi_view_editor.esm.js +++ b/bi_view_editor/static/src/components/bi_view_editor/bi_view_editor.esm.js @@ -10,8 +10,17 @@ import {JoinNodeDialog} from "./join_node_dialog.esm"; import {registry} from "@web/core/registry"; import {standardFieldProps} from "@web/views/fields/standard_field_props"; import {useService} from "@web/core/utils/hooks"; +import {uniqueId} from "@web/core/utils/functions"; export class BiViewEditor extends Component { + static components = { + ModelList, + FieldList, + }; + static template = "bi_view_editor.Frame"; + static props = { + ...standardFieldProps, + }; setup() { this.state = useState({ models: [], @@ -55,7 +64,7 @@ export class BiViewEditor extends Component { field.column = typeof field.column === "undefined" ? false : field.column; field.measure = typeof field.measure === "undefined" ? false : field.measure; field.list = typeof field.list === "undefined" ? true : field.list; - field._id = typeof field._id === "undefined" ? _.uniqueId("node_") : field._id; + field._id = typeof field._id === "undefined" ? uniqueId("node_") : field._id; if (field.join_node) { field.join_left = typeof field.join_left === "undefined" ? false : field.join_left; @@ -155,7 +164,7 @@ export class BiViewEditor extends Component { this.updateValue(); } addField(field) { - const data = _.extend({}, field); + const data = {...field}; const field_data = this.state.fields; this.orm .call("ir.model", "get_join_nodes", [field_data, data]) @@ -201,17 +210,13 @@ export class BiViewEditor extends Component { } } updateValue() { - this.props.update(JSON.stringify(this.state.fields)); + // This.props.update(JSON.stringify(this.state.fields)); this.updateModels(); } } -BiViewEditor.template = "bi_view_editor.Frame"; -BiViewEditor.components = { - ModelList, - FieldList, -}; -BiViewEditor.props = { - ...standardFieldProps, + +export const BiViewEditorField = { + component: BiViewEditor, }; -registry.category("fields").add("BVEEditor", BiViewEditor); +registry.category("fields").add("BVEEditor", BiViewEditorField); diff --git a/bi_view_editor/tests/test_bi_view.py b/bi_view_editor/tests/test_bi_view.py index 477b027f3f..12de102af8 100644 --- a/bi_view_editor/tests/test_bi_view.py +++ b/bi_view_editor/tests/test_bi_view.py @@ -367,7 +367,7 @@ def test_19_field_selection(self): .search( [ ("model", "=", self.company_model_name), - ("name", "=", "base_onboarding_company_state"), + ("name", "=", "font"), ], limit=1, ) diff --git a/bi_view_editor/views/bve_view.xml b/bi_view_editor/views/bve_view.xml index 08bf3059df..1b04e7f1cb 100644 --- a/bi_view_editor/views/bve_view.xml +++ b/bi_view_editor/views/bve_view.xml @@ -3,7 +3,7 @@ Custom BI Views bve.view - tree,form + list,form

Click to create a Custom Query Object. @@ -20,7 +20,7 @@ --> @@ -28,15 +28,15 @@ bve.view - + - + @@ -47,14 +47,14 @@