[IMP] Rounding should be done on move immediately to default UoM and quants should...
[odoo/odoo.git] / addons / auth_oauth / res_config.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2012-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 General Public License as published by
9 #    the Free Software Foundation, either version 3 of the License, or
10 #    (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 General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>
19 #
20 ##############################################################################
21
22 from openerp.osv import osv, fields
23
24 import logging
25 _logger = logging.getLogger(__name__)
26
27 class base_config_settings(osv.TransientModel):
28     _inherit = 'base.config.settings'
29
30     _columns = {
31         'auth_oauth_google_enabled' : fields.boolean('Allow users to sign in with Google'),
32         'auth_oauth_google_client_id' : fields.char('Client ID'),
33         'auth_oauth_facebook_enabled' : fields.boolean('Allow users to sign in with Facebook'),
34         'auth_oauth_facebook_client_id' : fields.char('Client ID'),
35     }
36
37     def default_get(self, cr, uid, fields, context=None):
38         res = super(base_config_settings, self).default_get(cr, uid, fields, context=context)
39         res.update(self.get_oauth_providers(cr, uid, fields, context=context))
40         return res
41
42     def get_oauth_providers(self, cr, uid, fields, context=None):
43         google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
44         facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
45         rg = self.pool.get('auth.oauth.provider').read(cr, uid, [google_id], ['enabled','client_id'], context=context)
46         rf = self.pool.get('auth.oauth.provider').read(cr, uid, [facebook_id], ['enabled','client_id'], context=context)
47         return {
48             'auth_oauth_google_enabled': rg[0]['enabled'],
49             'auth_oauth_google_client_id': rg[0]['client_id'],
50             'auth_oauth_facebook_enabled': rf[0]['enabled'],
51             'auth_oauth_facebook_client_id': rf[0]['client_id'],
52         }
53
54     def set_oauth_providers(self, cr, uid, ids, context=None):
55         google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
56         facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
57         config = self.browse(cr, uid, ids[0], context=context)
58         rg = {
59             'enabled':config.auth_oauth_google_enabled,
60             'client_id':config.auth_oauth_google_client_id,
61         }
62         rf = {
63             'enabled':config.auth_oauth_facebook_enabled,
64             'client_id':config.auth_oauth_facebook_client_id,
65         }
66         self.pool.get('auth.oauth.provider').write(cr, uid, [google_id], rg)
67         self.pool.get('auth.oauth.provider').write(cr, uid, [facebook_id], rf)
68