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_case
23 from osv import fields, osv
24 from tools.translate import _
28 class crm_phonecall(osv.osv, crm_case):
29 """ Phonecall Cases """
31 _name = "crm.phonecall"
32 _description = "Phonecall Cases"
34 _inherit = 'mailgate.thread'
38 'section_id': fields.many2one('crm.case.section', 'Sales Team', \
39 select=True, help='Sales team to which Case belongs to.\
40 Define Responsible user and Email account for mail gateway.'),
41 'user_id': fields.many2one('res.users', 'Responsible'),
42 'partner_id': fields.many2one('res.partner', 'Partner'),
43 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
44 domain="[('partner_id','=',partner_id)]"),
45 'company_id': fields.many2one('res.company', 'Company'),
46 'description': fields.text('Description'),
47 'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
48 help='The state is set to \'Draft\', when a case is created.\
49 \nIf the case is in progress the state is set to \'Open\'.\
50 \nWhen the case is over, the state is set to \'Done\'.\
51 \nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
52 'email_from': fields.char('Email', size=128, help="These people will receive email."),
53 'stage_id': fields.many2one('crm.case.stage', 'Stage', \
54 domain="[('section_id','=',section_id),\
55 ('object_id.model', '=', 'crm.phonecall')]"),
56 'date_open': fields.datetime('Opened', readonly=True),
58 'duration': fields.float('Duration'),
59 'categ_id': fields.many2one('crm.case.categ', 'Category', \
60 domain="[('section_id','=',section_id),\
61 ('object_id.model', '=', 'crm.phonecall')]"),
62 'partner_phone': fields.char('Phone', size=32),
63 'partner_contact': fields.related('partner_address_id', 'name', \
64 type="char", string="Contact", size=128),
65 'partner_mobile': fields.char('Mobile', size=32),
66 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
67 'canal_id': fields.many2one('res.partner.canal', 'Channel', \
68 help="The channels represent the different communication\
69 modes available with the customer." \
70 " With each commercial opportunity, you can indicate\
71 the canall which is this opportunity source."),
72 'date_closed': fields.datetime('Closed', readonly=True),
73 'date': fields.datetime('Date'),
74 'opportunity_id': fields.many2one ('crm.lead', 'Opportunity'),
78 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
79 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
80 'state': lambda *a: 'draft',
85 def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
86 res = super(crm_phonecall, self).onchange_partner_address_id(cr, uid, ids, add, email)
87 res.setdefault('value', {})
89 address = self.pool.get('res.partner.address').browse(cr, uid, add)
90 res['value']['partner_phone'] = address.phone
91 res['value']['partner_mobile'] = address.mobile
94 def case_close(self, cr, uid, ids, *args):
95 """Overrides close for crm_case for setting close date
96 @param self: The object pointer
97 @param cr: the current row, from the database cursor,
98 @param uid: the current user’s ID for security checks,
99 @param ids: List of case Ids
100 @param *args: Tuple Value for additional Params
102 res = super(crm_phonecall, self).case_close(cr, uid, ids, args)
103 self.write(cr, uid, ids, {'date_closed': time.strftime('%Y-%m-%d %H:%M:%S')})
106 def case_open(self, cr, uid, ids, *args):
107 """Overrides cancel for crm_case for setting Open Date
108 @param self: The object pointer
109 @param cr: the current row, from the database cursor,
110 @param uid: the current user’s ID for security checks,
111 @param ids: List of case's Ids
112 @param *args: Give Tuple Value
114 res = super(crm_phonecall, self).case_open(cr, uid, ids, *args)
115 self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
118 def action_make_meeting(self, cr, uid, ids, context=None):
120 This opens Meeting's calendar view to schedule meeting on current Phonecall
121 @param self: The object pointer
122 @param cr: the current row, from the database cursor,
123 @param uid: the current user’s ID for security checks,
124 @param ids: List of Phonecall to Meeting IDs
125 @param context: A standard dictionary for contextual values
127 @return : Dictionary value for created Meeting view
130 for phonecall in self.browse(cr, uid, ids):
131 data_obj = self.pool.get('ir.model.data')
134 result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
135 res = data_obj.read(cr, uid, result, ['res_id'])
136 id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
137 id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
138 id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
140 id1 = data_obj.browse(cr, uid, id1, context=context).res_id
142 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
144 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
147 'default_phonecall_id': phonecall.id,
148 'default_partner_id': phonecall.partner_id and phonecall.partner_id.id or False,
149 'default_email': phonecall.email_from ,
150 'default_name': phonecall.name
154 'name': _('Meetings'),
155 'domain' : "[('user_id','=',%s)]" % (uid),
158 'view_mode': 'calendar,form,tree',
159 'res_model': 'crm.meeting',
161 'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')],
162 'type': 'ir.actions.act_window',
163 'search_view_id': res['res_id'],
171 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: