[MERGE] with trunk
[odoo/odoo.git] / addons / crm / wizard / wizard_history_event.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution    
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero 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.
12 #
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 Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 import wizard
24 import pooler
25
26 def _open_history_event(self, cr, uid, data, context=None):
27     pool = pooler.get_pool(cr.dbname)
28     data_obj = pool.get('ir.model.data')
29     result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_filter')
30     id = data_obj.read(cr, uid, result, ['res_id'])
31     id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_section-view')
32     if id2:
33         id2 = data_obj.browse(cr, uid, id2, context=context).res_id 
34     res = ''    
35     if data.get('model',False) and data.get('ids',False):           
36         model_obj = pooler.get_pool(cr.dbname).get(data['model'])
37         res = model_obj.browse(cr, uid, data['ids'], context=context)
38         if len(res):
39             res = res[0].name       
40     return {
41         'name': 'History : ' +  res,
42         'view_type': 'form',
43         "view_mode": 'calendar, tree, form',
44         'view_id' : False,
45         'views': [(id2,'calendar'),(False,'form'),(False,'tree'),(False,'graph')],
46         'res_model': 'crm.case',
47         'type': 'ir.actions.act_window',
48         'domain': data.get('id',False) and "[('case_id','=',%d)]" % (data['id']) or "[]",
49         'search_view_id': id['res_id'] 
50     }
51     
52 class case_history_event(wizard.interface):
53     states = {
54     'init': {
55             'actions': [],
56             'result': {'type': 'action', 'action': _open_history_event, 'state':'end'}
57         }
58     }
59     
60 case_history_event('crm.case.history.events')