1 ##############################################################################
3 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
30 import os
, time
, base64
, datetime
40 from widget
.view
.form_gtk
.many2one
import dialog
41 class main(service
.Service
):
42 def __init__(self
, name
='action.main'):
43 service
.Service
.__init
__(self
, name
)
45 def exec_report(self
, name
, data
, context
={}):
50 ids
= rpc
.session
.rpc_exec_auth('/object', 'execute', datas
['model'], 'search', [])
52 common
.message(_('Nothing to print!'))
55 ctx
= rpc
.session
.context
.copy()
57 report_id
= rpc
.session
.rpc_exec_auth('/report', 'report', name
, ids
, datas
, ctx
)
61 val
= rpc
.session
.rpc_exec_auth('/report', 'report_get', report_id
)
69 common
.message(_('Printing aborted, too long delay !'))
71 printer
.print_data(val
)
74 def execute(self
, act_id
, datas
, type=None, context
={}):
75 ctx
= rpc
.session
.context
.copy()
78 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', 'ir.actions.actions', 'read', [act_id
], ['type'], ctx
)
80 raise Exception, 'ActionNotFound'
82 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', type, 'read', [act_id
], False, ctx
)[0]
83 self
._exec
_action
(res
,datas
,context
)
85 def _exec_action(self
, action
, datas
, context
={}):
86 if 'type' not in action
:
88 if action
['type']=='ir.actions.act_window':
89 for key
in ('res_id', 'res_model', 'view_type', 'view_mode',
90 'limit', 'auto_refresh'):
91 datas
[key
] = action
.get(key
, datas
.get(key
, None))
93 if datas
['limit'] is None or datas
['limit'] == 0:
97 if action
.get('views', []):
98 view_ids
=[x
[0] for x
in action
['views']]
99 datas
['view_mode']=",".join([x
[1] for x
in action
['views']])
100 elif action
.get('view_id', False):
101 view_ids
=[action
['view_id'][0]]
103 if not action
.get('domain', False):
104 action
['domain']='[]'
105 ctx
= {'active_id': datas
.get('id',False), 'active_ids': datas
.get('ids',[])}
106 ctx
.update(tools
.expr_eval(action
.get('context','{}'), ctx
.copy()))
111 a
['datetime'] = datetime
112 domain
= tools
.expr_eval(action
['domain'], a
)
114 if datas
.get('domain', False):
115 domain
.append(datas
['domain'])
116 if 'target' in action
and action
['target']=='new':
117 dia
= dialog(datas
['res_model'],window
=datas
.get('window',None), domain
=domain
, context
=ctx
)
118 dia
.but_cancel
.destroy()
122 obj
= service
.LocalService('gui.window')
123 obj
.create(view_ids
, datas
['res_model'], datas
['res_id'], domain
,
124 action
['view_type'], datas
.get('window',None), ctx
,
125 datas
['view_mode'], name
=action
.get('name', False),
126 limit
=datas
['limit'], auto_refresh
=datas
['auto_refresh'])
128 elif action
['type']=='ir.actions.server':
130 ctx
.update({'active_id': datas
.get('id',False), 'active_ids': datas
.get('ids',[])})
131 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', 'ir.actions.server', 'run', [action
['id']], ctx
)
133 self
._exec
_action
(res
, datas
, context
)
135 elif action
['type']=='ir.actions.wizard':
137 if 'window' in datas
:
140 wizard
.execute(action
['wiz_name'], datas
, parent
=win
, context
=context
)
142 elif action
['type']=='ir.actions.report.custom':
143 if 'window' in datas
:
146 datas
['report_id'] = action
['report_id']
147 self
.exec_report('custom', datas
)
149 elif action
['type']=='ir.actions.report.xml':
150 if 'window' in datas
:
153 self
.exec_report(action
['report_name'], datas
)
155 elif action
['type']=='ir.actions.act_url':
156 tools
.launch_browser(action
.get('url',''))
158 def exec_keyword(self
, keyword
, data
={}, adds
={}, context
={}, warning
=True):
162 id = data
.get('id', False)
163 actions
= rpc
.session
.rpc_exec_auth('/object', 'execute',
164 'ir.values', 'get', 'action', keyword
,
165 [(data
['model'], id)], False, rpc
.session
.context
)
166 actions
= map(lambda x
: x
[2], actions
)
167 except rpc
.rpc_exception
, e
:
168 # common.error(_('Error: ')+str(e.type), e.message, e.data)
172 for action
in actions
:
173 keyact
[action
['name']] = action
176 res
= common
.selection(_('Select your action'), keyact
)
179 self
._exec
_action
(action
, data
, context
=context
)
180 return (name
, action
)
181 elif not len(keyact
):
183 common
.message(_('No action defined!'))