[MERGE] [IMP] mail: Inbox usability improvements :
[odoo/odoo.git] / addons / mail / res_partner.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
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 Affero General Public License for more details.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from openerp.tools.translate import _
23 from openerp.osv import fields, osv
24
25
26 class res_partner_mail(osv.Model):
27     """ Update partner to add a field about notification preferences """
28     _name = "res.partner"
29     _inherit = ['res.partner', 'mail.thread']
30     _mail_flat_thread = False
31     _mail_mass_mailing = _('Customers')
32
33     _columns = {
34         'notify_email': fields.selection([
35             ('none', 'Never'),
36             ('always', 'All Messages'),
37             ], 'Receive Inbox Notifications by Email', required=True,
38             oldname='notification_email_send',
39             help="Policy to receive emails for new messages pushed to your personal Inbox:\n"
40                     "- Never: no emails are sent\n"
41                     "- All Messages: for every notification you receive in your Inbox"),
42     }
43
44     _defaults = {
45         'notify_email': lambda *args: 'always'
46     }
47
48     def message_get_suggested_recipients(self, cr, uid, ids, context=None):
49         recipients = super(res_partner_mail, self).message_get_suggested_recipients(cr, uid, ids, context=context)
50         for partner in self.browse(cr, uid, ids, context=context):
51             self._message_add_suggested_recipient(cr, uid, recipients, partner, partner=partner, reason=_('Partner Profile'))
52         return recipients
53
54     def message_get_default_recipients(self, cr, uid, ids, context=None):
55         return dict((id, {'partner_ids': [id], 'email_to': False, 'email_cc': False}) for id in ids)