Skip to content

Commit

Permalink
[MIG] bi_view_editor: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cormaza committed Jan 7, 2025
1 parent 4c00443 commit 11deda8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 73 deletions.
7 changes: 3 additions & 4 deletions bi_view_editor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 20 additions & 25 deletions bi_view_editor/models/bve_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -190,7 +189,7 @@ def _get_field_attrs(line):
res = attr and f'{attr}="{line.description}"' or ""
return f'<field name="{line.name}" {res} />'

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):
Expand Down Expand Up @@ -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": """<?xml version="1.0"?>
<tree create="false">
{}
</tree>
"arch": """<?xml version="1.0"?> <list create="false">
{}</list>
""".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()
Expand All @@ -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 + "'}",
}
)
)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions bi_view_editor/models/bve_view_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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);
2 changes: 1 addition & 1 deletion bi_view_editor/tests/test_bi_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Loading

0 comments on commit 11deda8

Please sign in to comment.