2010-03-17 12:57:11 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
2010-03-10 06:13:42 +00:00
|
|
|
|
#
|
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-03-17 12:57:11 +00:00
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2010-03-10 06:13:42 +00:00
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2010-03-17 12:57:11 +00:00
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
2010-03-10 06:13:42 +00:00
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-03-17 12:57:11 +00:00
|
|
|
|
# GNU Affero General Public License for more details.
|
2010-03-10 06:13:42 +00:00
|
|
|
|
#
|
2010-03-17 12:57:11 +00:00
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-03-10 06:13:42 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
2010-03-17 12:57:11 +00:00
|
|
|
|
##############################################################################
|
2010-03-10 06:13:42 +00:00
|
|
|
|
|
|
|
|
|
from osv import osv, fields
|
|
|
|
|
from tools.translate import _
|
|
|
|
|
|
2011-04-27 09:22:02 +00:00
|
|
|
|
import time
|
|
|
|
|
|
2010-03-10 06:13:42 +00:00
|
|
|
|
class crm_phonecall2phonecall(osv.osv_memory):
|
2010-03-17 12:57:11 +00:00
|
|
|
|
""" Converts Phonecall to Phonecall"""
|
|
|
|
|
|
2010-03-10 06:13:42 +00:00
|
|
|
|
_name = 'crm.phonecall2phonecall'
|
|
|
|
|
_description = 'Phonecall To Phonecall'
|
|
|
|
|
|
|
|
|
|
def action_cancel(self, cr, uid, ids, context=None):
|
2010-03-17 12:57:11 +00:00
|
|
|
|
"""
|
|
|
|
|
Closes Phonecall to Phonecall form
|
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of Phonecall to Phonecall's IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
"""
|
2010-03-10 06:13:42 +00:00
|
|
|
|
return {'type':'ir.actions.act_window_close'}
|
|
|
|
|
|
|
|
|
|
def action_apply(self, cr, uid, ids, context=None):
|
2010-03-17 12:57:11 +00:00
|
|
|
|
"""
|
|
|
|
|
This converts Phonecall to Phonecall and opens Phonecall view
|
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of Phonecall to Phonecall IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
|
|
|
|
|
@return : Dictionary value for created Opportunity form
|
|
|
|
|
"""
|
|
|
|
|
res = {}
|
|
|
|
|
record_id = context and context.get('active_id', False) or False
|
|
|
|
|
phonecall_obj = self.pool.get('crm.phonecall')
|
|
|
|
|
|
2010-03-10 06:13:42 +00:00
|
|
|
|
if record_id:
|
2010-03-17 12:57:11 +00:00
|
|
|
|
data_obj = self.pool.get('ir.model.data')
|
2010-03-22 10:40:26 +00:00
|
|
|
|
|
2010-03-17 12:57:11 +00:00
|
|
|
|
# Get Phonecall views
|
|
|
|
|
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
|
|
|
|
|
res = data_obj.read(cr, uid, result, ['res_id'])
|
|
|
|
|
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_form_view')
|
|
|
|
|
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_tree_view')
|
|
|
|
|
if id2:
|
|
|
|
|
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
|
|
|
|
|
if id3:
|
|
|
|
|
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
|
|
|
|
|
|
|
|
|
|
phonecall = phonecall_obj.browse(cr, uid, record_id, context=context)
|
|
|
|
|
|
|
|
|
|
for this in self.browse(cr, uid, ids, context=context):
|
|
|
|
|
values = {
|
2010-03-22 10:40:26 +00:00
|
|
|
|
'name': this.name,
|
|
|
|
|
'user_id': this.user_id and this.user_id.id,
|
2010-07-09 06:25:00 +00:00
|
|
|
|
'categ_id': this.categ_id.id,
|
|
|
|
|
'section_id': this.section_id.id or (phonecall.section_id and phonecall.section_id.id),
|
2010-03-22 10:40:26 +00:00
|
|
|
|
'description': phonecall.description or '',
|
|
|
|
|
'partner_id': phonecall.partner_id.id,
|
|
|
|
|
'partner_address_id': phonecall.partner_address_id.id,
|
|
|
|
|
'partner_mobile': phonecall.partner_mobile or False,
|
|
|
|
|
'priority': phonecall.priority,
|
|
|
|
|
'partner_phone': phonecall.partner_phone or False,
|
2010-03-17 12:57:11 +00:00
|
|
|
|
'date': this.date
|
|
|
|
|
}
|
|
|
|
|
phonecall_id = phonecall_obj.create(cr, uid, values, context=context)
|
2011-04-19 10:00:53 +00:00
|
|
|
|
if this.action == 'schedule':
|
|
|
|
|
phonecall_obj.case_open(cr, uid, [phonecall_id])
|
|
|
|
|
elif this.action == 'log':
|
|
|
|
|
phonecall_obj.case_close(cr, uid, [phonecall_id])
|
2010-03-25 13:05:11 +00:00
|
|
|
|
|
2010-03-17 12:57:11 +00:00
|
|
|
|
res = {
|
2010-03-10 06:13:42 +00:00
|
|
|
|
'name': _('Phone Call'),
|
|
|
|
|
'view_type': 'form',
|
|
|
|
|
'view_mode': 'form',
|
|
|
|
|
'res_model': 'crm.phonecall',
|
|
|
|
|
'view_id': False,
|
2010-03-17 12:57:11 +00:00
|
|
|
|
'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
|
2010-03-10 06:13:42 +00:00
|
|
|
|
'type': 'ir.actions.act_window',
|
2010-05-06 13:44:29 +00:00
|
|
|
|
'res_id': phonecall_id,
|
2010-07-09 06:25:00 +00:00
|
|
|
|
'domain': [('id', '=', phonecall_id)],
|
2010-05-06 13:44:29 +00:00
|
|
|
|
'search_view_id': res['res_id']
|
2010-03-10 06:13:42 +00:00
|
|
|
|
}
|
2010-03-17 12:57:11 +00:00
|
|
|
|
return res
|
2010-03-10 06:13:42 +00:00
|
|
|
|
|
|
|
|
|
_columns = {
|
2010-03-17 12:57:11 +00:00
|
|
|
|
'name' : fields.char('Call summary', size=64, required=True, select=1),
|
|
|
|
|
'user_id' : fields.many2one('res.users',"Assign To"),
|
2011-04-19 10:00:53 +00:00
|
|
|
|
'categ_id': fields.many2one('crm.case.categ', 'Category', \
|
2010-09-28 22:03:25 +00:00
|
|
|
|
domain="['|',('section_id','=',False),('section_id','=',section_id),\
|
2010-07-09 06:25:00 +00:00
|
|
|
|
('object_id.model', '=', 'crm.phonecall')]"),
|
2011-04-27 09:22:02 +00:00
|
|
|
|
'date': fields.datetime('Date'),
|
2010-03-17 12:57:11 +00:00
|
|
|
|
'section_id':fields.many2one('crm.case.section','Sales Team'),
|
2011-04-19 10:00:53 +00:00
|
|
|
|
'action': fields.selection([('schedule','Schedule a call'), ('log','Log a call')], 'Action', required=True),
|
2010-03-17 12:57:11 +00:00
|
|
|
|
}
|
2010-03-22 10:40:26 +00:00
|
|
|
|
|
2010-03-10 06:13:42 +00:00
|
|
|
|
def default_get(self, cr, uid, fields, context=None):
|
2010-03-17 12:57:11 +00:00
|
|
|
|
"""
|
|
|
|
|
This function gets default values
|
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param fields: List of fields for default value
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
|
|
|
|
|
@return : default values of fields.
|
|
|
|
|
"""
|
2010-03-19 11:01:15 +00:00
|
|
|
|
res = super(crm_phonecall2phonecall, self).default_get(cr, uid, fields, context=context)
|
2010-03-17 12:57:11 +00:00
|
|
|
|
record_id = context and context.get('active_id', False) or False
|
2011-04-27 09:22:02 +00:00
|
|
|
|
res.update({'action': 'schedule', 'date': time.strftime('%Y-%m-%d %H:%M:%S')})
|
2010-03-10 06:13:42 +00:00
|
|
|
|
if record_id:
|
2010-03-17 12:57:11 +00:00
|
|
|
|
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
|
2010-03-22 10:40:26 +00:00
|
|
|
|
|
2010-07-09 06:25:00 +00:00
|
|
|
|
categ_id = False
|
|
|
|
|
data_obj = self.pool.get('ir.model.data')
|
|
|
|
|
res_id = data_obj._get_id(cr, uid, 'crm', 'categ_phone2')
|
|
|
|
|
if res_id:
|
|
|
|
|
categ_id = data_obj.browse(cr, uid, res_id, context=context).res_id
|
|
|
|
|
|
2010-03-19 11:01:15 +00:00
|
|
|
|
if 'name' in fields:
|
|
|
|
|
res.update({'name': phonecall.name})
|
|
|
|
|
if 'user_id' in fields:
|
|
|
|
|
res.update({'user_id': phonecall.user_id and phonecall.user_id.id or False})
|
|
|
|
|
if 'date' in fields:
|
|
|
|
|
res.update({'date': phonecall.date})
|
|
|
|
|
if 'section_id' in fields:
|
|
|
|
|
res.update({'section_id': phonecall.section_id and phonecall.section_id.id or False})
|
2010-07-09 06:25:00 +00:00
|
|
|
|
if 'categ_id' in fields:
|
|
|
|
|
res.update({'categ_id': categ_id})
|
2010-03-10 06:13:42 +00:00
|
|
|
|
return res
|
2010-03-17 12:57:11 +00:00
|
|
|
|
|
|
|
|
|
crm_phonecall2phonecall()
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|