mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] bi_sql_editor : from 15.0 to 16.0
- move menu and action in according view file - use new sql_request_abstract menu entry for SQL views configuration - Use sql_request_abstract primary tree view - Use sql_request_abstract primary form view - move has_grouped_changed in sql_request_abstract module - improve demo data - add default count value to display in pivot, if no pivot_measures are defined ; - set widget handle to sequence field - reorder fields in tree view and add optional hide for some fields - simplify : make field_description field required - improve : add optional='hide' and 'show' on tree visibility - replace obsolete base.menu_board_root by spreadsheet_dashboard entries - update translation
This commit is contained in:
committed by
OCA-git-bot
parent
d62f47fd19
commit
6be6f7d02f
@@ -117,8 +117,6 @@ class BiSQLView(models.Model):
|
||||
},
|
||||
)
|
||||
|
||||
has_group_changed = fields.Boolean(copy=False)
|
||||
|
||||
bi_sql_view_field_ids = fields.One2many(
|
||||
string="SQL Fields",
|
||||
comodel_name="bi.sql.view.field",
|
||||
@@ -203,6 +201,11 @@ class BiSQLView(models.Model):
|
||||
):
|
||||
action["pivot_measures"].append(field.name)
|
||||
|
||||
# If no measure are defined, we display by default the count
|
||||
# of the element, to avoid an empty view
|
||||
if not action["pivot_measures"]:
|
||||
action["pivot_measures"] = ["__count__"]
|
||||
|
||||
for field in rec.bi_sql_view_field_ids.filtered(
|
||||
lambda x: x.graph_type == "row"
|
||||
):
|
||||
@@ -238,14 +241,9 @@ class BiSQLView(models.Model):
|
||||
sql_view.technical_name,
|
||||
)
|
||||
|
||||
@api.onchange("group_ids")
|
||||
def onchange_group_ids(self):
|
||||
if self.state not in ("draft", "sql_valid"):
|
||||
self.has_group_changed = True
|
||||
|
||||
# Overload Section
|
||||
def write(self, vals):
|
||||
res = super(BiSQLView, self).write(vals)
|
||||
res = super().write(vals)
|
||||
if vals.get("sequence", False):
|
||||
for rec in self.filtered(lambda x: x.menu_id):
|
||||
rec.menu_id.sequence = rec.sequence
|
||||
@@ -260,7 +258,7 @@ class BiSQLView(models.Model):
|
||||
)
|
||||
)
|
||||
self.cron_id.unlink()
|
||||
return super(BiSQLView, self).unlink()
|
||||
return super().unlink()
|
||||
|
||||
def copy(self, default=None):
|
||||
self.ensure_one()
|
||||
@@ -271,7 +269,7 @@ class BiSQLView(models.Model):
|
||||
"technical_name": "%s_copy" % self.technical_name,
|
||||
}
|
||||
)
|
||||
return super(BiSQLView, self).copy(default=default)
|
||||
return super().copy(default=default)
|
||||
|
||||
# Action Section
|
||||
def button_create_sql_view_and_model(self):
|
||||
@@ -313,7 +311,6 @@ class BiSQLView(models.Model):
|
||||
# Drop ORM
|
||||
sql_view._drop_model_and_fields()
|
||||
|
||||
sql_view.has_group_changed = False
|
||||
super(BiSQLView, sql_view).button_set_draft()
|
||||
return True
|
||||
|
||||
@@ -636,7 +633,7 @@ class BiSQLView(models.Model):
|
||||
the database structure is done, to know fields type."""
|
||||
self.ensure_one()
|
||||
sql_view_field_obj = self.env["bi.sql.view.field"]
|
||||
columns = super(BiSQLView, self)._check_execution()
|
||||
columns = super()._check_execution()
|
||||
field_ids = []
|
||||
for column in columns:
|
||||
existing_field = self.bi_sql_view_field_ids.filtered(
|
||||
|
||||
@@ -32,7 +32,9 @@ class BiSQLViewField(models.Model):
|
||||
|
||||
_TREE_VISIBILITY_SELECTION = [
|
||||
("unavailable", "Unavailable"),
|
||||
("hidden", "Hidden"),
|
||||
("invisible", "Invisible"),
|
||||
("optional_hide", "Optional (hidden)"),
|
||||
("optional_show", "Optional (shown)"),
|
||||
("available", "Available"),
|
||||
]
|
||||
|
||||
@@ -91,7 +93,8 @@ class BiSQLViewField(models.Model):
|
||||
)
|
||||
|
||||
field_description = fields.Char(
|
||||
help="This will be used as the name" " of the Odoo field, displayed for users",
|
||||
help="This will be used as the name of the Odoo field, displayed for users",
|
||||
required=True,
|
||||
)
|
||||
|
||||
ttype = fields.Selection(
|
||||
@@ -142,41 +145,42 @@ class BiSQLViewField(models.Model):
|
||||
)
|
||||
|
||||
# Overload Section
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
field_without_prefix = vals["name"][2:]
|
||||
# guess field description
|
||||
field_description = re.sub(
|
||||
r"\w+",
|
||||
lambda m: m.group(0).capitalize(),
|
||||
field_without_prefix.replace("_id", "").replace("_", " "),
|
||||
)
|
||||
|
||||
# Guess ttype
|
||||
# Don't execute as simple .get() in the dict to manage
|
||||
# correctly the type 'character varying(x)'
|
||||
ttype = False
|
||||
for k, v in self._SQL_MAPPING.items():
|
||||
if k in vals["sql_type"]:
|
||||
ttype = v
|
||||
|
||||
# Guess many2one_model_id
|
||||
many2one_model_id = False
|
||||
if vals["sql_type"] == "integer" and (vals["name"][-3:] == "_id"):
|
||||
ttype = "many2one"
|
||||
model_name = self._model_mapping().get(field_without_prefix, "")
|
||||
many2one_model_id = (
|
||||
self.env["ir.model"].search([("model", "=", model_name)]).id
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
field_without_prefix = vals["name"][2:]
|
||||
# guess field description
|
||||
field_description = re.sub(
|
||||
r"\w+",
|
||||
lambda m: m.group(0).capitalize(),
|
||||
field_without_prefix.replace("_id", "").replace("_", " "),
|
||||
)
|
||||
|
||||
vals.update(
|
||||
{
|
||||
"ttype": ttype,
|
||||
"field_description": field_description,
|
||||
"many2one_model_id": many2one_model_id,
|
||||
}
|
||||
)
|
||||
return super(BiSQLViewField, self).create(vals)
|
||||
# Guess ttype
|
||||
# Don't execute as simple .get() in the dict to manage
|
||||
# correctly the type 'character varying(x)'
|
||||
ttype = False
|
||||
for k, v in self._SQL_MAPPING.items():
|
||||
if k in vals["sql_type"]:
|
||||
ttype = v
|
||||
|
||||
# Guess many2one_model_id
|
||||
many2one_model_id = False
|
||||
if vals["sql_type"] == "integer" and (vals["name"][-3:] == "_id"):
|
||||
ttype = "many2one"
|
||||
model_name = self._model_mapping().get(field_without_prefix, "")
|
||||
many2one_model_id = (
|
||||
self.env["ir.model"].search([("model", "=", model_name)]).id
|
||||
)
|
||||
|
||||
vals.update(
|
||||
{
|
||||
"ttype": ttype,
|
||||
"field_description": field_description,
|
||||
"many2one_model_id": many2one_model_id,
|
||||
}
|
||||
)
|
||||
return super().create(vals)
|
||||
|
||||
# Custom Section
|
||||
@api.model
|
||||
@@ -217,45 +221,39 @@ class BiSQLViewField(models.Model):
|
||||
|
||||
def _prepare_tree_field(self):
|
||||
self.ensure_one()
|
||||
res = ""
|
||||
if self.field_description and self.tree_visibility != "unavailable":
|
||||
res = """<field name="{}" {}/>""".format(
|
||||
self.name, self.tree_visibility == "hidden" and 'invisible="1"' or ""
|
||||
)
|
||||
return res
|
||||
if self.tree_visibility == "unavailable":
|
||||
return ""
|
||||
visibility_text = ""
|
||||
if self.tree_visibility == "invisible":
|
||||
visibility_text = 'invisible="1"'
|
||||
elif self.tree_visibility == "optional_hide":
|
||||
visibility_text = 'option="hide"'
|
||||
elif self.tree_visibility == "optional_show":
|
||||
visibility_text = 'option="show"'
|
||||
|
||||
return f"""<field name="{self.name}" {visibility_text}/>\n"""
|
||||
|
||||
def _prepare_graph_field(self):
|
||||
self.ensure_one()
|
||||
res = ""
|
||||
if self.graph_type and self.field_description:
|
||||
res = """<field name="{}" type="{}" />\n""".format(
|
||||
self.name, self.graph_type
|
||||
)
|
||||
return res
|
||||
if not self.graph_type:
|
||||
return ""
|
||||
return f"""<field name="{self.name}" type="{self.graph_type}" />\n"""
|
||||
|
||||
def _prepare_pivot_field(self):
|
||||
self.ensure_one()
|
||||
res = ""
|
||||
if self.field_description:
|
||||
graph_type_text = self.graph_type and 'type="%s"' % (self.graph_type) or ""
|
||||
res = """<field name="{}" {} />\n""".format(self.name, graph_type_text)
|
||||
return res
|
||||
graph_type_text = self.graph_type and f'type="{self.graph_type}"' or ""
|
||||
return f"""<field name="{self.name}" {graph_type_text} />\n"""
|
||||
|
||||
def _prepare_search_field(self):
|
||||
self.ensure_one()
|
||||
res = ""
|
||||
if self.field_description:
|
||||
res = """<field name="{}"/>\n""".format(self.name)
|
||||
return res
|
||||
return """<field name="{}"/>\n""".format(self.name)
|
||||
|
||||
def _prepare_search_filter_field(self):
|
||||
self.ensure_one()
|
||||
res = ""
|
||||
if self.field_description and self.is_group_by:
|
||||
res = """<filter name="group_by_%s" string="%s"
|
||||
context="{'group_by':'%s'}"/>\n""" % (
|
||||
self.name,
|
||||
self.field_description,
|
||||
self.name,
|
||||
)
|
||||
return res
|
||||
if not self.is_group_by:
|
||||
return ""
|
||||
return (
|
||||
f"""<filter name="group_by_{self.name}" """
|
||||
f"""string="{self.field_description}" """
|
||||
f"""context="{{'group_by':'{self.name}'}}"/>\n"""
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user