2009-12-30 10:20:44 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# 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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2012-05-30 07:47:41 +00:00
from base_status . base_state import base_state
2012-09-17 10:11:09 +00:00
from base_status . base_stage import base_stage
2010-04-28 11:26:12 +00:00
from crm import crm
2010-05-06 07:31:09 +00:00
from osv import fields , osv
2011-02-15 09:42:10 +00:00
import tools
2011-07-05 05:46:19 +00:00
from tools . translate import _
2011-02-15 09:42:10 +00:00
CRM_HELPDESK_STATES = (
crm . AVAILABLE_STATES [ 2 ] [ 0 ] , # Cancelled
crm . AVAILABLE_STATES [ 3 ] [ 0 ] , # Done
crm . AVAILABLE_STATES [ 4 ] [ 0 ] , # Pending
)
2010-01-11 12:18:27 +00:00
2012-09-17 10:11:09 +00:00
class crm_helpdesk ( base_state , base_stage , osv . osv ) :
2010-03-22 10:40:26 +00:00
""" Helpdesk Cases """
2009-12-30 10:20:44 +00:00
_name = " crm.helpdesk "
2010-07-22 11:00:56 +00:00
_description = " Helpdesk "
2009-12-30 10:20:44 +00:00
_order = " id desc "
2011-07-22 18:23:37 +00:00
_inherit = [ ' mail.thread ' ]
2012-08-21 14:27:47 +00:00
2010-01-08 11:05:05 +00:00
_columns = {
2011-02-07 05:51:57 +00:00
' id ' : fields . integer ( ' ID ' , readonly = True ) ,
' name ' : fields . char ( ' Name ' , size = 128 , required = True ) ,
' active ' : fields . boolean ( ' Active ' , required = False ) ,
' date_action_last ' : fields . datetime ( ' Last Action ' , readonly = 1 ) ,
' date_action_next ' : fields . datetime ( ' Next Action ' , readonly = 1 ) ,
' description ' : fields . text ( ' Description ' ) ,
' create_date ' : fields . datetime ( ' Creation Date ' , readonly = True ) ,
' write_date ' : fields . datetime ( ' Update Date ' , readonly = True ) ,
' date_deadline ' : fields . date ( ' Deadline ' ) ,
' user_id ' : fields . many2one ( ' res.users ' , ' Responsible ' ) ,
2010-05-06 07:31:09 +00:00
' section_id ' : fields . many2one ( ' crm.case.section ' , ' Sales Team ' , \
select = True , help = ' Sales team to which Case belongs to. \
2011-02-07 05:51:57 +00:00
Define Responsible user and Email account for mail gateway . ' ),
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' ) ,
' date_closed ' : fields . datetime ( ' Closed ' , readonly = True ) ,
' partner_id ' : fields . many2one ( ' res.partner ' , ' Partner ' ) ,
' email_cc ' : fields . text ( ' Watchers Emails ' , size = 252 , help = " These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma " ) ,
' email_from ' : fields . char ( ' Email ' , size = 128 , help = " These people will receive email. " ) ,
' date ' : fields . datetime ( ' Date ' ) ,
' ref ' : fields . reference ( ' Reference ' , selection = crm . _links_get , size = 128 ) ,
' ref2 ' : fields . reference ( ' Reference 2 ' , selection = crm . _links_get , size = 128 ) ,
2011-08-27 23:31:30 +00:00
' channel_id ' : fields . many2one ( ' crm.case.channel ' , ' Channel ' , help = " Communication channel. " ) ,
2011-02-07 05:51:57 +00:00
' planned_revenue ' : fields . float ( ' Planned Revenue ' ) ,
' planned_cost ' : fields . float ( ' Planned Costs ' ) ,
' priority ' : fields . selection ( crm . AVAILABLE_PRIORITIES , ' Priority ' ) ,
' probability ' : fields . float ( ' Probability ( % ) ' ) ,
2010-03-23 05:55:46 +00:00
' categ_id ' : fields . many2one ( ' crm.case.categ ' , ' Category ' , \
2011-07-19 05:49:15 +00:00
domain = " [ ' | ' ,( ' section_id ' , ' = ' ,False),( ' section_id ' , ' = ' ,section_id), \
2012-10-02 10:29:15 +00:00
( ' object_id.model ' , ' = ' , ' crm.helpdesk ' ) ] " ),
' duration ' : fields . float ( ' Duration ' , states = { ' done ' : [ ( ' readonly ' , True ) ] } ) ,
' state ' : fields . selection ( crm . AVAILABLE_STATES , ' Status ' , size = 16 , readonly = True ,
2010-05-06 07:31:09 +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 \' . \
2010-07-08 06:18:06 +00:00
\nIf the case needs to be reviewed then the state is set to \' Pending \' . ' ) ,
2009-12-30 10:20:44 +00:00
}
2010-03-22 10:40:26 +00:00
2010-03-22 08:13:44 +00:00
_defaults = {
2011-02-07 05:51:57 +00:00
' active ' : lambda * a : 1 ,
2012-05-29 14:23:33 +00:00
' user_id ' : lambda s , cr , uid , c : s . _get_default_user ( cr , uid , c ) ,
' partner_id ' : lambda s , cr , uid , c : s . _get_default_partner ( cr , uid , c ) ,
' email_from ' : lambda s , cr , uid , c : s . _get_default_email ( cr , uid , c ) ,
2011-02-07 05:51:57 +00:00
' state ' : lambda * a : ' draft ' ,
2012-05-29 14:23:33 +00:00
' date ' : lambda * a : fields . datetime . now ( ) ,
2011-02-07 05:51:57 +00:00
' company_id ' : lambda s , cr , uid , c : s . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' crm.helpdesk ' , context = c ) ,
' priority ' : lambda * a : crm . AVAILABLE_PRIORITIES [ 2 ] [ 0 ] ,
2010-03-22 08:13:44 +00:00
}
2010-02-02 07:50:19 +00:00
2012-04-30 10:56:06 +00:00
def create ( self , cr , uid , vals , context = None ) :
obj_id = super ( crm_helpdesk , self ) . create ( cr , uid , vals , context )
self . create_send_note ( cr , uid , [ obj_id ] , context = context )
return obj_id
2012-06-04 14:12:54 +00:00
# -------------------------------------------------------
# Mail gateway
# -------------------------------------------------------
def message_new ( self , cr , uid , msg , custom_values = None , context = None ) :
""" Overrides mail_thread message_new that is called by the mailgateway
through message_process .
This override updates the document according to the email .
"""
if custom_values is None : custom_values = { }
custom_values . update ( {
' name ' : msg . get ( ' subject ' ) or _ ( " No Subject " ) ,
2012-08-17 12:06:06 +00:00
' description ' : msg . get ( ' body ' ) ,
2012-06-04 14:12:54 +00:00
' email_from ' : msg . get ( ' from ' ) ,
' email_cc ' : msg . get ( ' cc ' ) ,
2011-02-15 09:42:10 +00:00
' user_id ' : False ,
2012-06-04 14:12:54 +00:00
} )
2012-06-04 15:01:39 +00:00
return super ( crm_helpdesk , self ) . message_new ( cr , uid , msg , custom_values = custom_values , context = context )
2011-02-15 09:42:10 +00:00
2012-06-04 14:12:54 +00:00
def message_update ( self , cr , uid , ids , msg , update_vals = None , context = None ) :
""" Overrides mail_thread message_update that is called by the mailgateway
through message_process .
This method updates the document according to the email .
"""
2011-02-15 09:42:10 +00:00
if isinstance ( ids , ( str , int , long ) ) :
ids = [ ids ]
2012-06-04 14:12:54 +00:00
if update_vals is None : update_vals = { }
2011-07-22 18:23:37 +00:00
2011-02-15 09:42:10 +00:00
if msg . get ( ' priority ' ) in dict ( crm . AVAILABLE_PRIORITIES ) :
2012-06-04 14:12:54 +00:00
update_vals [ ' priority ' ] = msg . get ( ' priority ' )
2011-02-15 09:42:10 +00:00
maps = {
' cost ' : ' planned_cost ' ,
' revenue ' : ' planned_revenue ' ,
' probability ' : ' probability '
}
2012-08-17 12:06:06 +00:00
for line in msg [ ' body ' ] . split ( ' \n ' ) :
2011-02-15 09:42:10 +00:00
line = line . strip ( )
res = tools . misc . command_re . match ( line )
if res and maps . get ( res . group ( 1 ) . lower ( ) ) :
key = maps . get ( res . group ( 1 ) . lower ( ) )
2012-06-04 14:12:54 +00:00
update_vals [ key ] = res . group ( 2 ) . lower ( )
2011-02-15 09:42:10 +00:00
2012-06-04 14:12:54 +00:00
return super ( crm_helpdesk , self ) . message_update ( cr , uid , ids , msg , update_vals = update_vals , context = context )
2011-02-15 09:42:10 +00:00
2012-10-02 10:29:15 +00:00
# ---------------------------------------------------
2012-05-30 08:47:14 +00:00
# OpenChatter
2012-10-02 10:29:15 +00:00
# ---------------------------------------------------
2012-06-01 12:20:26 +00:00
2012-05-30 10:11:31 +00:00
def case_get_note_msg_prefix ( self , cr , uid , id , context = None ) :
2012-06-01 12:20:26 +00:00
""" override of default base_state method. """
return ' Case '
2009-12-31 12:57:20 +00:00
2012-06-01 12:20:26 +00:00
def create_send_note ( self , cr , uid , ids , context = None ) :
2012-06-01 14:40:59 +00:00
msg = _ ( ' Case has been <b>created</b>. ' )
2012-08-17 10:03:02 +00:00
self . message_post ( cr , uid , ids , body = msg , context = context )
2012-06-01 12:20:26 +00:00
return True
2009-12-31 12:57:20 +00:00
2012-06-01 12:20:26 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: