Skip to content

Commit 20ac40e

Browse files
astirpehuguesdk
authored andcommitted
[13.0][MIG] bi_view_editor
1 parent 7c21bbd commit 20ac40e

16 files changed

+136
-230
lines changed

bi_view_editor/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from . import models
44
from . import wizard
5-
from .hooks import post_load, uninstall_hook
5+
from .hooks import uninstall_hook

bi_view_editor/__manifest__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
"license": "AGPL-3",
1010
"website": "https://github.com/OCA/reporting-engine",
1111
"category": "Reporting",
12-
"version": "12.0.1.0.0",
12+
"version": "13.0.1.0.0",
1313
"development_status": "Beta",
14-
"depends": ["web",],
14+
"depends": ["web"],
1515
"data": [
1616
"security/ir.model.access.csv",
1717
"security/rules.xml",
1818
"templates/assets_template.xml",
1919
"views/bve_view.xml",
2020
],
2121
"qweb": ["static/src/xml/bi_view_editor.xml"],
22-
"post_load": "post_load",
2322
"uninstall_hook": "uninstall_hook",
2423
"installable": True,
2524
}

bi_view_editor/hooks.py

-48
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,6 @@
11
# Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
import logging
5-
6-
from odoo import SUPERUSER_ID, api, modules
7-
from odoo.tools import existing_tables, topological_sort
8-
9-
_logger = logging.getLogger(__name__)
10-
11-
12-
def _bi_view(_name):
13-
return _name.startswith("x_bve.")
14-
15-
16-
def post_load():
17-
def check_tables_exist(self, cr):
18-
"""
19-
Verify that all tables are present and try to initialize
20-
those that are missing.
21-
"""
22-
# This monkey patch is meant to avoid that the _logger writes
23-
# warning and error messages, while running an update all,
24-
# in case the model is a bi-view-generated model.
25-
26-
env = api.Environment(cr, SUPERUSER_ID, {})
27-
table2model = {
28-
model._table: name
29-
for name, model in env.items()
30-
if not model._abstract and not _bi_view(name) # here is the patch
31-
}
32-
missing_tables = set(table2model).difference(existing_tables(cr, table2model))
33-
34-
if missing_tables:
35-
missing = {table2model[table] for table in missing_tables}
36-
_logger.warning("Models have no table: %s.", ", ".join(missing))
37-
# recreate missing tables following model dependencies
38-
deps = {name: model._depends for name, model in env.items()}
39-
for name in topological_sort(deps):
40-
if name in missing:
41-
_logger.info("Recreate table of model %s.", name)
42-
env[name].init()
43-
# check again, and log errors if tables are still missing
44-
missing_tables = set(table2model).difference(
45-
existing_tables(cr, table2model)
46-
)
47-
for table in missing_tables:
48-
_logger.error("Model %s has no table.", table2model[table])
49-
50-
modules.registry.Registry.check_tables_exist = check_tables_exist
51-
524

535
def uninstall_hook(cr, registry):
546
# delete dirty data that could cause problems

bi_view_editor/i18n/nl.po

100755100644
File mode changed.

bi_view_editor/models/bve_view.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _inverse_serialized_data(self):
6060
line_ids = self._sync_lines_and_data(bve_view.data)
6161
bve_view.write({"line_ids": line_ids})
6262

