Fill keyword arguments using dictionary to launch action
This commit is contained in:
+4
-7
@@ -54,12 +54,12 @@
|
||||
});
|
||||
}
|
||||
data.action_id = action.id;
|
||||
var params = {};
|
||||
var params = {
|
||||
'icon': action['icon.rec_name'] || '',
|
||||
};
|
||||
var name_prm;
|
||||
switch (action.type) {
|
||||
case 'ir.action.act_window':
|
||||
params.view_ids = [];
|
||||
params.mode = null;
|
||||
if (!jQuery.isEmptyObject(action.views)) {
|
||||
params.view_ids = [];
|
||||
params.mode = [];
|
||||
@@ -103,12 +103,9 @@
|
||||
params.res_id = action.res_id || data.res_id;
|
||||
params.context_model = action.context_model;
|
||||
params.context_domain = action.context_domain;
|
||||
if (action.limit !== null) {
|
||||
if ((action.limit !== undefined) && (action.limit !== null)) {
|
||||
params.limit = action.limit;
|
||||
} else {
|
||||
params.limit = Sao.config.limit;
|
||||
}
|
||||
params.icon = action['icon.rec_name'] || '';
|
||||
|
||||
if (action.keyword) {
|
||||
name_prm = add_name_suffix(action.name, params.context);
|
||||
|
||||
@@ -6,7 +6,6 @@ import webbrowser
|
||||
import tryton.rpc as rpc
|
||||
from tryton.common import (
|
||||
RPCException, RPCExecute, file_open, file_write, message, selection)
|
||||
from tryton.config import CONFIG
|
||||
from tryton.pyson import PYSONDecoder
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -91,14 +90,15 @@ class Action(object):
|
||||
return name
|
||||
|
||||
data['action_id'] = action['id']
|
||||
params = {
|
||||
'icon': action.get('icon.rec_name') or '',
|
||||
}
|
||||
if action['type'] == 'ir.action.act_window':
|
||||
view_ids = []
|
||||
view_mode = None
|
||||
if action.get('views', []):
|
||||
view_ids = [x[0] for x in action['views']]
|
||||
view_mode = [x[1] for x in action['views']]
|
||||
params['view_ids'] = [x[0] for x in action['views']]
|
||||
params['view_mode'] = [x[1] for x in action['views']]
|
||||
elif action.get('view_id', False):
|
||||
view_ids = [action['view_id'][0]]
|
||||
params['view_ids'] = [action['view_id'][0]]
|
||||
|
||||
action.setdefault('pyson_domain', '[]')
|
||||
ctx = {
|
||||
@@ -109,58 +109,47 @@ class Action(object):
|
||||
ctx.update(rpc.CONTEXT)
|
||||
ctx['_user'] = rpc._USER
|
||||
decoder = PYSONDecoder(ctx)
|
||||
action_ctx = context.copy()
|
||||
action_ctx.update(
|
||||
params['context'] = context.copy()
|
||||
params['context'].update(
|
||||
decoder.decode(action.get('pyson_context') or '{}'))
|
||||
ctx.update(action_ctx)
|
||||
ctx.update(params['context'])
|
||||
|
||||
ctx['context'] = ctx
|
||||
decoder = PYSONDecoder(ctx)
|
||||
domain = decoder.decode(action['pyson_domain'])
|
||||
order = decoder.decode(action['pyson_order'])
|
||||
search_value = decoder.decode(action['pyson_search_value'] or '[]')
|
||||
tab_domain = [(n, decoder.decode(d), c)
|
||||
for n, d, c in action['domains']]
|
||||
params['domain'] = decoder.decode(action['pyson_domain'])
|
||||
params['order'] = decoder.decode(action['pyson_order'])
|
||||
params['search_value'] = decoder.decode(
|
||||
action['pyson_search_value'] or '[]')
|
||||
params['tab_domain'] = [
|
||||
(n, decoder.decode(d), c) for n, d, c in action['domains']]
|
||||
|
||||
name = action.get('name', '')
|
||||
if action.get('keyword', ''):
|
||||
name = add_name_suffix(name, action_ctx)
|
||||
name = add_name_suffix(name, params['context'])
|
||||
params['name'] = name
|
||||
|
||||
res_model = action.get('res_model', data.get('res_model'))
|
||||
res_id = action.get('res_id', data.get('res_id'))
|
||||
params['res_id'] = action.get('res_id', data.get('res_id'))
|
||||
params['context_model'] = action.get('context_model')
|
||||
params['context_domain'] = action.get('context_domain')
|
||||
limit = action.get('limit')
|
||||
if limit is None:
|
||||
limit = CONFIG['client.limit']
|
||||
if limit is not None:
|
||||
params['limit'] = limit
|
||||
|
||||
Window.create(res_model,
|
||||
view_ids=view_ids,
|
||||
res_id=res_id,
|
||||
domain=domain,
|
||||
context=action_ctx,
|
||||
order=order,
|
||||
mode=view_mode,
|
||||
name=name,
|
||||
limit=limit,
|
||||
search_value=search_value,
|
||||
icon=(action.get('icon.rec_name') or ''),
|
||||
tab_domain=tab_domain,
|
||||
context_model=action['context_model'],
|
||||
context_domain=action['context_domain'])
|
||||
Window.create(res_model, **params)
|
||||
elif action['type'] == 'ir.action.wizard':
|
||||
params['context'] = context
|
||||
params['window'] = action.get('window')
|
||||
name = action.get('name', '')
|
||||
if action.get('keyword', 'form_action') == 'form_action':
|
||||
name = add_name_suffix(name, context)
|
||||
Window.create_wizard(action['wiz_name'], data,
|
||||
direct_print=action.get('direct_print', False),
|
||||
name=name,
|
||||
context=context, icon=(action.get('icon.rec_name') or ''),
|
||||
window=action.get('window', False))
|
||||
|
||||
params['name'] = name
|
||||
Window.create_wizard(action['wiz_name'], data, **params)
|
||||
elif action['type'] == 'ir.action.report':
|
||||
Action.exec_report(
|
||||
action['report_name'], data,
|
||||
direct_print=action.get('direct_print', False),
|
||||
context=context)
|
||||
params['direct_print'] = action.get('direct_print', False)
|
||||
params['context'] = context
|
||||
del params['icon']
|
||||
Action.exec_report(action['report_name'], data, **params)
|
||||
|
||||
elif action['type'] == 'ir.action.url':
|
||||
if action['url']:
|
||||
|
||||
+31
-45
@@ -9,6 +9,7 @@ import sys
|
||||
import threading
|
||||
import traceback
|
||||
import webbrowser
|
||||
from functools import partial
|
||||
from urllib.parse import parse_qsl, unquote, urlparse
|
||||
|
||||
from gi.repository import Gdk, GdkPixbuf, Gio, GLib, Gtk
|
||||
@@ -960,6 +961,7 @@ class Main(Gtk.Application):
|
||||
dialog.show()
|
||||
|
||||
def _open_url(self, url):
|
||||
loads = partial(json.loads, object_hook=object_hook)
|
||||
urlp = urlparse(url)
|
||||
if not urlp.scheme == 'tryton':
|
||||
return
|
||||
@@ -982,88 +984,72 @@ class Main(Gtk.Application):
|
||||
model, path = (path.split('/', 1) + [''])[:2]
|
||||
if not model:
|
||||
return
|
||||
res_id = None
|
||||
mode = None
|
||||
attributes = {}
|
||||
try:
|
||||
view_ids = json.loads(params.get('views', '[]'))
|
||||
attributes['view_ids'] = loads(params.get('views', '[]'))
|
||||
if 'limit' in params:
|
||||
attributes['limit'] = json.loads(
|
||||
params.get('limit', 'null'))
|
||||
name = json.loads(params.get('name', '""'))
|
||||
search_value = json.loads(params.get('search_value', '[]'),
|
||||
object_hook=object_hook)
|
||||
domain = json.loads(params.get('domain', '[]'),
|
||||
object_hook=object_hook)
|
||||
context = json.loads(params.get('context', '{}'),
|
||||
object_hook=object_hook)
|
||||
context_model = params.get('context_model')
|
||||
tab_domain = json.loads(params.get('tab_domain', '[]'),
|
||||
object_hook=object_hook)
|
||||
attributes['limit'] = loads(params.get('limit', 'null'))
|
||||
attributes['name'] = loads(params.get('name', '""'))
|
||||
attributes['search_value'] = loads(
|
||||
params.get('search_value', '[]'))
|
||||
attributes['domain'] = loads(params.get('domain', '[]'))
|
||||
attributes['context'] = loads(params.get('context', '{}'))
|
||||
attributes['context_model'] = params.get('context_model')
|
||||
attributes['tab_domain'] = loads(
|
||||
params.get('tab_domain', '[]'))
|
||||
except ValueError:
|
||||
return
|
||||
if path:
|
||||
try:
|
||||
res_id = int(path)
|
||||
attributes['res_id'] = int(path)
|
||||
except ValueError:
|
||||
return
|
||||
mode = ['form', 'tree']
|
||||
attributes['mode'] = ['form', 'tree']
|
||||
try:
|
||||
Window.create(model,
|
||||
view_ids=view_ids,
|
||||
res_id=res_id,
|
||||
domain=domain,
|
||||
context=context,
|
||||
context_model=context_model,
|
||||
mode=mode,
|
||||
name=name,
|
||||
search_value=search_value,
|
||||
tab_domain=tab_domain,
|
||||
**attributes)
|
||||
Window.create(model, **attributes)
|
||||
except Exception:
|
||||
# Prevent crashing the client
|
||||
return
|
||||
|
||||
def open_wizard(wizard):
|
||||
attributes = {}
|
||||
if not wizard:
|
||||
return
|
||||
try:
|
||||
data = json.loads(params.get('data', '{}'),
|
||||
object_hook=object_hook)
|
||||
direct_print = json.loads(params.get('direct_print', 'false'))
|
||||
name = json.loads(params.get('name', '""'))
|
||||
window = json.loads(params.get('window', 'false'))
|
||||
context = json.loads(params.get('context', '{}'),
|
||||
object_hook=object_hook)
|
||||
attributes['data'] = loads(params.get('data', '{}'))
|
||||
attributes['direct_print'] = loads(
|
||||
params.get('direct_print', 'false'))
|
||||
attributes['name'] = loads(params.get('name', '""'))
|
||||
attributes['window'] = loads(params.get('window', 'false'))
|
||||
attributes['context'] = loads(params.get('context', '{}'))
|
||||
except ValueError:
|
||||
return
|
||||
try:
|
||||
Window.create_wizard(
|
||||
wizard, data, direct_print=direct_print, name=name,
|
||||
context=context, window=window)
|
||||
Window.create_wizard(wizard, **attributes)
|
||||
except Exception:
|
||||
# Prevent crashing the client
|
||||
return
|
||||
|
||||
def open_report(report):
|
||||
attributes = {}
|
||||
if not report:
|
||||
return
|
||||
try:
|
||||
data = json.loads(params.get('data'), object_hook=object_hook)
|
||||
direct_print = json.loads(params.get('direct_print', 'false'))
|
||||
context = json.loads(params.get('context', '{}'),
|
||||
object_hook=object_hook)
|
||||
attributes['data'] = loads(params.get('data', '{}'))
|
||||
attributes['direct_print'] = loads(
|
||||
params.get('direct_print', 'false'))
|
||||
attributes['context'] = loads(params.get('context', '{}'))
|
||||
except ValueError:
|
||||
return
|
||||
try:
|
||||
Action.exec_report(
|
||||
report, data, direct_print=direct_print, context=context)
|
||||
Action.exec_report(report, **attributes)
|
||||
except Exception:
|
||||
# Prevent crashing the client
|
||||
return
|
||||
|
||||
def open_url():
|
||||
try:
|
||||
url = json.loads(params.get('url', 'false'))
|
||||
url = loads(params.get('url', 'false'))
|
||||
except ValueError:
|
||||
return
|
||||
if url:
|
||||
|
||||
Reference in New Issue
Block a user