[FIX] Forgotten ',' and issue on calling _push_event
[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.osv import fields, osv
23
24 class res_partner_mail(osv.Model):
25     """ Update partner to add a field about notification preferences """
26     _name = "res.partner"
27     _inherit = ['res.partner', 'mail.thread']
28     _mail_flat_thread = False
29
30     _columns = {
31         'notification_email_send': fields.selection([
32             ('all', 'All feeds'),
33             ('comment', 'Comments and Emails'),
34             ('email', 'Emails only'),
35             ('none', 'Never')
36             ], 'Receive Feeds by Email', required=True,
37             help="Choose in which case you want to receive an email when you "\
38                   "receive new feeds."),
39     }
40
41     _defaults = {
42         'notification_email_send': lambda *args: 'comment'
43     }
44
45     def message_post(self, cr, uid, thread_id, **kwargs):
46         """ Override related to res.partner. In case of email message, set it as
47             private:
48             - add the target partner in the message partner_ids
49             - set thread_id as None, because this will trigger the 'private'
50                 aspect of the message (model=False, res_id=False)
51         """
52         if isinstance(thread_id, (list, tuple)):
53             thread_id = thread_id[0]
54         if kwargs.get('type') == 'email':
55             partner_ids = kwargs.get('partner_ids', [])
56             if thread_id not in [command[1] for command in partner_ids]:
57                 partner_ids.append((4, thread_id))
58             kwargs['partner_ids'] = partner_ids
59             thread_id = False
60         return super(res_partner_mail, self).message_post(cr, uid, thread_id, **kwargs)
61
62 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: