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 crm import crm_base
23 from osv import fields, osv
24 from tools.translate import _
27 from datetime import datetime
29 class crm_phonecall(crm_base, osv.osv):
30 """ Phonecall Cases """
32 _name = "crm.phonecall"
33 _description = "Phonecall"
37 'id': fields.integer('ID'),
38 'name': fields.char('Call Summary', size=64),
39 'active': fields.boolean('Active', required=False),
40 'date_action_last': fields.datetime('Last Action', readonly=1),
41 'date_action_next': fields.datetime('Next Action', readonly=1),
42 'create_date': fields.datetime('Creation Date' , readonly=True),
43 'section_id': fields.many2one('crm.case.section', 'Sales Team', \
44 select=True, help='Sales team to which Case belongs to.'),
45 'user_id': fields.many2one('res.users', 'Responsible'),
46 'partner_id': fields.many2one('res.partner', 'Partner'),
47 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
48 domain="[('partner_id','=',partner_id)]"),
49 'company_id': fields.many2one('res.company', 'Company'),
50 'description': fields.text('Description'),
51 'state': fields.selection([
54 ('cancel', 'Cancelled'),
56 ('pending', 'Not Held'),
57 ], 'State', size=16, readonly=True,
58 help='The state is set to \'Todo\', when a case is created.\
59 \nIf the case is in progress the state is set to \'Open\'.\
60 \nWhen the case is over, the state is set to \'Done\'.\
61 \nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
62 'email_from': fields.char('Email', size=128, help="These people will receive email."),
63 'date_open': fields.datetime('Opened', readonly=True),
65 'duration': fields.float('Duration', help="Duration in Minutes"),
66 'categ_id': fields.many2one('crm.case.categ', 'Category', \
67 domain="['|',('section_id','=',section_id),('section_id','=',False),\
68 ('object_id.model', '=', 'crm.phonecall')]"),
69 'partner_phone': fields.char('Phone', size=32),
70 'partner_contact': fields.related('partner_address_id', 'name', \
71 type="char", string="Contact", size=128),
72 'partner_mobile': fields.char('Mobile', size=32),
73 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
74 'canal_id': fields.many2one('res.partner.canal', 'Channel', \
75 help="The channels represent the different communication\
76 modes available with the customer." \
77 " With each commercial opportunity, you can indicate\
78 the canall which is this opportunity source."),
79 'date_closed': fields.datetime('Closed', readonly=True),
80 'date': fields.datetime('Date'),
81 'opportunity_id': fields.many2one ('crm.lead', 'Lead/Opportunity'),
82 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
85 def _get_default_state(self, cr, uid, context=None):
86 if context and context.get('default_state', False):
87 return context.get('default_state')
91 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
92 'priority': crm.AVAILABLE_PRIORITIES[2][0],
93 'state': _get_default_state,
94 'user_id': lambda self,cr,uid,ctx: uid,
102 def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
103 res = super(crm_phonecall, self).onchange_partner_address_id(cr, uid, ids, add, email)
104 res.setdefault('value', {})
106 address = self.pool.get('res.partner.address').browse(cr, uid, add)
107 res['value']['partner_phone'] = address.phone
108 res['value']['partner_mobile'] = address.mobile
111 def case_close(self, cr, uid, ids, *args):
112 """Overrides close for crm_case for setting close date
113 @param self: The object pointer
114 @param cr: the current row, from the database cursor,
115 @param uid: the current user’s ID for security checks,
116 @param ids: List of case Ids
117 @param *args: Tuple Value for additional Params
120 for phone in self.browse(cr, uid, ids):
122 data = {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')}
123 if phone.duration <=0:
124 duration = datetime.now() - datetime.strptime(phone.date, '%Y-%m-%d %H:%M:%S')
125 data.update({'duration': duration.seconds/float(60)})
126 res = super(crm_phonecall, self).case_close(cr, uid, [phone_id], args)
127 self.write(cr, uid, [phone_id], data)
130 def case_reset(self, cr, uid, ids, *args):
131 """Resets case as Todo
132 @param self: The object pointer
133 @param cr: the current row, from the database cursor,
134 @param uid: the current user’s ID for security checks,
135 @param ids: List of case Ids
136 @param *args: Tuple Value for additional Params
138 res = super(crm_phonecall, self).case_reset(cr, uid, ids, args, 'crm.phonecall')
139 self.write(cr, uid, ids, {'duration': 0.0})
143 def case_open(self, cr, uid, ids, *args):
144 """Overrides cancel for crm_case for setting Open Date
145 @param self: The object pointer
146 @param cr: the current row, from the database cursor,
147 @param uid: the current user’s ID for security checks,
148 @param ids: List of case's Ids
149 @param *args: Give Tuple Value
151 res = super(crm_phonecall, self).case_open(cr, uid, ids, *args)
152 self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
155 def action_make_meeting(self, cr, uid, ids, context=None):
157 This opens Meeting's calendar view to schedule meeting on current Phonecall
158 @param self: The object pointer
159 @param cr: the current row, from the database cursor,
160 @param uid: the current user’s ID for security checks,
161 @param ids: List of Phonecall to Meeting IDs
162 @param context: A standard dictionary for contextual values
164 @return : Dictionary value for created Meeting view
167 for phonecall in self.browse(cr, uid, ids, context=context):
168 data_obj = self.pool.get('ir.model.data')
171 result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
172 res = data_obj.read(cr, uid, result, ['res_id'])
173 id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
174 id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
175 id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
177 id1 = data_obj.browse(cr, uid, id1, context=context).res_id
179 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
181 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
184 'default_phonecall_id': phonecall.id,
185 'default_partner_id': phonecall.partner_id and phonecall.partner_id.id or False,
186 'default_email': phonecall.email_from ,
187 'default_name': phonecall.name
191 'name': _('Meetings'),
192 'domain' : "[('user_id','=',%s)]" % (uid),
195 'view_mode': 'calendar,form,tree',
196 'res_model': 'crm.meeting',
198 'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')],
199 'type': 'ir.actions.act_window',
200 'search_view_id': res['res_id'],
209 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: