fix
[odoo/odoo.git] / addons / crm / wizard / mail_compose_message.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation, either version 3 of the License, or
10 #    (at your option) any later version.
11 #
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 General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>
19 #
20 ##############################################################################
21
22 from osv import osv
23 from osv import fields
24 import tools
25
26 SUPPORTED_MODELS = ['crm.lead',]
27
28 class mail_compose_message(osv.osv_memory):
29     _inherit = 'mail.compose.message'
30
31     def get_value(self, cr, uid, model, res_id, context=None):
32         """Returns a defaults-like dict with initial values for the composition
33            wizard when sending an email related to the document record identified
34            by ``model`` and ``res_id``.
35
36            Overrides the default implementation to provide more default field values
37            related to the corresponding CRM case.
38
39            :param str model: model name of the document record this mail is related to.
40            :param int res_id: id of the document record this mail is related to.
41            :param dict context: several context values will modify the behavior
42                                 of the wizard, cfr. the class description.
43         """
44         result = super(mail_compose_message, self).get_value(cr, uid,  model, res_id, context=context)
45         if model in SUPPORTED_MODELS and res_id:
46             model_obj = self.pool.get(model)
47             data = model_obj.browse(cr, uid , res_id, context)
48             user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
49             result.update({
50                     'subject' : data.name or False,
51                     'email_to' : data.email_from or False,
52                     'email_from' : user.user_email or tools.config.get('email_from', False),
53                     'body_text' : '\n' + tools.ustr(user.signature),
54                     'email_cc' : tools.ustr(data.email_cc or ''),
55                     'model': model,
56                     'res_id': res_id,
57                     'subtype': 'plain',
58                 })
59             if hasattr(data, 'section_id'):
60                 result.update({'reply_to' : data.section_id and data.section_id.reply_to or False})
61         return result
62
63 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: