1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools.translate import _
25 class crm_phonecall2phonecall(osv.osv_memory):
26 """ Converts Phonecall to Phonecall"""
28 _name = 'crm.phonecall2phonecall'
29 _description = 'Phonecall To Phonecall'
31 def action_cancel(self, cr, uid, ids, context=None):
33 Closes Phonecall to Phonecall form
34 @param self: The object pointer
35 @param cr: the current row, from the database cursor,
36 @param uid: the current user’s ID for security checks,
37 @param ids: List of Phonecall to Phonecall's IDs
38 @param context: A standard dictionary for contextual values
40 return {'type':'ir.actions.act_window_close'}
42 def action_apply(self, cr, uid, ids, context=None):
44 This converts Phonecall to Phonecall and opens Phonecall view
45 @param self: The object pointer
46 @param cr: the current row, from the database cursor,
47 @param uid: the current user’s ID for security checks,
48 @param ids: List of Phonecall to Phonecall IDs
49 @param context: A standard dictionary for contextual values
51 @return : Dictionary value for created Opportunity form
54 record_id = context and context.get('active_id', False) or False
55 phonecall_obj = self.pool.get('crm.phonecall')
58 data_obj = self.pool.get('ir.model.data')
61 result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
62 res = data_obj.read(cr, uid, result, ['res_id'])
63 id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_form_view')
64 id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_tree_view')
66 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
68 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
70 phonecall = phonecall_obj.browse(cr, uid, record_id, context=context)
72 for this in self.browse(cr, uid, ids, context=context):
75 'user_id': this.user_id and this.user_id.id,
76 'categ_id': this.categ_id.id,
77 'section_id': this.section_id.id or (phonecall.section_id and phonecall.section_id.id),
78 'description': phonecall.description or '',
79 'partner_id': phonecall.partner_id.id,
80 'partner_address_id': phonecall.partner_address_id.id,
81 'partner_mobile': phonecall.partner_mobile or False,
82 'priority': phonecall.priority,
83 'partner_phone': phonecall.partner_phone or False,
86 phonecall_id = phonecall_obj.create(cr, uid, values, context=context)
89 'name': _('Phone Call'),
92 'res_model': 'crm.phonecall',
94 'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
95 'type': 'ir.actions.act_window',
96 'res_id': phonecall_id,
97 'domain': [('id', '=', phonecall_id)],
98 'search_view_id': res['res_id']
103 'name' : fields.char('Call summary', size=64, required=True, select=1),
104 'user_id' : fields.many2one('res.users',"Assign To"),
105 'categ_id': fields.many2one('crm.case.categ', 'Category', required=True, \
106 domain="['|',('section_id','=',False),('section_id','=',section_id),\
107 ('object_id.model', '=', 'crm.phonecall')]"),
108 'date': fields.datetime('Date', required=True),
109 'section_id':fields.many2one('crm.case.section','Sales Team'),
112 def default_get(self, cr, uid, fields, context=None):
114 This function gets default values
115 @param self: The object pointer
116 @param cr: the current row, from the database cursor,
117 @param uid: the current user’s ID for security checks,
118 @param fields: List of fields for default value
119 @param context: A standard dictionary for contextual values
121 @return : default values of fields.
123 res = super(crm_phonecall2phonecall, self).default_get(cr, uid, fields, context=context)
124 record_id = context and context.get('active_id', False) or False
127 phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
130 data_obj = self.pool.get('ir.model.data')
131 res_id = data_obj._get_id(cr, uid, 'crm', 'categ_phone2')
133 categ_id = data_obj.browse(cr, uid, res_id, context=context).res_id
136 res.update({'name': phonecall.name})
137 if 'user_id' in fields:
138 res.update({'user_id': phonecall.user_id and phonecall.user_id.id or False})
140 res.update({'date': phonecall.date})
141 if 'section_id' in fields:
142 res.update({'section_id': phonecall.section_id and phonecall.section_id.id or False})
143 if 'categ_id' in fields:
144 res.update({'categ_id': categ_id})
147 crm_phonecall2phonecall()
149 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: