improve, fix few bugs related to the address
[odoo/odoo.git] / bin / addons / base / ir / ir_actions.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #
6 # $Id$
7 #
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
13 # Service Company
14 #
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.
19 #
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.
24 #
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.
28 #
29 ##############################################################################
30
31 from osv import fields,osv
32 import tools
33 import time
34 from tools.config import config
35 import netsvc
36 import re
37
38 class actions(osv.osv):
39     _name = 'ir.actions.actions'
40     _table = 'ir_actions'
41     _columns = {
42         'name': fields.char('Action Name', required=True, size=64),
43         'type': fields.char('Action Type', required=True, size=32),
44         'usage': fields.char('Action Usage', size=32),
45         'parent_id': fields.many2one('ir.actions.server', 'Parent Action'),
46     }
47     _defaults = {
48         'usage': lambda *a: False,
49     }
50 actions()
51
52 class report_custom(osv.osv):
53     _name = 'ir.actions.report.custom'
54     _table = 'ir_act_report_custom'
55     _sequence = 'ir_actions_id_seq'
56     _columns = {
57         'name': fields.char('Report Name', size=64, required=True, translate=True),
58         'type': fields.char('Report Type', size=32, required=True),
59         'model':fields.char('Object', size=64, required=True),
60         'report_id': fields.integer('Report Ref.', required=True),
61         'usage': fields.char('Action Usage', size=32),
62         'multi': fields.boolean('On multiple doc.', help="If set to true, the action will not be displayed on the right toolbar of a form views.")
63     }
64     _defaults = {
65         'multi': lambda *a: False,
66         'type': lambda *a: 'ir.actions.report.custom',
67     }
68 report_custom()
69
70 class report_xml(osv.osv):
71
72     def _report_content(self, cursor, user, ids, name, arg, context=None):
73         res = {}
74         for report in self.browse(cursor, user, ids, context=context):
75             data = report[name + '_data']
76             if not data and report[name[:-8]]:
77                 try:
78                     fp = tools.file_open(report[name[:-8]], mode='rb')
79                     data = fp.read()
80                 except:
81                     data = False
82             res[report.id] = data
83         return res
84
85     def _report_content_inv(self, cursor, user, id, name, value, arg, context=None):
86         self.write(cursor, user, id, {name+'_data': value}, context=context)
87
88     def _report_sxw(self, cursor, user, ids, name, arg, context=None):
89         res = {}
90         for report in self.browse(cursor, user, ids, context=context):
91             if report.report_rml:
92                 res[report.id] = report.report_rml.replace('.rml', '.sxw')
93             else:
94                 res[report.id] = False
95         return res
96
97     _name = 'ir.actions.report.xml'
98     _table = 'ir_act_report_xml'
99     _sequence = 'ir_actions_id_seq'
100     _columns = {
101         'name': fields.char('Name', size=64, required=True, translate=True),
102         'type': fields.char('Report Type', size=32, required=True),
103         'model': fields.char('Object', size=64, required=True),
104         'report_name': fields.char('Internal Name', size=64, required=True),
105         'report_xsl': fields.char('XSL path', size=256),
106         'report_xml': fields.char('XML path', size=256),
107         'report_rml': fields.char('RML path', size=256,
108             help="The .rml path of the file or NULL if the content is in report_rml_content"),
109         'report_sxw': fields.function(_report_sxw, method=True, type='char',
110             string='SXW path'),
111         'report_sxw_content_data': fields.binary('SXW content'),
112         'report_rml_content_data': fields.binary('RML content'),
113         'report_sxw_content': fields.function(_report_content,
114             fnct_inv=_report_content_inv, method=True,
115             type='binary', string='SXW content',),
116         'report_rml_content': fields.function(_report_content,
117             fnct_inv=_report_content_inv, method=True,
118             type='binary', string='RML content'),
119         'auto': fields.boolean('Automatic XSL:RML', required=True),
120         'usage': fields.char('Action Usage', size=32),
121         'header': fields.boolean('Add RML header',
122             help="Add or not the coporate RML header"),
123         'multi': fields.boolean('On multiple doc.',
124             help="If set to true, the action will not be displayed on the right toolbar of a form views."),
125         'report_type': fields.selection([
126             ('pdf', 'pdf'),
127             ('html', 'html'),
128             ('raw', 'raw'),
129             ('sxw', 'sxw'),
130             ], string='Type', required=True),
131         'groups_id': fields.many2many('res.groups', 'res_groups_report_rel', 'uid', 'gid', 'Groups'),
132         'attachment': fields.char('Save As Attachment Prefix', size=32, help='This is the prefix of the file name the print will be saved as attachement. Keep empty to not save the printed reports')
133     }
134     _defaults = {
135         'type': lambda *a: 'ir.actions.report.xml',
136         'multi': lambda *a: False,
137         'auto': lambda *a: True,
138         'header': lambda *a: True,
139         'report_sxw_content': lambda *a: False,
140         'report_type': lambda *a: 'pdf',
141         'attachment': lambda *a: False,
142     }
143
144 report_xml()
145
146 class act_window(osv.osv):
147     _name = 'ir.actions.act_window'
148     _table = 'ir_act_window'
149     _sequence = 'ir_actions_id_seq'
150
151 #    def search(self, cr, uid, args, offset=0, limit=2000, order=None,
152 #            context=None, count=False):
153 #        if context is None:
154 #            context = {}
155 #        ids = osv.orm.orm.search(self, cr, uid, args, offset, limit, order,
156 #                context=context)
157 #        if uid==1:
158 #            return ids
159 #        user_groups = self.pool.get('res.users').read(cr, uid, [uid])[0]['groups_id']
160 #        result = []
161 #        for act in self.browse(cr, uid, ids):
162 #            if not len(act.groups_id):
163 #                result.append(act.id)
164 #                continue
165 #            for g in act.groups_id:
166 #                if g.id in user_groups:
167 #                    result.append(act.id)
168 #                    break
169 #        return result
170
171     def _views_get_fnc(self, cr, uid, ids, name, arg, context={}):
172         res={}
173         for act in self.browse(cr, uid, ids):
174             res[act.id]=[(view.view_id.id, view.view_mode) for view in act.view_ids]
175             if (not act.view_ids):
176                 modes = act.view_mode.split(',')
177                 find = False
178                 if act.view_id:
179                     res[act.id].append((act.view_id.id, act.view_id.type))
180                 for t in modes:
181                     if act.view_id and (t == act.view_id.type) and not find:
182                         find = True
183                         continue
184                     res[act.id].append((False, t))
185
186                 if 'calendar' not in modes:
187                     mobj = self.pool.get(act.res_model)
188                     if mobj._date_name in mobj._columns:
189                         res[act.id].append((False, 'calendar'))
190         return res
191
192     _columns = {
193         'name': fields.char('Action Name', size=64, translate=True),
194         'type': fields.char('Action Type', size=32, required=True),
195         'view_id': fields.many2one('ir.ui.view', 'View Ref.', ondelete='cascade'),
196         'domain': fields.char('Domain Value', size=250),
197         'context': fields.char('Context Value', size=250),
198         'res_model': fields.char('Object', size=64),
199         'src_model': fields.char('Source Object', size=64),
200         'target': fields.selection([('current','Current Window'),('new','New Window')], 'Target Window'),
201         'view_type': fields.selection((('tree','Tree'),('form','Form')),string='Type of view'),
202         'view_mode': fields.char('Mode of view', size=250),
203         'usage': fields.char('Action Usage', size=32),
204         'view_ids': fields.one2many('ir.actions.act_window.view', 'act_window_id', 'Views'),
205         'views': fields.function(_views_get_fnc, method=True, type='binary', string='Views'),
206         'limit': fields.integer('Limit', help='Default limit for the list view'),
207         'auto_refresh': fields.integer('Auto-Refresh',
208             help='Add an auto-refresh on the view'),
209         'groups_id': fields.many2many('res.groups', 'ir_act_window_group_rel',
210             'act_id', 'gid', 'Groups'),
211     }
212     _defaults = {
213         'type': lambda *a: 'ir.actions.act_window',
214         'view_type': lambda *a: 'form',
215         'view_mode': lambda *a: 'tree,form',
216         'context': lambda *a: '{}',
217         'limit': lambda *a: 80,
218         'target': lambda *a: 'current',
219         'auto_refresh': lambda *a: 0,
220     }
221 act_window()
222
223 class act_window_view(osv.osv):
224     _name = 'ir.actions.act_window.view'
225     _table = 'ir_act_window_view'
226     _rec_name = 'view_id'
227     _columns = {
228         'sequence': fields.integer('Sequence'),
229         'view_id': fields.many2one('ir.ui.view', 'View'),
230         'view_mode': fields.selection((
231             ('tree', 'Tree'),
232             ('form', 'Form'),
233             ('graph', 'Graph'),
234             ('calendar', 'Calendar'),
235             ('gantt', 'Gantt')), string='Type of view', required=True),
236         'act_window_id': fields.many2one('ir.actions.act_window', 'Action', ondelete='cascade'),
237         'multi': fields.boolean('On multiple doc.',
238             help="If set to true, the action will not be displayed on the right toolbar of a form views."),
239     }
240     _defaults = {
241         'multi': lambda *a: False,
242     }
243     _order = 'sequence'
244 act_window_view()
245
246 class act_wizard(osv.osv):
247     _name = 'ir.actions.wizard'
248     _table = 'ir_act_wizard'
249     _sequence = 'ir_actions_id_seq'
250     _columns = {
251         'name': fields.char('Wizard info', size=64, required=True, translate=True),
252         'type': fields.char('Action type', size=32, required=True),
253         'wiz_name': fields.char('Wizard name', size=64, required=True),
254         'multi': fields.boolean('Action on multiple doc.', help="If set to true, the wizard will not be displayed on the right toolbar of a form views."),
255         'groups_id': fields.many2many('res.groups', 'res_groups_wizard_rel', 'uid', 'gid', 'Groups'),
256         'model': fields.char('Object', size=64),
257     }
258     _defaults = {
259         'type': lambda *a: 'ir.actions.wizard',
260         'multi': lambda *a: False,
261     }
262 act_wizard()
263
264 class act_url(osv.osv):
265     _name = 'ir.actions.url'
266     _table = 'ir_act_url'
267     _sequence = 'ir_actions_id_seq'
268     _columns = {
269         'name': fields.char('Action Name', size=64, translate=True),
270         'type': fields.char('Action Type', size=32, required=True),
271         'url': fields.text('Action Url',required=True),
272         'target': fields.selection((
273             ('new', 'New Window'),
274             ('self', 'This Window')),
275             'Action Target', required=True
276         )
277     }
278     _defaults = {
279         'type': lambda *a: 'ir.actions.act_url',
280         'target': lambda *a: 'new'
281     }
282 act_url()
283
284 def model_get(self, cr, uid, context={}):
285     wkf_pool = self.pool.get('workflow')
286     ids = wkf_pool.search(cr, uid, [])
287     osvs = wkf_pool.read(cr, uid, ids, ['osv'])
288
289     res = []
290     mpool = self.pool.get('ir.model')
291     for osv in osvs:
292         model = osv.get('osv')
293         id = mpool.search(cr, uid, [('model','=',model)])
294         name = mpool.read(cr, uid, id)[0]['name']
295         res.append((model, name))
296
297     return res
298
299 class ir_model_fields(osv.osv):
300     _inherit = 'ir.model.fields'
301     _rec_name = 'complete_name'
302     _columns = {
303         'complete_name': fields.char('Complete Name', required=True, size=64, select=1),
304     }
305
306     def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
307
308         def get_fields(cr, uid, field, rel):
309             result = []
310             mobj = self.pool.get('ir.model')
311             id = mobj.search(cr, uid, [('model','=',rel)])
312
313             obj = self.pool.get('ir.model.fields')
314             ids = obj.search(cr, uid, [('model_id','in',id)])
315             records = obj.read(cr, uid, ids)
316             for record in records:
317                 id = record['id']
318                 fld = field + '/' + record['name']
319
320                 result.append((id, fld))
321             return result
322
323         if not args:
324             args=[]
325         if not context:
326             context={}
327             return super(ir_model_fields, self).name_search(cr, uid, name, args, operator, context, limit)
328
329         if context.get('key') != 'server_action':
330             return super(ir_model_fields, self).name_search(cr, uid, name, args, operator, context, limit)
331
332         result = []
333         obj = self.pool.get('ir.model.fields')
334         ids = obj.search(cr, uid, args)
335         records = obj.read(cr, uid, ids)
336         for record in records:
337             id = record['id']
338             field = record['name']
339
340             if record['ttype'] == 'many2one':
341                 rel = record['relation']
342                 res = get_fields(cr, uid, field, record['relation'])
343                 for rs in res:
344                     result.append(rs)
345
346             result.append((id, field))
347
348         for rs in result:
349             obj.write(cr, uid, [rs[0]], {'complete_name':rs[1]})
350
351         iids = []
352         for rs in result:
353             iids.append(rs[0])
354
355         result = super(ir_model_fields, self).name_search(cr, uid, name, [('complete_name','ilike',name), ('id','in',iids)], operator, context, limit)
356
357         return result
358
359 ir_model_fields()
360
361 class server_object_lines(osv.osv):
362     _name = 'ir.server.object.lines'
363     _sequence = 'ir_actions_id_seq'
364     _columns = {
365         'server_id': fields.many2one('ir.actions.server', 'Object Mapping'),
366         'col1': fields.many2one('ir.model.fields', 'Destination', required=True),
367         'value': fields.text('Value', required=True),
368         'type': fields.selection([
369             ('value','Value'),
370             ('equation','Formula')
371         ], 'Type', required=True, size=32, change_default=True),
372     }
373     _defaults = {
374         'type': lambda *a: 'equation',
375     }
376 server_object_lines()
377
378 ##
379 # Actions that are run on the server side
380 #
381 class actions_server(osv.osv):
382     _name = 'ir.actions.server'
383     _table = 'ir_act_server'
384     _sequence = 'ir_actions_id_seq'
385     _columns = {
386         'name': fields.char('Action Name', required=True, size=64),
387         'state': fields.selection([
388             ('python','Python Code'),
389             ('dummy','Dummy'),
390             ('trigger','Trigger'),
391             ('email','Email'),
392             ('sms','SMS'),
393             ('object_create','Create Object'),
394             ('object_write','Write Object'),
395             ('client_action','Client Action'),
396             ('other','Others Actions'),
397         ], 'Action State', required=True, size=32, change_default=True),
398         'code': fields.text('Python Code'),
399         'sequence': fields.integer('Sequence'),
400         'model_id': fields.many2one('ir.model', 'Object', required=True),
401         'trigger_name': fields.char('Trigger Name', size=128),
402         'trigger_obj_id': fields.reference('Trigger On', selection=model_get, size=128),
403         'message': fields.text('Message', translate=True),
404         'address': fields.many2one('ir.model.fields', 'Email / Mobile'),
405         'sms': fields.char('SMS', size=160, translate=True),
406         'child_ids': fields.one2many('ir.actions.actions', 'parent_id', 'Others Actions'),
407         'usage': fields.char('Action Usage', size=32),
408         'type': fields.char('Report Type', size=32, required=True),
409         'srcmodel_id': fields.many2one('ir.model', 'Model'),
410         'fields_lines': fields.one2many('ir.server.object.lines', 'server_id', 'Fields Mapping'),
411         'otype': fields.selection([
412             ('copy','Create in Same Model'),
413             ('new','Create in Other Model')
414         ], 'Create Model', size=32, change_default=True),
415     }
416     _defaults = {
417         'state': lambda *a: 'dummy',
418         'type': lambda *a: 'ir.actions.server',
419         'sequence': lambda *a: 0,
420         'code': lambda *a: """# You can use the following variables
421 #    - object
422 #    - object2
423 #    - time
424 #    - cr
425 #    - uid
426 #    - ids
427 # If you plan to return an action, assign: action = {...}
428 """,
429         'otype': lambda *a: 'copy',
430     }
431
432     def get_field_value(self, cr, uid, action, context):
433         obj_pool = self.pool.get(action.model_id.model)
434         id = context.get('active_id')
435         obj = obj_pool.browse(cr, uid, id)
436
437         fields = None
438
439         if '/' in action.address.complete_name:
440             fields = action.address.complete_name.split('/')
441         elif '.' in action.address.complete_name:
442             fields = action.address.complete_name.split('.')
443
444         for field in fields:
445             try:
446                 obj = getattr(obj, field)
447             except Exception,e :
448                 logger.notifyChannel('Workflow', netsvc.LOG_ERROR, 'Failed to parse : %s' % (match.group()))
449
450         return obj
451
452     def merge_message(self, cr, uid, keystr, action, context):
453         logger = netsvc.Logger()
454         def merge(match):
455
456             obj_pool = self.pool.get(action.model_id.model)
457             id = context.get('active_id')
458             obj = obj_pool.browse(cr, uid, id)
459
460             field = match.group()
461             field = field.replace('[','')
462             field = field.replace(']','')
463             field = field.strip()
464
465             fields = field.split('.')
466             for field in fields:
467                 try:
468                     obj = getattr(obj, field)
469                 except Exception,e :
470                     logger.notifyChannel('Workflow', netsvc.LOG_ERROR, 'Failed to parse : %s' % (match.group()))
471
472             return str(obj)
473
474         com = re.compile('\[\[(.+?)\]\]')
475         message = com.sub(merge, keystr)
476         return message
477
478     #
479     # Context should contains:
480     #   ids : original ids
481     #   id  : current id of the object
482     # OUT:
483     #   False : Finnished correctly
484     #   ACTION_ID : Action to launch
485     def run(self, cr, uid, ids, context={}):
486         logger = netsvc.Logger()
487         for action in self.browse(cr, uid, ids, context):
488             if action.state=='python':
489                 localdict = {
490                     'self': self.pool.get(action.model_id.model),
491                     'context': context,
492                     'time': time,
493                     'ids': ids,
494                     'cr': cr,
495                     'uid': uid
496                 }
497                 exec action.code in localdict
498                 if 'action' in localdict:
499                     return localdict['action']
500
501             if action.state == 'email':
502                 user = config['email_from']
503                 subject = action.name
504                 address = self.get_field_value(cr, uid, action, context)
505                 if not address:
506                     raise osv.except_osv(_('Error'), _("Please specify the Partner Email address !"))
507                 
508                 body = self.merge_message(cr, uid, str(action.message), action, context)
509
510                 if tools.email_send_attach(user, address, subject, body, debug=False) == True:
511                     logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (address))
512                 else:
513                     logger.notifyChannel('email', netsvc.LOG_ERROR, 'Failed to send email to : %s' % (address))
514
515             if action.state == 'trigger':
516                 wf_service = netsvc.LocalService("workflow")
517                 res = str(action.trigger_obj_id).split(',')
518                 model = res[0]
519                 id = res[1]
520                 wf_service.trg_validate(uid, model, int(id), action.trigger_name, cr)
521
522             if action.state == 'sms':
523                 #TODO: set the user and password from the system
524                 # for the sms gateway user / password
525                 api_id = ''
526                 text = action.sms
527                 to = self.get_field_value(cr, uid, action, context)
528                 #TODO: Apply message mearge with the field
529                 if tools.sms_send(user, password, api_id, text, to) == True:
530                     logger.notifyChannel('sms', netsvc.LOG_INFO, 'SMS successfully send to : %s' % (action.address))
531                 else:
532                     logger.notifyChannel('sms', netsvc.LOG_ERROR, 'Failed to send SMS to : %s' % (action.address))
533             if action.state == 'other':
534                 localdict = {
535                     'self': self.pool.get(action.model_id.model),
536                     'context': context,
537                     'time': time,
538                     'ids': ids,
539                     'cr': cr,
540                     'uid': uid
541                 }
542
543                 for act in action.child_ids:
544                     code = """action = {'model':'%s','type':'%s', %s}""" % (action.model_id.model, act.type, act.usage)
545                     exec code in localdict
546                     if 'action' in localdict:
547                         return localdict['action']
548             if action.state == 'object_write':
549                 res = {}
550                 for exp in action.fields_lines:
551                     euq = exp.value
552                     if exp.type == 'equation':
553                         expr = self.merge_message(cr, uid, euq, action, context)
554                         expr = eval(expr)
555                     else:
556                         expr = exp.value
557                     res[exp.col1.name] = expr
558                 obj_pool = self.pool.get(action.model_id.model)
559                 obj_pool.write(cr, uid, [context.get('active_id')], res)
560
561             if action.state == 'object_create':
562                 res = {}
563                 for exp in action.fields_lines:
564                     euq = exp.value
565                     if exp.type == 'equation':
566                         expr = self.merge_message(cr, uid, euq, action, context)
567                         expr = eval(expr)
568                     else:
569                         expr = exp.value
570                     res[exp.col1.name] = expr
571
572                 obj_pool = None
573                 if action.state == 'object_create' and action.otype == 'new':
574                     obj_pool = self.pool.get(action.srcmodel_id.model)
575                     obj_pool.create(cr, uid, res)
576                 else:
577                     obj_pool = self.pool.get(action.model_id.model)
578                     id = context.get('active_id')
579                     obj_pool.copy(cr, uid, id, res)
580
581         return False
582 actions_server()
583
584 class act_window_close(osv.osv):
585     _name = 'ir.actions.act_window_close'
586     _table = 'ir_actions'
587     _sequence = 'ir_actions_id_seq'
588     _columns = {
589         'name': fields.char('Action Name', size=64, translate=True),
590         'type': fields.char('Action Type', size=32, required=True),
591     }
592     _defaults = {
593         'type': lambda *a: 'ir.actions.act_window_close',
594     }
595 act_window_close()
596
597 # This model use to register action services.
598 # if action type is 'configure', it will be start on configuration wizard.
599 # if action type is 'service',
600 #                - if start_type= 'at once', it will be start at one time on start date
601 #                - if start_type='auto', it will be start on auto starting from start date, and stop on stop date
602 #                - if start_type="manual", it will start and stop on manually 
603 class ir_actions_todo(osv.osv):
604     _name = 'ir.actions.todo'   
605     _columns={
606         'name':fields.char('Name',size=64,required=True, select=True),
607         'note':fields.text('Text'),
608                 'start_date': fields.datetime('Start Date'),
609                 'end_date': fields.datetime('End Date'),
610         'action_id':fields.many2one('ir.actions.act_window', 'Action', select=True,required=True, ondelete='cascade'),
611         'sequence':fields.integer('Sequence'),
612                 'active': fields.boolean('Active'),
613                 'type':fields.selection([('configure', 'Configure'),('service', 'Service'),('other','Other')], string='Type', required=True),
614                 'start_on':fields.selection([('at_once', 'At Once'),('auto', 'Auto'),('manual','Manual')], string='Start On'),
615                 'groups_id': fields.many2many('res.groups', 'res_groups_act_todo_rel', 'act_todo_id', 'group_id', 'Groups'),
616                 'users_id': fields.many2many('res.users', 'res_users_act_todo_rel', 'act_todo_id', 'user_id', 'Users'),
617         'state':fields.selection([('open', 'Not Started'),('done', 'Done'),('skip','Skipped'),('cancel','Cancel')], string='State', required=True)
618     }
619     _defaults={
620         'state': lambda *a: 'open',
621         'sequence': lambda *a: 10,
622                 'active':lambda *a:True,
623                 'type':lambda *a:'configure'
624     }
625     _order="sequence"
626 ir_actions_todo()
627
628 # This model to use run all configuration actions
629 class ir_actions_configuration_wizard(osv.osv_memory):
630     _name='ir.actions.configuration.wizard'
631     def next_configuration_action(self,cr,uid,context={}):
632         item_obj = self.pool.get('ir.actions.todo')
633         item_ids = item_obj.search(cr, uid, [('type','=','configure'),('state', '=', 'open'),('active','=',True)], limit=1, context=context)
634         if item_ids and len(item_ids):
635             item = item_obj.browse(cr, uid, item_ids[0], context=context)
636             return item
637         return False
638     def _get_action_name(self, cr, uid, context={}):
639         next_action=self.next_configuration_action(cr,uid,context=context)        
640         if next_action:
641             return next_action.note
642         else:
643             return "Your database is now fully configured.\n\nClick 'Continue' and enjoy your OpenERP experience..."
644         return False
645
646     def _get_action(self, cr, uid, context={}):
647         next_action=self.next_configuration_action(cr,uid,context=context)
648         if next_action:           
649             return next_action.id
650         return False
651
652     def _progress_get(self,cr,uid, context={}):
653         total = self.pool.get('ir.actions.todo').search_count(cr, uid, [], context)
654         todo = self.pool.get('ir.actions.todo').search_count(cr, uid, [('type','=','configure'),('active','=',True),('state','<>','open')], context)
655         return max(5.0,round(todo*100/total))
656
657     _columns = {
658         'name': fields.text('Next Wizard',readonly=True),
659         'progress': fields.float('Configuration Progress', readonly=True),
660         'item_id':fields.many2one('ir.actions.todo', 'Next Configuration Wizard',invisible=True, readonly=True),
661     }
662     _defaults={
663         'progress': _progress_get,
664         'item_id':_get_action,
665         'name':_get_action_name,
666     }
667     def button_skip(self,cr,uid,ids,context=None):
668         item_obj = self.pool.get('ir.actions.todo')
669         item_id=self.read(cr,uid,ids)[0]['item_id']
670         if item_id:
671             item = item_obj.browse(cr, uid, item_id, context=context)
672             item_obj.write(cr, uid, item.id, {
673                 'state': 'skip',
674                 }, context=context)
675             return{
676                 'view_type': 'form',
677                 "view_mode": 'form',
678                 'res_model': 'ir.actions.configuration.wizard',
679                 'type': 'ir.actions.act_window',
680                 'target':'new',
681             }
682         return {'type':'ir.actions.act_window_close'}
683
684     def button_continue(self, cr, uid, ids, context=None):
685         item_obj = self.pool.get('ir.actions.todo')
686         item_id=self.read(cr,uid,ids)[0]['item_id']
687         if item_id:
688             item = item_obj.browse(cr, uid, item_id, context=context)
689             item_obj.write(cr, uid, item.id, {
690                 'state': 'done',
691                 }, context=context)
692             return{
693                   'view_mode': item.action_id.view_mode,
694                   'view_type': item.action_id.view_type,
695                   'view_id':item.action_id.view_id and [item.action_id.view_id.id] or False,
696                   'res_model': item.action_id.res_model,
697                   'type': item.action_id.type,
698                   'target':item.action_id.target,
699             }
700         user_action=self.pool.get('res.users').browse(cr,uid,uid)
701         act_obj=self.pool.get(user_action.menu_id.type)
702         action_ids=act_obj.search(cr,uid,[('name','=',user_action.menu_id.name)])
703         action_open=act_obj.browse(cr,uid,action_ids)[0]
704         if context.get('menu',False):
705             return{
706               'view_type': action_open.view_type,
707               'view_id':action_open.view_id and [action_open.view_id.id] or False,
708               'res_model': action_open.res_model,
709               'type': action_open.type,
710               'domain':action_open.domain
711                }
712         return {'type':'ir.actions.act_window_close' }
713 ir_actions_configuration_wizard()
714
715 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
716