1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
import os, time, base64, datetime
33
from widget.view.form_gtk.many2one import dialog
35
class main(service.Service):
36
def __init__(self, name='action.main'):
37
service.Service.__init__(self, name)
39
def exec_report(self, name, data, context={}):
44
ids = rpc.session.rpc_exec_auth('/object', 'execute', datas['model'], 'search', [])
46
common.message(_('Nothing to print!'))
49
ctx = rpc.session.context.copy()
51
report_id = rpc.session.rpc_exec_auth('/report', 'report', name, ids, datas, ctx)
55
val = rpc.session.rpc_exec_auth('/report', 'report_get', report_id)
63
common.message(_('Printing aborted, too long delay !'))
65
printer.print_data(val)
68
def execute(self, act_id, datas, type=None, context={}):
70
ctx = rpc.session.context.copy()
73
res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.actions', 'read', int(act_id), ['type'], ctx)
74
if not (res and len(res)):
75
raise Exception, 'ActionNotFound'
78
res = rpc.session.rpc_exec_auth('/object', 'execute', type, 'read', act_id, False, ctx)
79
self._exec_action(res,datas,context)
81
def _exec_action(self, action, datas, context={}):
82
if 'type' not in action:
84
if action['type']=='ir.actions.act_window':
85
for key in ('res_id', 'res_model', 'view_type', 'view_mode',
86
'limit', 'auto_refresh'):
87
datas[key] = action.get(key, datas.get(key, None))
89
if datas['limit'] is None or datas['limit'] == 0:
93
if action.get('views', []):
94
if isinstance(action['views'],list):
95
view_ids=[x[0] for x in action['views']]
96
datas['view_mode']=",".join([x[1] for x in action['views']])
98
# view_ids=[(action['view_type']=='tree') and 1 or False,(action['view_type']=='form') and 1 or False]
99
if action.get('view_id', False):
100
view_ids=[action['view_id'][0]]
101
elif action.get('view_id', False):
102
view_ids=[action['view_id'][0]]
104
if not action.get('domain', False):
105
action['domain']='[]'
107
ctx.update( {'active_id': datas.get('id',False), 'active_ids': datas.get('ids',[])} )
108
ctx.update(tools.expr_eval(action.get('context','{}'), ctx.copy()))
112
a['datetime'] = datetime
113
domain = tools.expr_eval(action['domain'], a)
115
if datas.get('domain', False):
116
domain.append(datas['domain'])
117
if action.get('target', False)=='new':
118
dia = dialog(datas['res_model'], window=datas.get('window',None), domain=domain, context=ctx, view_ids=view_ids,target=True, view_type=datas.get('view_mode', 'tree').split(','))
119
if dia.dia.get_has_separator():
120
dia.dia.set_has_separator(False)
124
obj = service.LocalService('gui.window')
125
obj.create(view_ids, datas['res_model'], datas['res_id'], domain,
126
action['view_type'], datas.get('window',None), ctx,
127
datas['view_mode'], name=action.get('name', False),
128
limit=datas['limit'], auto_refresh=datas['auto_refresh'])
130
elif action['type']=='ir.actions.server':
132
ctx.update({'active_id': datas.get('id',False), 'active_ids': datas.get('ids',[])})
133
res = rpc.session.rpc_exec_auth('/object', 'execute', 'ir.actions.server', 'run', [action['id']], ctx)
135
self._exec_action(res, datas, context)
137
elif action['type']=='ir.actions.wizard':
139
if 'window' in datas:
142
wizard.execute(action['wiz_name'], datas, parent=win, context=context)
144
elif action['type']=='ir.actions.report.custom':
145
if 'window' in datas:
148
datas['report_id'] = action['report_id']
149
self.exec_report('custom', datas)
151
elif action['type']=='ir.actions.report.xml':
152
if 'window' in datas:
155
self.exec_report(action['report_name'], datas)
157
elif action['type']=='ir.actions.act_url':
158
tools.launch_browser(action.get('url',''))
160
def exec_keyword(self, keyword, data={}, adds={}, context={}, warning=True):
164
id = data.get('id', False)
165
actions = rpc.session.rpc_exec_auth('/object', 'execute',
166
'ir.values', 'get', 'action', keyword,
167
[(data['model'], id)], False, rpc.session.context)
168
actions = map(lambda x: x[2], actions)
169
except rpc.rpc_exception, e:
170
# common.error(_('Error: ')+str(e.type), e.message, e.data)
174
for action in actions:
175
keyact[action['name']] = action
178
res = common.selection(_('Select your action'), keyact)
181
self._exec_action(action, data, context=context)
182
return (name, action)
187
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: