1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
31 import os
, time
, base64
, datetime
41 from widget
.view
.form_gtk
.many2one
import dialog
43 class main(service
.Service
):
44 def __init__(self
, name
='action.main'):
45 service
.Service
.__init
__(self
, name
)
47 def exec_report(self
, name
, data
, context
={}):
52 ids
= rpc
.session
.rpc_exec_auth('/object', 'execute', datas
['model'], 'search', [])
54 common
.message(_('Nothing to print!'))
57 ctx
= rpc
.session
.context
.copy()
59 report_id
= rpc
.session
.rpc_exec_auth('/report', 'report', name
, ids
, datas
, ctx
)
63 val
= rpc
.session
.rpc_exec_auth('/report', 'report_get', report_id
)
71 common
.message(_('Printing aborted, too long delay !'))
73 printer
.print_data(val
)
76 def execute(self
, act_id
, datas
, type=None, context
={}):
77 ctx
= rpc
.session
.context
.copy()
80 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', 'ir.actions.actions', 'read', act_id
, ['type'], ctx
)
81 if not (res
and len(res
)):
82 raise Exception, 'ActionNotFound'
85 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', type, 'read', act_id
, False, ctx
)
86 self
._exec
_action
(res
,datas
,context
)
88 def _exec_action(self
, action
, datas
, context
={}):
89 if 'type' not in action
:
91 if action
['type']=='ir.actions.act_window':
92 for key
in ('res_id', 'res_model', 'view_type', 'view_mode',
93 'limit', 'auto_refresh'):
94 datas
[key
] = action
.get(key
, datas
.get(key
, None))
96 if datas
['limit'] is None or datas
['limit'] == 0:
100 if action
.get('views', []):
101 if isinstance(action
['views'],list):
102 view_ids
=[x
[0] for x
in action
['views']]
103 datas
['view_mode']=",".join([x
[1] for x
in action
['views']])
105 # view_ids=[(action['view_type']=='tree') and 1 or False,(action['view_type']=='form') and 1 or False]
106 if action
.get('view_id', False):
107 view_ids
=[action
['view_id'][0]]
108 elif action
.get('view_id', False):
109 view_ids
=[action
['view_id'][0]]
111 if not action
.get('domain', False):
112 action
['domain']='[]'
113 ctx
= {'active_id': datas
.get('id',False), 'active_ids': datas
.get('ids',[])}
114 ctx
.update(tools
.expr_eval(action
.get('context','{}'), ctx
.copy()))
119 a
['datetime'] = datetime
120 domain
= tools
.expr_eval(action
['domain'], a
)
122 if datas
.get('domain', False):
123 domain
.append(datas
['domain'])
124 if action
.get('target', False)=='new':
125 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(','))
126 if dia
.dia
.get_has_separator():
127 dia
.dia
.set_has_separator(False)
131 obj
= service
.LocalService('gui.window')
132 obj
.create(view_ids
, datas
['res_model'], datas
['res_id'], domain
,
133 action
['view_type'], datas
.get('window',None), ctx
,
134 datas
['view_mode'], name
=action
.get('name', False),
135 limit
=datas
['limit'], auto_refresh
=datas
['auto_refresh'])
137 elif action
['type']=='ir.actions.server':
139 ctx
.update({'active_id': datas
.get('id',False), 'active_ids': datas
.get('ids',[])})
140 res
= rpc
.session
.rpc_exec_auth('/object', 'execute', 'ir.actions.server', 'run', [action
['id']], ctx
)
142 self
._exec
_action
(res
, datas
, context
)
144 elif action
['type']=='ir.actions.wizard':
146 if 'window' in datas
:
149 wizard
.execute(action
['wiz_name'], datas
, parent
=win
, context
=context
)
151 elif action
['type']=='ir.actions.report.custom':
152 if 'window' in datas
:
155 datas
['report_id'] = action
['report_id']
156 self
.exec_report('custom', datas
)
158 elif action
['type']=='ir.actions.report.xml':
159 if 'window' in datas
:
162 self
.exec_report(action
['report_name'], datas
)
164 elif action
['type']=='ir.actions.act_url':
165 tools
.launch_browser(action
.get('url',''))
167 def exec_keyword(self
, keyword
, data
={}, adds
={}, context
={}, warning
=True):
171 id = data
.get('id', False)
172 actions
= rpc
.session
.rpc_exec_auth('/object', 'execute',
173 'ir.values', 'get', 'action', keyword
,
174 [(data
['model'], id)], False, rpc
.session
.context
)
175 actions
= map(lambda x
: x
[2], actions
)
176 except rpc
.rpc_exception
, e
:
177 # common.error(_('Error: ')+str(e.type), e.message, e.data)
181 for action
in actions
:
182 keyact
[action
['name']] = action
185 res
= common
.selection(_('Select your action'), keyact
)
188 self
._exec
_action
(action
, data
, context
=context
)
189 return (name
, action
)
194 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: