2009-12-30 10:20:44 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
2010-01-08 11:05:05 +00:00
|
|
|
|
#
|
2009-12-30 10:20:44 +00:00
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2009-12-30 10:20:44 +00:00
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# 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.
|
|
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-01-08 11:05:05 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-12-30 10:20:44 +00:00
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2010-05-05 11:55:13 +00:00
|
|
|
|
from crm import crm_case
|
2009-12-30 10:20:44 +00:00
|
|
|
|
from osv import fields, osv
|
2010-04-01 11:31:30 +00:00
|
|
|
|
from tools.translate import _
|
2010-01-13 13:34:09 +00:00
|
|
|
|
import crm
|
2010-02-28 20:36:51 +00:00
|
|
|
|
import time
|
2010-07-13 10:05:22 +00:00
|
|
|
|
from datetime import datetime, timedelta
|
2010-01-11 13:16:46 +00:00
|
|
|
|
|
2010-08-17 12:54:00 +00:00
|
|
|
|
class crm_phonecall(crm_case, osv.osv):
|
2010-03-22 10:40:26 +00:00
|
|
|
|
""" Phonecall Cases """
|
|
|
|
|
|
2009-12-30 10:20:44 +00:00
|
|
|
|
_name = "crm.phonecall"
|
2010-05-19 18:32:32 +00:00
|
|
|
|
_description = "Phonecall"
|
2009-12-30 10:20:44 +00:00
|
|
|
|
_order = "id desc"
|
2010-06-23 20:29:29 +00:00
|
|
|
|
_inherit = ['mailgate.thread']
|
2010-01-08 11:05:05 +00:00
|
|
|
|
_columns = {
|
2010-05-03 12:30:48 +00:00
|
|
|
|
# From crm.case
|
2010-08-06 13:26:50 +00:00
|
|
|
|
'id': fields.integer('ID'),
|
2010-09-21 16:39:51 +00:00
|
|
|
|
'name': fields.char('Call Summary', size=64),
|
2010-05-19 13:42:43 +00:00
|
|
|
|
'active': fields.boolean('Active', required=False),
|
2010-05-26 12:13:46 +00:00
|
|
|
|
'date_action_last': fields.datetime('Last Action', readonly=1),
|
|
|
|
|
'date_action_next': fields.datetime('Next Action', readonly=1),
|
|
|
|
|
'create_date': fields.datetime('Creation Date' , readonly=True),
|
2010-05-03 12:30:48 +00:00
|
|
|
|
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
|
2010-07-15 13:18:56 +00:00
|
|
|
|
select=True, help='Sales team to which Case belongs to.'),
|
2010-05-03 12:30:48 +00:00
|
|
|
|
'user_id': fields.many2one('res.users', 'Responsible'),
|
|
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner'),
|
2010-05-03 13:41:42 +00:00
|
|
|
|
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
|
2010-05-04 07:33:13 +00:00
|
|
|
|
domain="[('partner_id','=',partner_id)]"),
|
|
|
|
|
'company_id': fields.many2one('res.company', 'Company'),
|
2010-05-06 10:27:00 +00:00
|
|
|
|
'description': fields.text('Description'),
|
2010-05-06 13:44:29 +00:00
|
|
|
|
'state': fields.selection([
|
|
|
|
|
('draft', 'Draft'),
|
|
|
|
|
('open', 'Todo'),
|
|
|
|
|
('cancel', 'Cancelled'),
|
2011-04-14 11:57:33 +00:00
|
|
|
|
('done', 'Held'),
|
2011-04-20 09:17:39 +00:00
|
|
|
|
('pending', 'Pending'),
|
2010-05-06 13:44:29 +00:00
|
|
|
|
], 'State', size=16, readonly=True,
|
2010-05-03 13:41:42 +00:00
|
|
|
|
help='The state is set to \'Draft\', when a case is created.\
|
|
|
|
|
\nIf the case is in progress the state is set to \'Open\'.\
|
|
|
|
|
\nWhen the case is over, the state is set to \'Done\'.\
|
|
|
|
|
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
|
2010-05-06 10:27:00 +00:00
|
|
|
|
'email_from': fields.char('Email', size=128, help="These people will receive email."),
|
|
|
|
|
'date_open': fields.datetime('Opened', readonly=True),
|
2010-05-03 12:30:48 +00:00
|
|
|
|
# phonecall fields
|
2010-07-13 10:05:22 +00:00
|
|
|
|
'duration': fields.float('Duration', help="Duration in Minutes"),
|
2010-03-22 10:40:26 +00:00
|
|
|
|
'categ_id': fields.many2one('crm.case.categ', 'Category', \
|
2010-09-28 22:03:25 +00:00
|
|
|
|
domain="['|',('section_id','=',section_id),('section_id','=',False),\
|
2010-05-03 13:41:42 +00:00
|
|
|
|
('object_id.model', '=', 'crm.phonecall')]"),
|
|
|
|
|
'partner_phone': fields.char('Phone', size=32),
|
|
|
|
|
'partner_contact': fields.related('partner_address_id', 'name', \
|
|
|
|
|
type="char", string="Contact", size=128),
|
|
|
|
|
'partner_mobile': fields.char('Mobile', size=32),
|
|
|
|
|
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
|
|
|
|
|
'canal_id': fields.many2one('res.partner.canal', 'Channel', \
|
2010-03-22 10:40:26 +00:00
|
|
|
|
help="The channels represent the different communication\
|
|
|
|
|
modes available with the customer." \
|
|
|
|
|
" With each commercial opportunity, you can indicate\
|
2010-05-03 13:41:42 +00:00
|
|
|
|
the canall which is this opportunity source."),
|
|
|
|
|
'date_closed': fields.datetime('Closed', readonly=True),
|
|
|
|
|
'date': fields.datetime('Date'),
|
2011-04-20 09:17:39 +00:00
|
|
|
|
'opportunity_id': fields.many2one ('crm.lead', 'Lead/Opportunity'),
|
2010-07-16 10:41:21 +00:00
|
|
|
|
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
|
2009-12-30 10:20:44 +00:00
|
|
|
|
}
|
2010-03-22 10:40:26 +00:00
|
|
|
|
|
2011-04-14 11:57:33 +00:00
|
|
|
|
def _get_default_state(self, cr, uid, context=None):
|
|
|
|
|
if context and context.get('default_state', False):
|
|
|
|
|
return context.get('default_state')
|
|
|
|
|
return 'open'
|
|
|
|
|
|
2010-02-28 13:21:56 +00:00
|
|
|
|
_defaults = {
|
2010-05-03 13:41:42 +00:00
|
|
|
|
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
2011-01-31 13:29:31 +00:00
|
|
|
|
'priority': crm.AVAILABLE_PRIORITIES[2][0],
|
2011-04-14 11:57:33 +00:00
|
|
|
|
'state': _get_default_state,
|
2010-05-31 17:09:19 +00:00
|
|
|
|
'user_id': lambda self,cr,uid,ctx: uid,
|
2011-01-31 13:29:31 +00:00
|
|
|
|
'active': 1,
|
2010-02-28 13:21:56 +00:00
|
|
|
|
}
|
2010-05-03 13:41:42 +00:00
|
|
|
|
|
|
|
|
|
# From crm.case
|
2010-05-05 13:02:55 +00:00
|
|
|
|
|
|
|
|
|
def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
|
|
|
|
|
res = super(crm_phonecall, self).onchange_partner_address_id(cr, uid, ids, add, email)
|
|
|
|
|
res.setdefault('value', {})
|
|
|
|
|
if add:
|
|
|
|
|
address = self.pool.get('res.partner.address').browse(cr, uid, add)
|
|
|
|
|
res['value']['partner_phone'] = address.phone
|
|
|
|
|
res['value']['partner_mobile'] = address.mobile
|
|
|
|
|
return res
|
|
|
|
|
|
2010-05-03 13:41:42 +00:00
|
|
|
|
def case_close(self, cr, uid, ids, *args):
|
2010-05-05 11:55:13 +00:00
|
|
|
|
"""Overrides close for crm_case for setting close date
|
2010-05-03 13:41:42 +00:00
|
|
|
|
@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 case Ids
|
|
|
|
|
@param *args: Tuple Value for additional Params
|
|
|
|
|
"""
|
2010-07-13 10:05:22 +00:00
|
|
|
|
for phone in self.browse(cr, uid, ids):
|
|
|
|
|
phone_id= phone.id
|
|
|
|
|
data = {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')}
|
|
|
|
|
if phone.duration <=0:
|
|
|
|
|
duration = datetime.now() - datetime.strptime(phone.date, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
data.update({'duration': duration.seconds/float(60)})
|
|
|
|
|
res = super(crm_phonecall, self).case_close(cr, uid, [phone_id], args)
|
|
|
|
|
self.write(cr, uid, ids, data)
|
2010-05-05 11:55:13 +00:00
|
|
|
|
return res
|
2010-05-03 13:41:42 +00:00
|
|
|
|
|
2010-07-13 10:05:22 +00:00
|
|
|
|
def case_reset(self, cr, uid, ids, *args):
|
|
|
|
|
"""Resets case as draft
|
|
|
|
|
@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 case Ids
|
|
|
|
|
@param *args: Tuple Value for additional Params
|
|
|
|
|
"""
|
|
|
|
|
res = super(crm_phonecall, self).case_reset(cr, uid, ids, args)
|
|
|
|
|
self.write(cr, uid, ids, {'duration': 0.0})
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
2010-05-03 13:41:42 +00:00
|
|
|
|
def case_open(self, cr, uid, ids, *args):
|
2010-05-05 11:55:13 +00:00
|
|
|
|
"""Overrides cancel for crm_case for setting Open Date
|
2010-05-03 13:41:42 +00:00
|
|
|
|
@param self: The object pointer
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-05-05 11:55:13 +00:00
|
|
|
|
@param ids: List of case's Ids
|
|
|
|
|
@param *args: Give Tuple Value
|
2010-05-03 13:41:42 +00:00
|
|
|
|
"""
|
2010-05-05 11:55:13 +00:00
|
|
|
|
res = super(crm_phonecall, self).case_open(cr, uid, ids, *args)
|
|
|
|
|
self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
|
|
|
|
|
return res
|
2010-03-22 10:40:26 +00:00
|
|
|
|
|
2010-04-01 11:31:30 +00:00
|
|
|
|
def action_make_meeting(self, cr, uid, ids, context=None):
|
|
|
|
|
"""
|
|
|
|
|
This opens Meeting's calendar view to schedule meeting on current Phonecall
|
|
|
|
|
@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 Meeting IDs
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
|
|
|
|
|
@return : Dictionary value for created Meeting view
|
|
|
|
|
"""
|
|
|
|
|
value = {}
|
2010-11-19 13:48:01 +00:00
|
|
|
|
for phonecall in self.browse(cr, uid, ids, context=context):
|
2010-04-01 11:31:30 +00:00
|
|
|
|
data_obj = self.pool.get('ir.model.data')
|
|
|
|
|
|
|
|
|
|
# Get meeting views
|
|
|
|
|
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
|
|
|
|
|
res = data_obj.read(cr, uid, result, ['res_id'])
|
|
|
|
|
id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
|
|
|
|
|
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
|
|
|
|
|
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
|
|
|
|
|
if id1:
|
|
|
|
|
id1 = data_obj.browse(cr, uid, id1, context=context).res_id
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
context = {
|
2010-05-03 13:41:42 +00:00
|
|
|
|
'default_phonecall_id': phonecall.id,
|
|
|
|
|
'default_partner_id': phonecall.partner_id and phonecall.partner_id.id or False,
|
|
|
|
|
'default_email': phonecall.email_from ,
|
2010-04-01 11:31:30 +00:00
|
|
|
|
'default_name': phonecall.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = {
|
2010-05-03 13:41:42 +00:00
|
|
|
|
'name': _('Meetings'),
|
|
|
|
|
'domain' : "[('user_id','=',%s)]" % (uid),
|
|
|
|
|
'context': context,
|
|
|
|
|
'view_type': 'form',
|
|
|
|
|
'view_mode': 'calendar,form,tree',
|
|
|
|
|
'res_model': 'crm.meeting',
|
|
|
|
|
'view_id': False,
|
|
|
|
|
'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')],
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'search_view_id': res['res_id'],
|
2010-04-01 11:31:30 +00:00
|
|
|
|
'nodestroy': True
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
2009-12-31 12:57:20 +00:00
|
|
|
|
crm_phonecall()
|
|
|
|
|
|
2010-05-13 14:15:36 +00:00
|
|
|
|
|
2010-04-07 07:03:45 +00:00
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|