63-
name = fields.Char(required=True, copy=False)
63+
name = fields.Char(required=True, copy=False, default="")
6464
model_name = fields.Char(compute="_compute_model_name", store=True)
6565
note = fields.Text(string="Notes")
6666
state = fields.Selection(
@@ -100,7 +100,7 @@ def _inverse_serialized_data(self):
100100
)
101101
query = fields.Text(compute="_compute_sql_query")
102102
over_condition = fields.Text(
103-
states={"draft": [("readonly", False),],},
103+
states={"draft": [("readonly", False)]},
104104
readonly=True,
105105
help="Condition to be inserted in the OVER part "
106106
"of the ID's row_number function.\n"
@@ -169,7 +169,7 @@ def _compute_er_diagram_image(self):
169169
try:
170170
png_base64_image = base64.b64encode(graph.create_png())
171171
bve_view.er_diagram_image = png_base64_image
172-
except:
172+
except Exception:
173173
bve_view.er_diagram_image = False
174174

175175
def _create_view_arch(self):
@@ -191,7 +191,7 @@ def _get_field_attrs(line):
191191
return '<field name="{}" {} />'.format(line.name, res)
192192

193193
bve_field_lines = self.field_ids.filtered(lambda l: l.in_list)
194-
return list(map(_get_field_attrs, bve_field_lines))
194+
return list(map(_get_field_attrs, bve_field_lines.sorted("sequence")))
195195

196196
def _create_bve_view(self):
197197
self.ensure_one()
@@ -236,7 +236,7 @@ def _create_bve_view(self):
236236
"model": self.model_name,
237237
"priority": 16,
238238
"arch": """<?xml version="1.0"?>
239-
<search string="Search BI View">
239+
<search>
240240
{}
241241
</search>
242242
""".format(
@@ -254,7 +254,7 @@ def _create_bve_view(self):
254254
"model": self.model_name,
255255
"priority": 16,
256256
"arch": """<?xml version="1.0"?>
257-
<tree string="List Analysis" create="false">
257+
<tree create="false">
258258
{}
259259
</tree>
260260
""".format(
@@ -272,7 +272,6 @@ def _create_bve_view(self):
272272
"name": self.name,
273273
"res_model": self.model_name,
274274
"type": "ir.actions.act_window",
275-
"view_type": "form",
276275
"view_mode": "tree,graph,pivot",
277276
"view_id": tree_view.id,
278277
"context": "{'service_name': '%s'}" % self.name,
@@ -475,7 +474,7 @@ def _check_groups_consistency(self):
475474
self.env["ir.model.access"]
476475
.sudo()
477476
.search(
478-
[("model_id", "=", line_model.id), ("perm_read", "=", True),]
477+
[("model_id", "=", line_model.id), ("perm_read", "=", True)]
479478
)
480479
)
481480
group_list = ""
@@ -495,20 +494,18 @@ def _check_invalid_lines(self):
495494
if not self.line_ids:
496495
raise ValidationError(_("No data to process."))
497496

498-
if any(not line.model_id for line in self.line_ids):
499-
invalid_lines = self.line_ids.filtered(lambda l: not l.model_id)
500-
missing_models = set(invalid_lines.mapped("model_name"))
501-
missing_models = ", ".join(missing_models)
497+
invalid_lines = self.line_ids.filtered(lambda l: not l.model_id)
498+
if invalid_lines:
499+
missing_models = ", ".join(set(invalid_lines.mapped("model_name")))
502500
raise ValidationError(
503501
_(
504502
"Following models are missing: %s.\n"
505503
"Probably some modules were uninstalled." % (missing_models,)
506504
)
507505
)
508-
if any(not line.field_id for line in self.line_ids):
509-
invalid_lines = self.line_ids.filtered(lambda l: not l.field_id)
510-
missing_fields = set(invalid_lines.mapped("field_name"))
511-
missing_fields = ", ".join(missing_fields)
506+
invalid_lines = self.line_ids.filtered(lambda l: not l.field_id)
507+
if invalid_lines:
508+
missing_fields = ", ".join(set(invalid_lines.mapped("field_name")))
512509
raise ValidationError(
513510
_("Following fields are missing: {}.".format(missing_fields))
514511
)
@@ -520,7 +517,6 @@ def open_view(self):
520517
action["display_name"] = _("BI View")
521518
return action
522519

523-
@api.multi
524520
def copy(self, default=None):
525521
self.ensure_one()
526522
default = dict(default or {}, name=_("%s (copy)") % self.name)
@@ -623,7 +619,9 @@ def _constraint_line_ids(self):
623619

624620
@api.model
625621
def get_clean_list(self, data_dict):
626-
serialized_data = json.loads(data_dict)
622+
serialized_data = data_dict
623+
if type(data_dict) == str:
624+
serialized_data = json.loads(data_dict)
627625
table_alias_list = set()
628626
for item in serialized_data:
629627
if item.get("join_node", -1) in [-1, False]:

bi_view_editor/models/bve_view_line.py

+22-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
1+
# Copyright 2015-2020 Onestein (<https://www.onestein.eu>)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
from odoo import _, api, fields, models
@@ -12,11 +12,11 @@ class BveViewLine(models.Model):
1212
name = fields.Char(compute="_compute_name")
1313
sequence = fields.Integer(default=1)
1414
bve_view_id = fields.Many2one("bve.view", ondelete="cascade")
15-
model_id = fields.Many2one("ir.model", string="Model")
16-
model_name = fields.Char(compute="_compute_model_name", store=True)
17-
table_alias = fields.Char()
18-
join_model_id = fields.Many2one("ir.model", string="Join Model")
19-
field_id = fields.Many2one("ir.model.fields", string="Field")
15+
model_id = fields.Many2one("ir.model")
16+
model_name = fields.Char(related="model_id.model", store=True, string="Model Name")
17+
table_alias = fields.Char(required=True)
18+
join_model_id = fields.Many2one("ir.model")
19+
field_id = fields.Many2one("ir.model.fields")
2020
field_name = fields.Char(compute="_compute_model_field_name", store=True)
2121
ttype = fields.Char(string="Type")
2222
description = fields.Char(translate=True)
@@ -29,7 +29,7 @@ class BveViewLine(models.Model):
2929
measure = fields.Boolean()
3030
in_list = fields.Boolean()
3131
list_attr = fields.Selection(
32-
[("sum", "Sum"), ("avg", "Average"),], string="List Attribute", default="sum"
32+
[("sum", "Sum"), ("avg", "Average")], string="List Attribute", default="sum"
3333
)
3434
view_field_type = fields.Char(compute="_compute_view_field_type")
3535

@@ -44,14 +44,13 @@ def _compute_view_field_type(self):
4444
@api.constrains("row", "column", "measure")
4545
def _constrains_options_check(self):
4646
measure_types = ["float", "integer", "monetary"]
47-
for line in self.filtered(lambda l: l.row or l.column):
48-
if line.join_model_id or line.ttype in measure_types:
49-
err_msg = _("This field cannot be a row or a column.")
50-
raise ValidationError(err_msg)
51-
for line in self.filtered(lambda l: l.measure):
52-
if line.join_model_id or line.ttype not in measure_types:
53-
err_msg = _("This field cannot be a measure.")
54-
raise ValidationError(err_msg)
47+
lines = self.filtered(lambda l: l.join_model_id or l.ttype in measure_types)
48+
if lines.filtered(lambda l: l.row or l.column):
49+
err_msg = _("This field cannot be a row or a column.")
50+
raise ValidationError(err_msg)
51+
if lines.filtered(lambda l: l.measure):
52+
err_msg = _("This field cannot be a measure.")
53+
raise ValidationError(err_msg)
5554

5655
@api.constrains("table_alias", "field_id")
5756
def _constrains_unique_fields_check(self):
@@ -67,21 +66,17 @@ def _constrains_unique_fields_check(self):
6766

6867
@api.depends("field_id", "sequence")
6968
def _compute_name(self):
70-
for line in self.filtered(lambda l: l.field_id):
71-
field_name = line.field_id.name
72-
line.name = "x_bve_{}_{}".format(line.table_alias, field_name)
73-
74-
@api.depends("model_id")
75-
def _compute_model_name(self):
76-
for line in self.filtered(lambda l: l.model_id):
77-
line.model_name = line.model_id.model
69+
for line in self:
70+
line.name = False
71+
if line.field_id:
72+
line.name = "x_bve_{}_{}".format(line.table_alias, line.field_id.name)
7873

7974
@api.depends("field_id")
8075
def _compute_model_field_name(self):
81-
for line in self.filtered(lambda l: l.field_id):
82-
field_name = line.description
83-
model_name = line.model_name
84-
line.field_name = "{} ({})".format(field_name, model_name)
76+
for line in self:
77+
line.field_name = False
78+
if line.field_id:
79+
line.field_name = "{} ({})".format(line.description, line.model_name)
8580

8681
def _prepare_field_vals(self):
8782
vals_list = []

bi_view_editor/models/ir_model.py

+1-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from collections import defaultdict
55

6-
from odoo import api, models, registry
6+
from odoo import api, models
77

88
NO_BI_MODELS = ["fetchmail.server"]
99

@@ -212,25 +212,3 @@ def get_fields(self, model_id):
212212
)
213213
fields_dict = list(map(dict_for_field, fields))
214214
return fields_dict
215-
216-
@api.model
217-
def create(self, vals):
218-
if self.env.context and self.env.context.get("bve"):
219-
vals["state"] = "base"
220-
res = super().create(vals)
221-
222-
# this sql update is necessary since a write method here would
223-
# be not working (an orm constraint is restricting the modification
224-
# of the state field while updating ir.model)
225-
q = "UPDATE ir_model SET state = 'manual' WHERE id = %s"
226-
self.env.cr.execute(q, (res.id,))
227-
228-
# # update registry
229-
if self.env.context.get("bve"):
230-
# setup models; this reloads custom models in registry
231-
self.pool.setup_models(self._cr)
232-
233-
# signal that registry has changed
234-
registry(self.env.cr.dbname).signal_changes()
235-
236-
return res

bi_view_editor/models/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def _bi_view(_name):
1717
_auto_init_orig = models.BaseModel._auto_init
1818

1919

20-
@api.model_cr_context
2120
def _auto_init(self):
2221

2322
# This monkey patch is meant to fix an error (probably

bi_view_editor/readme/USAGE.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ A more advanced UI is also available under the "Details" tab. It provides extra
2222
possibilities for more advanced users, like to use LEFT JOIN instead of the
2323
default INNER JOIN.
2424

25-
It also possible to improve the IDs generation for new views by adding an `Over Condition` in the "SQL" tab, see https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS for further details.
26-
For instance, an ORDER BY clause helps preventing unreliable behavior when filtering the generated views.
25+
It also possible to improve the IDs generation for new views by adding an
26+
`Over Condition` in the "SQL" tab, see https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS
27+
for further details.
28+
For instance, an ORDER BY clause helps preventing unreliable behavior when
29+
filtering the generated views.

bi_view_editor/static/src/css/bve.css

-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@
159159
width: 175px;
160160
}
161161

162-
.oe_form_field_bi_editor .context-menu .checkbox {
163-
margin-top: 0px;
164-
margin-bottom: 0px;
165-
}
166-
167162
.oe_form_field_bi_editor .context-menu .checkbox label {
168163
display: block;
169164
}

0 commit comments

Comments
 (0)