Browse Source

Merge pull request #4 from Eficent/9.0-mig-bi_sql_editor-imp

[IMP]bi_sql_editor. Select View Order.
pull/148/head
Juan José Scarafía 7 years ago
committed by GitHub
parent
commit
48978f4cc0
  1. 32
      bi_sql_editor/models/bi_sql_view.py
  2. 1
      bi_sql_editor/views/view_bi_sql_view.xml

32
bi_sql_editor/models/bi_sql_view.py

@ -59,6 +59,14 @@ class BiSQLView(models.Model):
state = fields.Selection(selection_add=_STATE_SQL_EDITOR)
view_order = fields.Char(string='View Order',
required=True,
readonly=False,
states={'ui_valid': [('readonly', True)]},
default="pivot,graph,tree",
help='Comma-separated text. Possible values:'
' "graph", "pivot" or "tree"')
query = fields.Text(
help="SQL Request that will be inserted as the view. Take care to :\n"
" * set a name for all your selected fields, specially if you use"
@ -113,6 +121,16 @@ class BiSQLView(models.Model):
rule_id = fields.Many2one(
string='Odoo Rule', comodel_name='ir.rule', readonly=True)
@api.constrains('view_order')
@api.multi
def _check_view_order(self):
for rec in self:
if rec.view_order:
for vtype in rec.view_order.split(','):
if vtype not in ('graph', 'pivot', 'tree'):
raise UserError(_(
'Only graph, pivot or tree views are supported'))
# Compute Section
@api.depends('is_materialized')
@api.multi
@ -233,7 +251,7 @@ class BiSQLView(models.Model):
'type': 'ir.actions.act_window',
'res_model': self.model_id.model,
'search_view_id': self.search_view_id.id,
'view_mode': 'graph,pivot,tree',
'view_mode': self.action_id.view_mode,
}
# Prepare Function
@ -357,12 +375,20 @@ class BiSQLView(models.Model):
@api.multi
def _prepare_action(self):
self.ensure_one()
view_mode = self.view_order
first_view = view_mode.split(',')[0]
if first_view == 'tree':
view_id = self.tree_view_id.id
elif first_view == 'pivot':
view_id = self.pivot_view_id.id
else:
view_id = self.graph_view_id.id
return {
'name': self.name,
'res_model': self.model_id.model,
'type': 'ir.actions.act_window',
'view_mode': 'graph,pivot,tree',
'view_id': self.graph_view_id.id,
'view_mode': view_mode,
'view_id': view_id,
'search_view_id': self.search_view_id.id,
}

1
bi_sql_editor/views/view_bi_sql_view.xml

@ -54,6 +54,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<group>
<field name="technical_name"/>
<field name="view_name"/>
<field name="view_order"/>
<field name="is_materialized"/>
<field name="size"
attrs="{'invisible': ['|', ('state', '=', 'draft'), ('is_materialized', '=', False)]}"/>

Loading…
Cancel
Save