mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[13.0][MIG] bi_view_editor
This commit is contained in:
@@ -60,7 +60,7 @@ class BveView(models.Model):
|
||||
line_ids = self._sync_lines_and_data(bve_view.data)
|
||||
bve_view.write({"line_ids": line_ids})
|
||||
|
||||
name = fields.Char(required=True, copy=False)
|
||||
name = fields.Char(required=True, copy=False, default="")
|
||||
model_name = fields.Char(compute="_compute_model_name", store=True)
|
||||
note = fields.Text(string="Notes")
|
||||
state = fields.Selection(
|
||||
@@ -100,7 +100,7 @@ class BveView(models.Model):
|
||||
)
|
||||
query = fields.Text(compute="_compute_sql_query")
|
||||
over_condition = fields.Text(
|
||||
states={"draft": [("readonly", False),],},
|
||||
states={"draft": [("readonly", False)]},
|
||||
readonly=True,
|
||||
help="Condition to be inserted in the OVER part "
|
||||
"of the ID's row_number function.\n"
|
||||
@@ -169,7 +169,7 @@ class BveView(models.Model):
|
||||
try:
|
||||
png_base64_image = base64.b64encode(graph.create_png())
|
||||
bve_view.er_diagram_image = png_base64_image
|
||||
except:
|
||||
except Exception:
|
||||
bve_view.er_diagram_image = False
|
||||
|
||||
def _create_view_arch(self):
|
||||
@@ -191,7 +191,7 @@ class BveView(models.Model):
|
||||
return '<field name="{}" {} />'.format(line.name, res)
|
||||
|
||||
bve_field_lines = self.field_ids.filtered(lambda l: l.in_list)
|
||||
return list(map(_get_field_attrs, bve_field_lines))
|
||||
return list(map(_get_field_attrs, bve_field_lines.sorted("sequence")))
|
||||
|
||||
def _create_bve_view(self):
|
||||
self.ensure_one()
|
||||
@@ -236,7 +236,7 @@ class BveView(models.Model):
|
||||
"model": self.model_name,
|
||||
"priority": 16,
|
||||
"arch": """<?xml version="1.0"?>
|
||||
<search string="Search BI View">
|
||||
<search>
|
||||
{}
|
||||
</search>
|
||||
""".format(
|
||||
@@ -254,7 +254,7 @@ class BveView(models.Model):
|
||||
"model": self.model_name,
|
||||
"priority": 16,
|
||||
"arch": """<?xml version="1.0"?>
|
||||
<tree string="List Analysis" create="false">
|
||||
<tree create="false">
|
||||
{}
|
||||
</tree>
|
||||
""".format(
|
||||
@@ -272,7 +272,6 @@ class BveView(models.Model):
|
||||
"name": self.name,
|
||||
"res_model": self.model_name,
|
||||
"type": "ir.actions.act_window",
|
||||
"view_type": "form",
|
||||
"view_mode": "tree,graph,pivot",
|
||||
"view_id": tree_view.id,
|
||||
"context": "{'service_name': '%s'}" % self.name,
|
||||
@@ -475,7 +474,7 @@ class BveView(models.Model):
|
||||
self.env["ir.model.access"]
|
||||
.sudo()
|
||||
.search(
|
||||
[("model_id", "=", line_model.id), ("perm_read", "=", True),]
|
||||
[("model_id", "=", line_model.id), ("perm_read", "=", True)]
|
||||
)
|
||||
)
|
||||
group_list = ""
|
||||
@@ -495,20 +494,18 @@ class BveView(models.Model):
|
||||
if not self.line_ids:
|
||||
raise ValidationError(_("No data to process."))
|
||||
|
||||
if any(not line.model_id for line in self.line_ids):
|
||||
invalid_lines = self.line_ids.filtered(lambda l: not l.model_id)
|
||||
missing_models = set(invalid_lines.mapped("model_name"))
|
||||
missing_models = ", ".join(missing_models)
|
||||
invalid_lines = self.line_ids.filtered(lambda l: not l.model_id)
|
||||
if invalid_lines:
|
||||
missing_models = ", ".join(set(invalid_lines.mapped("model_name")))
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Following models are missing: %s.\n"
|
||||
"Probably some modules were uninstalled." % (missing_models,)
|
||||
)
|
||||
)
|
||||
if any(not line.field_id for line in self.line_ids):
|
||||
invalid_lines = self.line_ids.filtered(lambda l: not l.field_id)
|
||||
missing_fields = set(invalid_lines.mapped("field_name"))
|
||||
missing_fields = ", ".join(missing_fields)
|
||||
invalid_lines = self.line_ids.filtered(lambda l: not l.field_id)
|
||||
if invalid_lines:
|
||||
missing_fields = ", ".join(set(invalid_lines.mapped("field_name")))
|
||||
raise ValidationError(
|
||||
_("Following fields are missing: {}.".format(missing_fields))
|
||||
)
|
||||
@@ -520,7 +517,6 @@ class BveView(models.Model):
|
||||
action["display_name"] = _("BI View")
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def copy(self, default=None):
|
||||
self.ensure_one()
|
||||
default = dict(default or {}, name=_("%s (copy)") % self.name)
|
||||
@@ -623,7 +619,9 @@ class BveView(models.Model):
|
||||
|
||||
@api.model
|
||||
def get_clean_list(self, data_dict):
|
||||
serialized_data = json.loads(data_dict)
|
||||
serialized_data = data_dict
|
||||
if type(data_dict) == str:
|
||||
serialized_data = json.loads(data_dict)
|
||||
table_alias_list = set()
|
||||
for item in serialized_data:
|
||||
if item.get("join_node", -1) in [-1, False]:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2015-2019 Onestein (<https://www.onestein.eu>)
|
||||
# Copyright 2015-2020 Onestein (<https://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
@@ -12,11 +12,11 @@ class BveViewLine(models.Model):
|
||||
name = fields.Char(compute="_compute_name")
|
||||
sequence = fields.Integer(default=1)
|
||||
bve_view_id = fields.Many2one("bve.view", ondelete="cascade")
|
||||
model_id = fields.Many2one("ir.model", string="Model")
|
||||
model_name = fields.Char(compute="_compute_model_name", store=True)
|
||||
table_alias = fields.Char()
|
||||
join_model_id = fields.Many2one("ir.model", string="Join Model")
|
||||
field_id = fields.Many2one("ir.model.fields", string="Field")
|
||||
model_id = fields.Many2one("ir.model")
|
||||
model_name = fields.Char(related="model_id.model", store=True, string="Model Name")
|
||||
table_alias = fields.Char(required=True)
|
||||
join_model_id = fields.Many2one("ir.model")
|
||||
field_id = fields.Many2one("ir.model.fields")
|
||||
field_name = fields.Char(compute="_compute_model_field_name", store=True)
|
||||
ttype = fields.Char(string="Type")
|
||||
description = fields.Char(translate=True)
|
||||
@@ -29,7 +29,7 @@ class BveViewLine(models.Model):
|
||||
measure = fields.Boolean()
|
||||
in_list = fields.Boolean()
|
||||
list_attr = fields.Selection(
|
||||
[("sum", "Sum"), ("avg", "Average"),], string="List Attribute", default="sum"
|
||||
[("sum", "Sum"), ("avg", "Average")], string="List Attribute", default="sum"
|
||||
)
|
||||
view_field_type = fields.Char(compute="_compute_view_field_type")
|
||||
|
||||
@@ -44,14 +44,13 @@ class BveViewLine(models.Model):
|
||||
@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):
|
||||
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):
|
||||
if line.join_model_id or line.ttype not in measure_types:
|
||||
err_msg = _("This field cannot be a measure.")
|
||||
raise ValidationError(err_msg)
|
||||
lines = self.filtered(lambda l: l.join_model_id or l.ttype in measure_types)
|
||||
if lines.filtered(lambda l: l.row or l.column):
|
||||
err_msg = _("This field cannot be a row or a column.")
|
||||
raise ValidationError(err_msg)
|
||||
if lines.filtered(lambda l: l.measure):
|
||||
err_msg = _("This field cannot be a measure.")
|
||||
raise ValidationError(err_msg)
|
||||
|
||||
@api.constrains("table_alias", "field_id")
|
||||
def _constrains_unique_fields_check(self):
|
||||
@@ -67,21 +66,17 @@ class BveViewLine(models.Model):
|
||||
|
||||
@api.depends("field_id", "sequence")
|
||||
def _compute_name(self):
|
||||
for line in self.filtered(lambda l: l.field_id):
|
||||
field_name = line.field_id.name
|
||||
line.name = "x_bve_{}_{}".format(line.table_alias, field_name)
|
||||
|
||||
@api.depends("model_id")
|
||||
def _compute_model_name(self):
|
||||
for line in self.filtered(lambda l: l.model_id):
|
||||
line.model_name = line.model_id.model
|
||||
for line in self:
|
||||
line.name = False
|
||||
if line.field_id:
|
||||
line.name = "x_bve_{}_{}".format(line.table_alias, line.field_id.name)
|
||||
|
||||
@api.depends("field_id")
|
||||
def _compute_model_field_name(self):
|
||||
for line in self.filtered(lambda l: l.field_id):
|
||||
field_name = line.description
|
||||
model_name = line.model_name
|
||||
line.field_name = "{} ({})".format(field_name, model_name)
|
||||
for line in self:
|
||||
line.field_name = False
|
||||
if line.field_id:
|
||||
line.field_name = "{} ({})".format(line.description, line.model_name)
|
||||
|
||||
def _prepare_field_vals(self):
|
||||
vals_list = []
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, models, registry
|
||||
from odoo import api, models
|
||||
|
||||
NO_BI_MODELS = ["fetchmail.server"]
|
||||
|
||||
@@ -212,25 +212,3 @@ class IrModel(models.Model):
|
||||
)
|
||||
fields_dict = list(map(dict_for_field, fields))
|
||||
return fields_dict
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if self.env.context and self.env.context.get("bve"):
|
||||
vals["state"] = "base"
|
||||
res = super().create(vals)
|
||||
|
||||
# this sql update is necessary since a write method here would
|
||||
# be not working (an orm constraint is restricting the modification
|
||||
# of the state field while updating ir.model)
|
||||
q = "UPDATE ir_model SET state = 'manual' WHERE id = %s"
|
||||
self.env.cr.execute(q, (res.id,))
|
||||
|
||||
# # update registry
|
||||
if self.env.context.get("bve"):
|
||||
# setup models; this reloads custom models in registry
|
||||
self.pool.setup_models(self._cr)
|
||||
|
||||
# signal that registry has changed
|
||||
registry(self.env.cr.dbname).signal_changes()
|
||||
|
||||
return res
|
||||
|
||||
@@ -17,7 +17,6 @@ def _bi_view(_name):
|
||||
_auto_init_orig = models.BaseModel._auto_init
|
||||
|
||||
|
||||
@api.model_cr_context
|
||||
def _auto_init(self):
|
||||
|
||||
# This monkey patch is meant to fix an error (probably
|
||||
|
||||
Reference in New Issue
Block a user