From b8be5bf9ed234cbedfd19a8fe828d9894ab84ec2 Mon Sep 17 00:00:00 2001 From: Martin Nicolas Cuesta Date: Tue, 23 Jan 2018 12:20:34 -0300 Subject: [PATCH 1/2] [FIX] ActWindow from Python Method after Popup Allow python methods called from an ir.action.act_window.message action to return window actions without specifying the ``views`` key, as they would be if called from a button defined in xml. ``view_mode`` key is used for creating the views array as it is required anyway --- .../js/web_ir_actions_act_window_message.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js index 227cd6710..7eb6c816c 100644 --- a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js +++ b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js @@ -78,6 +78,29 @@ openerp.web_ir_actions_act_window_message = function(instance) { if(_.isObject(result)) { + if (! ('views' in result) && 'view_mode' in result){ + types = result.view_mode.split(","); + if (types.length > 1){ + if (types.includes('tree') && types.includes('form')){ + if (types[0] === "tree"){ + views = [[false, "list"], [false, types[1]]]; + result.view_mode = "list" + ',' + types[1]; + } + else { + views = [[false, types[0]], [false, "list"]]; + result.view_mode = types[0] + ',' + "list"; + } + } + } + else if (result.view_mode === 'form'){ + views = [[false, "form"]]; + } + else if (result.view_mode === 'tree'){ + views = [[false, "list"]]; + result.view_mode = 'list'; + } + result.views = views; + } self.do_action(result); } else From 6bcaf9af72f297b072acaab765626c533dc75130 Mon Sep 17 00:00:00 2001 From: Martin Nicolas Cuesta Date: Tue, 23 Jan 2018 15:14:30 -0300 Subject: [PATCH 2/2] [MOD] Action Cleaning as in fix_view_modes --- .../js/web_ir_actions_act_window_message.js | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js index 7eb6c816c..a263f6d00 100644 --- a/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js +++ b/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js @@ -78,30 +78,57 @@ openerp.web_ir_actions_act_window_message = function(instance) { if(_.isObject(result)) { - if (! ('views' in result) && 'view_mode' in result){ - types = result.view_mode.split(","); - if (types.length > 1){ - if (types.includes('tree') && types.includes('form')){ - if (types[0] === "tree"){ - views = [[false, "list"], [false, types[1]]]; - result.view_mode = "list" + ',' + types[1]; - } - else { - views = [[false, types[0]], [false, "list"]]; - result.view_mode = types[0] + ',' + "list"; - } + // clean the action as it is done in the method ``fix_view_modes`` + // in the main controller of the web module + action = result; + if ( ! ('views' in action) ){ + view_id = action.view_id || false; + if ( view_id instanceof Array ){ + view_id = view_id[0]; + } + view_modes = action.view_mode.split(","); + if ( view_modes.length > 1 ){ + if (view_id){ + throw new Error( + _.str.sprintf(_t("Non-db action dictionaries should provide " + + "either multiple view modes or a single view " + + "mode and an optional view id."))); } + action.views = []; + for ( i=0; i