From b00e6f9c9b815b65eb6bc5c1374e7ca847347721 Mon Sep 17 00:00:00 2001 From: aheficent Date: Fri, 21 Jul 2017 10:56:15 +0200 Subject: [PATCH] [IMP]add an option to select the first view --- bi_sql_editor/models/bi_sql_view.py | 32 +++++++++++++++++++++--- bi_sql_editor/views/view_bi_sql_view.xml | 3 ++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index 066f1bb9..ec873452 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/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, } diff --git a/bi_sql_editor/views/view_bi_sql_view.xml b/bi_sql_editor/views/view_bi_sql_view.xml index 210a90d8..14aecd12 100644 --- a/bi_sql_editor/views/view_bi_sql_view.xml +++ b/bi_sql_editor/views/view_bi_sql_view.xml @@ -53,7 +53,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - + +