Browse Source

[WIP] imp bi_sql_editor

14.0-report-py3o-pr-506
Sylvain LE GAL 5 years ago
committed by David James
parent
commit
a3cf870117
  1. 35
      bi_sql_editor/models/bi_sql_view.py
  2. 22
      bi_sql_editor/models/bi_sql_view_field.py
  3. 5
      bi_sql_editor/views/view_bi_sql_view.xml

35
bi_sql_editor/models/bi_sql_view.py

@ -8,7 +8,7 @@ from psycopg2 import ProgrammingError
from odoo import _, api, fields, models, SUPERUSER_ID
from odoo.exceptions import UserError
from odoo.tools import pycompat, sql
from odoo.tools import pycompat, safe_eval, sql
from odoo.addons.base.models.ir_model import IrModel
_logger = logging.getLogger(__name__)
@ -120,6 +120,10 @@ class BiSQLView(models.Model):
'sql_valid': [('readonly', False)],
})
computed_action_context = fields.Text(
compute="_compute_computed_action_context",
string="Computed Action Context")
action_context = fields.Text(
string="Action Context", default="{}", readonly=True,
help="Define here a context that will be used"
@ -127,6 +131,7 @@ class BiSQLView(models.Model):
states={
'draft': [('readonly', False)],
'sql_valid': [('readonly', False)],
'model_valid': [('readonly', False)],
})
has_group_changed = fields.Boolean(copy=False)
@ -192,6 +197,29 @@ class BiSQLView(models.Model):
'Only graph, pivot or tree views are supported'))
# Compute Section
@api.depends("bi_sql_view_field_ids.graph_type")
@api.multi
def _compute_computed_action_context(self):
for rec in self:
action = {
"pivot_measures": [],
"pivot_row_groupby": [],
"pivot_column_groupby": [],
}
for field in rec.bi_sql_view_field_ids.filtered(
lambda x: x.graph_type == "measure"):
action["pivot_measures"].append(field.name)
for field in rec.bi_sql_view_field_ids.filtered(
lambda x: x.graph_type == "row"):
action["pivot_row_groupby"].append(field.name)
for field in rec.bi_sql_view_field_ids.filtered(
lambda x: x.graph_type == "col"):
action["pivot_column_groupby"].append(field.name)
rec.computed_action_context = str(action)
@api.depends('is_materialized')
@api.multi
def _compute_materialized_text(self):
@ -453,6 +481,9 @@ class BiSQLView(models.Model):
view_id = self.pivot_view_id.id
else:
view_id = self.graph_view_id.id
action = safe_eval(self.computed_action_context)
for k, v in safe_eval(self.action_context).items():
action[k] = v
return {
'name': self._prepare_action_name(),
'res_model': self.model_id.model,
@ -460,7 +491,7 @@ class BiSQLView(models.Model):
'view_mode': view_mode,
'view_id': view_id,
'search_view_id': self.search_view_id.id,
'context': self.action_context,
'context': str(action),
}
@api.multi

22
bi_sql_editor/models/bi_sql_view_field.py

@ -118,7 +118,7 @@ class BiSQLViewField(models.Model):
sql_field.bi_sql_view_id.view_name, sql_field.name)
# Overload Section
@api.multi
@api.model
def create(self, vals):
field_without_prefix = vals['name'][2:]
# guess field description
@ -201,7 +201,7 @@ class BiSQLViewField(models.Model):
self.ensure_one()
res = ''
if self.graph_type and self.field_description:
res = """<field name="{}" type="{}" />""".format(
res = """<field name="{}" type="{}" />\n""".format(
self.name, self.graph_type)
return res
@ -209,9 +209,11 @@ class BiSQLViewField(models.Model):
def _prepare_pivot_field(self):
self.ensure_one()
res = ''
if self.graph_type and self.field_description:
res = """<field name="{}" type="{}" />""".format(
self.name, self.graph_type)
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
@api.multi
@ -219,7 +221,7 @@ class BiSQLViewField(models.Model):
self.ensure_one()
res = ''
if self.field_description:
res = """<field name="{}"/>""".format(self.name)
res = """<field name="{}"/>\n""".format(self.name)
return res
@api.multi
@ -227,10 +229,8 @@ class BiSQLViewField(models.Model):
self.ensure_one()
res = ''
if self.field_description and self.is_group_by:
res = \
"""<filter name="%s" string="%s"
context="{'group_by':'%s'}"/>""" % (
self.field_description.lower().replace(' ', '_'),
self.field_description, self.name
res = """<filter name="group_by_%s" string="%s"
context="{'group_by':'%s'}"/>\n""" % (
self.name, self.field_description, self.name
)
return res

5
bi_sql_editor/views/view_bi_sql_view.xml

@ -107,7 +107,10 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
</group>
</page>
<page string="Action Settings">
<group string="Context">
<group string="Computed Context">
<field name="computed_action_context" nolabel="1" colspan="4"/>
</group>
<group string="Custom Context">
<field name="action_context" nolabel="1" colspan="4"/>
</group>
</page>

Loading…
Cancel
Save