[MERGE + clean] bug fix lp:689566
[odoo/odoo.git] / addons / crm / wizard / crm_phonecall_to_meeting.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import osv
23 from tools.translate import _
24 import wizard
25 import pooler
26
27 #===============================================================================
28 # Put original wizard because of action in init
29 # Remove it after solution foraction in init
30 #===============================================================================
31
32 class phonecall2meeting(wizard.interface):
33
34     def _makeMeeting(self, cr, uid, data, context=None):
35         pool = pooler.get_pool(cr.dbname)
36         phonecall_case_obj = pool.get('crm.phonecall')                   
37         data_obj = pool.get('ir.model.data')
38         result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
39         id = data_obj.read(cr, uid, result, ['res_id'])
40         id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
41         id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
42         id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
43         if id1:
44             id1 = data_obj.browse(cr, uid, id1, context=context).res_id
45         if id2:
46             id2 = data_obj.browse(cr, uid, id2, context=context).res_id
47         if id3:
48             id3 = data_obj.browse(cr, uid, id3, context=context).res_id
49         phonecall = phonecall_case_obj.browse(cr, uid, data['id'], context=context)
50         partner_id = phonecall.partner_id and phonecall.partner_id.id or False
51         name = phonecall.name
52         email = phonecall.email_from
53         section_id = phonecall.section_id and phonecall.section_id.id or False      
54         return {            
55             'name': _('Meetings'),
56             'domain' : "[('user_id','=',%s)]"%(uid), 
57             'context': {'default_partner_id': partner_id, 'default_section_id': section_id, 'default_email_from': email, 'default_state':'open', 'default_name':name},        
58             'view_type': 'form',
59             'view_mode': 'calendar,form,tree',
60             'res_model': 'crm.meeting',
61             'view_id': False,
62             'views': [(id1,'calendar'),(id2,'form'),(id3,'tree')],
63             'type': 'ir.actions.act_window',
64             'search_view_id': id['res_id']
65             }
66
67     states = {
68         'init': {
69             'actions': [],
70             'result': {'type': 'action', 'action': _makeMeeting, 'state': 'order'}
71         },
72         'order': {
73             'actions': [],
74             'result': {'type': 'state', 'state': 'end'}
75         }
76     }
77 phonecall2meeting('crm.phonecall.meeting_set')
78
79 class crm_phonecall2meeting(osv.osv_memory):
80     """ Phonecall to Meeting """
81
82     _name = 'crm.phonecall2meeting'
83     _description = 'Phonecall To Meeting'
84
85     def action_cancel(self, cr, uid, ids, context=None):
86         """
87         Closes Phonecall to Meeting form
88         @param self: The object pointer
89         @param cr: the current row, from the database cursor,
90         @param uid: the current user’s ID for security checks,
91         @param ids: List of Phonecall to Meeting IDs
92         @param context: A standard dictionary for contextual values
93
94         """
95         return {'type':'ir.actions.act_window_close'}
96
97     def action_make_meeting(self, cr, uid, ids, context=None):
98         """
99         This opens Meeting's calendar view to schedule meeting on current Phonecall
100         @param self: The object pointer
101         @param cr: the current row, from the database cursor,
102         @param uid: the current user’s ID for security checks,
103         @param ids: List of Phonecall to Meeting IDs
104         @param context: A standard dictionary for contextual values
105
106         @return : Dictionary value for created Meeting view
107         """
108         value = {}
109         record_id = context and context.get('active_id', False) or False
110
111         if record_id:
112             phonecall_obj = self.pool.get('crm.phonecall')                   
113             data_obj = self.pool.get('ir.model.data')
114
115             # Get meeting views
116             result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
117             res = data_obj.read(cr, uid, result, ['res_id'])
118             id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
119             id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
120             id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
121             if id1:
122                 id1 = data_obj.browse(cr, uid, id1, context=context).res_id
123             if id2:
124                 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
125             if id3:
126                 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
127
128             phonecall = phonecall_obj.browse(cr, uid, record_id, context=context)
129             context = {
130                         'default_phonecall_id': phonecall.id, 
131                         'default_partner_id': phonecall.partner_id and phonecall.partner_id.id or False, 
132                         'default_email': phonecall.email_from , 
133                         'default_name': phonecall.name
134                     }
135
136             value = {
137                 'name': _('Meetings'), 
138                 'domain' : "[('user_id','=',%s)]" % (uid), 
139                 'context': context, 
140                 'view_type': 'form', 
141                 'view_mode': 'calendar,form,tree', 
142                 'res_model': 'crm.meeting', 
143                 'view_id': False, 
144                 'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')], 
145                 'type': 'ir.actions.act_window', 
146                 'search_view_id': res['res_id']
147                 }
148
149         return value
150
151 crm_phonecall2meeting()
152
153 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: