[IMP] mail: composition form: removed default body_html;
[odoo/odoo.git] / addons / mail / res_users.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2009-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 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 osv import osv, fields
23 from tools.translate import _
24
25 class res_users(osv.osv):
26     """ Update of res.users class
27         - add a preference about sending emails about notificatoins
28         - make a new user follow itself
29     """
30     _name = 'res.users'
31     _inherit = ['res.users', 'mail.thread']
32     
33     _columns = {
34         'notification_email_pref': fields.selection([
35             ('all', 'All feeds'),
36             ('comments', 'Only comments'),
37             ('to_me', 'Only when sent directly to me'),
38             ('none', 'Never')
39             ], 'Receive Feeds by Email', required=True,
40             help="Choose in which case you want to receive an email when you "\
41                   "receive new feeds."),
42     }
43     
44     _defaults = {
45         'notification_email_pref': 'to_me',
46     }
47     
48     def __init__(self, pool, cr):
49         """ Override of __init__ to add access rights on notification_email_pref
50             field. Access rights are disabled by default, but allowed on
51             fields defined in self.SELF_WRITEABLE_FIELDS.
52         """
53         init_res = super(res_users, self).__init__(pool, cr)
54         # duplicate list to avoid modifying the original reference
55         self.SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
56         self.SELF_WRITEABLE_FIELDS.append('notification_email_pref')
57         return init_res
58     
59     def create(self, cr, uid, data, context=None):
60         user_id = super(res_users, self).create(cr, uid, data, context=context)
61         user = self.browse(cr, uid, [user_id], context=context)[0]
62         # make user follow itself
63         self.message_subscribe(cr, uid, [user_id], [user_id], context=context)
64         # create a welcome message to broadcast
65         company_name = user.company_id.name if user.company_id else 'the company'
66         message = _('%s has joined %s! You may leave him/her a message to celebrate a new arrival in the company ! You can help him/her doing its first steps on OpenERP.') % (user.name, company_name)
67         # TODO: clean the broadcast feature. As this is not cleany specified, temporarily remove the message broadcasting that is not buggy but not very nice.
68         #self.message_broadcast(cr, uid, [user.id], 'Welcome notification', message, context=context)
69         return user_id
70
71     def message_search_get_domain(self, cr, uid, ids, context=None):
72         """ Override of message_search_get_domain for partner discussion page.
73             The purpose is to add messages directly sent to user using
74             @user_login.
75         """
76         initial_domain = super(res_users, self).message_search_get_domain(cr, uid, ids, context=context)
77         custom_domain = []
78         for user in self.browse(cr, uid, ids, context=context):
79             if custom_domain:
80                 custom_domain += ['|']
81             custom_domain += ['|', ('body_text', 'like', '@%s' % (user.login)), ('body_html', 'like', '@%s' % (user.login))]
82         return ['|'] + initial_domain + custom_domain