[IMP] res.users: message_load_ids overriden, to fetch ids of messages: 1/ res_model...
[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         'message_email_pref': fields.selection([
35                         ('all', 'Everytime'),
36                         ('comments', 'Only for comments'),
37                         ('me', 'Only when sent directly to me'),
38                         ('none', 'Never'),
39                         ], 'New feeds email', help="Choose whether you want to receive an email when you receive new feeds."),
40     }
41     
42     _default = {
43         'message_email_pref': 'all',
44     }
45     
46     def create(self, cr, uid, data, context=None):
47         user_id = super(res_users, self).create(cr, uid, data, context=context)
48         # make user follow itself
49         self.message_subscribe(cr, uid, [user_id], [user_id], context=context)
50         return user_id
51
52     def message_load_ids(self, cr, uid, ids, limit=100, offset=0, domain=[], ascent=False, root_ids=[False], context=None):
53         if context is None:
54             context = {}
55         user_data = self.read(cr, uid, ids, ['id', 'login'], context=context)
56         msg_obj = self.pool.get('mail.message')
57         msg_ids = []
58         for x_id in range(0, len(ids)):
59             msg_ids += msg_obj.search(cr, uid, ['|', ('body_text', 'like', '@%s' % (user_data[x_id]['login'])), '&', ('res_id', '=', ids[x_id]), ('model', '=', self._name)] + domain,
60             limit=limit, offset=offset, context=context)
61         if (ascent): msg_ids = self._message_get_parent_ids(cr, uid, ids, msg_ids, root_ids, context=context)
62         return msg_ids