[FIX] stock: picking invoice: do not invoice scrapped products (simply code)
[odoo/odoo.git] / addons / project_messages / project_messages.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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 osv import fields, osv
23 import netsvc
24
25 class messages(osv.osv):
26     """
27     Message from one user to another within a project
28     """
29     _name = 'project.messages'
30     logger = netsvc.Logger()
31
32     _columns = {
33         'create_date': fields.datetime('Creation Date', readonly=True),
34         'from_id': fields.many2one('res.users', 'From', required=True, ondelete="CASCADE"),
35         'to_id': fields.many2one('res.users', 'To', ondelete="CASCADE", help="Keep this empty to broadcast the message."),
36         'project_id': fields.many2one('project.project', 'Project',
37                                      required=True, ondelete="CASCADE"),
38         'message': fields.text('Message', required=True),
39     }
40     
41     def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
42         # return messages by current user, for current user or for all users
43         # return all messages if current user is administrator  
44         if uid != 1:
45             args.extend(['|',('from_id', 'in', [uid,]),('to_id', 'in', [uid, False])])
46         return super(messages, self).search(cr, uid, args, offset, limit,
47                 order, context=context, count=count)
48         
49     _defaults = {
50         'from_id': lambda self, cr, uid, context: uid,
51     }
52
53 messages()
54
55 class project_with_message(osv.osv):
56     _inherit = 'project.project'
57     
58     _columns = {
59         'message_ids':fields.one2many('project.messages', 'project_id', 'Messages'),
60     }
61 project_with_message()
62
63 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: