[IMP] Rounding should be done on move immediately to default UoM and quants should...
[odoo/odoo.git] / addons / share / ir_model.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010-2012 OpenERP S.A. (<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 from openerp.osv import osv
22
23 class ir_model_access(osv.Model):
24     _inherit = 'ir.model.access'
25
26     # overload group_names_with_access() to avoid returning sharing groups
27     # by filtering out groups with share=true.
28     def group_names_with_access(self, cr, model_name, access_mode):
29         """Returns the names of visible groups which have been granted ``access_mode`` on
30            the model ``model_name``.
31            :rtype: list
32         """
33         assert access_mode in ['read','write','create','unlink'], 'Invalid access mode: %s' % access_mode
34         cr.execute('''SELECT
35                         c.name, g.name
36                       FROM
37                         ir_model_access a
38                         JOIN ir_model m ON (a.model_id=m.id)
39                         JOIN res_groups g ON (a.group_id=g.id)
40                         LEFT JOIN ir_module_category c ON (c.id=g.category_id)
41                       WHERE
42                         m.model=%s AND
43                         a.active IS true AND
44                         (g.share IS NULL or g.share IS false) AND
45                         a.perm_''' + access_mode, (model_name,))
46         return [('%s/%s' % x) if x[0] else x[1] for x in cr.fetchall()]
47     
48
49 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: