1 ##############################################################################
3 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 # Fabien Pinckaers <fp@tiny.Be>
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ##############################################################################
29 import os
, time
, base64
, datetime
40 class main(service
.Service
):
41 def __init__(self
, name
='action.main'):
42 service
.Service
.__init
__(self
, name
)
44 def exec_report(self
, name
, data
, context
={}):
49 ids
= rpc
.session
.rpc_exec_auth('/object', 'execute', datas
['model'], 'search', [])
51 common
.message(_('Nothing to print!'))
54 ctx
= rpc
.session
.context
.copy()
56 report_id
= rpc
.session
.rpc_exec_auth('/report', 'report', name
, ids
, datas
, ctx
)
60 val
= rpc
.session
.rpc_exec_auth('/report', 'report_get', report_id
)
68 common
.message(_('Printing aborted, too long delay !'))
70 printer
.print_data(val
)
73 def execute(self
, act_id
, datas
, type=None, context
={}):
74 ctx
= rpc
.session
.context
.copy()
77 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', 'ir.actions.actions', 'read', [act_id
], ['type'], ctx
)
79 raise Exception, 'ActionNotFound'
81 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', type, 'read', [act_id
], False, ctx
)[0]
82 self
._exec
_action
(res
,datas
)
84 def _exec_action(self
, action
, datas
, context
={}):
85 if 'type' not in action
:
87 if action
['type']=='ir.actions.act_window':
88 for key
in ('res_id', 'res_model', 'view_type', 'view_mode',
89 'limit', 'auto_refresh'):
90 datas
[key
] = action
.get(key
, datas
.get(key
, None))
92 if datas
['limit'] is None or datas
['limit'] == 0:
96 if action
.get('views', []):
97 view_ids
=[x
[0] for x
in action
['views']]
98 datas
['view_mode']=",".join([x
[1] for x
in action
['views']])
99 elif action
.get('view_id', False):
100 view_ids
=[action
['view_id'][0]]
102 if not action
.get('domain', False):
103 action
['domain']='[]'
104 ctx
= {'active_id': datas
.get('id',False), 'active_ids': datas
.get('ids',[])}
105 ctx
.update(tools
.expr_eval(action
.get('context','{}'), ctx
.copy()))
110 a
['datetime'] = datetime
111 domain
= tools
.expr_eval(action
['domain'], a
)
113 if datas
.get('domain', False):
114 domain
.append(datas
['domain'])
116 obj
= service
.LocalService('gui.window')
117 obj
.create(view_ids
, datas
['res_model'], datas
['res_id'], domain
,
118 action
['view_type'], datas
.get('window',None), ctx
,
119 datas
['view_mode'], name
=action
.get('name', False),
120 limit
=datas
['limit'], auto_refresh
=datas
['auto_refresh'])
122 #for key in tools.expr_eval(action.get('context', '{}')).keys():
123 # del rpc.session.context[key]
125 elif action
['type']=='ir.actions.wizard':
127 if 'window' in datas
:
130 wizard
.execute(action
['wiz_name'], datas
, parent
=win
, context
=context
)
132 elif action
['type']=='ir.actions.report.custom':
133 if 'window' in datas
:
136 datas
['report_id'] = action
['report_id']
137 self
.exec_report('custom', datas
)
139 elif action
['type']=='ir.actions.report.xml':
140 if 'window' in datas
:
143 self
.exec_report(action
['report_name'], datas
)
145 elif action
['type']=='ir.actions.url':
146 tools
.launch_browser(action
.get('url',''))
148 def exec_keyword(self
, keyword
, data
={}, adds
={}, context
={}, warning
=True):
152 id = data
.get('id', False)
153 actions
= rpc
.session
.rpc_exec_auth('/object', 'execute',
154 'ir.values', 'get', 'action', keyword
,
155 [(data
['model'], id)], False, rpc
.session
.context
)
156 actions
= map(lambda x
: x
[2], actions
)
157 except rpc
.rpc_exception
, e
:
158 # common.error(_('Error: ')+str(e.type), e.message, e.data)
162 for action
in actions
:
163 keyact
[action
['name']] = action
166 res
= common
.selection(_('Select your action'), keyact
)
169 self
._exec
_action
(action
, data
, context
=context
)
170 return (name
, action
)
171 elif not len(keyact
):
173 common
.message(_('No action defined!'))