From b581e2004f0921f95c6ac10a64b76abf7a80f2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Wed, 4 May 2016 11:47:32 +0200 Subject: [PATCH] [MOV] google_drive : move code to split file per model --- addons/google_drive/__openerp__.py | 1 + addons/google_drive/models/__init__.py | 1 + addons/google_drive/models/google_drive.py | 38 ---------------- addons/google_drive/models/res_config.py | 43 +++++++++++++++++++ .../google_drive/views/google_drive_views.xml | 18 -------- .../google_drive/views/res_config_views.xml | 22 ++++++++++ 6 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 addons/google_drive/models/res_config.py create mode 100644 addons/google_drive/views/res_config_views.xml diff --git a/addons/google_drive/__openerp__.py b/addons/google_drive/__openerp__.py index b63812cb3ea..e91cb487d76 100644 --- a/addons/google_drive/__openerp__.py +++ b/addons/google_drive/__openerp__.py @@ -10,6 +10,7 @@ 'data': [ 'security/ir.model.access.csv', 'data/google_drive_data.xml', + 'views/res_config_views.xml', 'views/google_drive_views.xml', 'views/google_drive_templates.xml', ], diff --git a/addons/google_drive/models/__init__.py b/addons/google_drive/models/__init__.py index 02eb472052a..bfd04903c5d 100644 --- a/addons/google_drive/models/__init__.py +++ b/addons/google_drive/models/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import google_drive +import res_config diff --git a/addons/google_drive/models/google_drive.py b/addons/google_drive/models/google_drive.py index 3cd7da3612d..97d13ec1a5c 100644 --- a/addons/google_drive/models/google_drive.py +++ b/addons/google_drive/models/google_drive.py @@ -218,41 +218,3 @@ class config(osv.Model): def get_google_scope(self): return 'https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file' - - -class base_config_settings(osv.TransientModel): - _inherit = "base.config.settings" - - def _get_drive_uri(self, cr, uid, ids, field_name, arg, context=None): - return { - wizard_id: self.default_get(cr, uid, ['google_drive_uri']).get('google_drive_uri') - for wizard_id in ids - } - - def _get_wizard_ids(self, cr, uid, ids, context=None): - result = [] - if any(rec.key in ['google_drive_client_id', 'google_redirect_uri'] for rec in self.browse(cr, uid, ids, context=context)): - result.extend(self.pool['base.config.settings'].search(cr, uid, [], context=context)) - return result - - _columns = { - 'google_drive_authorization_code': fields.char('Authorization Code'), - 'google_drive_uri': fields.function(_get_drive_uri, string='URI', help="The URL to generate the authorization code from Google", type="char", store={ - 'ir.config_parameter': (_get_wizard_ids, None, 20), - }), # TODO: 1. in master, remove the store, there is no reason for this field to be stored. It's just a dynamic link. - # TODO: 2. when converted to the new API, the code to get the default value can be moved to the compute method directly, and the default value can be removed - # the only reason the default value is defined is because function fields are not computed in draft mode in the old API. - } - _defaults = { - 'google_drive_uri': lambda s, cr, uid, c: s.pool['google.service']._get_google_token_uri(cr, uid, 'drive', scope=s.pool['google.drive.config'].get_google_scope(), context=c), - 'google_drive_authorization_code': lambda s, cr, uid, c: s.pool['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'google_drive_authorization_code', context=c), - } - - def set_google_authorization_code(self, cr, uid, ids, context=None): - ir_config_param = self.pool['ir.config_parameter'] - config = self.browse(cr, uid, ids[0], context) - auth_code = config.google_drive_authorization_code - if auth_code and auth_code != ir_config_param.get_param(cr, uid, 'google_drive_authorization_code', context=context): - refresh_token = self.pool['google.service'].generate_refresh_token(cr, uid, 'drive', config.google_drive_authorization_code, context=context) - ir_config_param.set_param(cr, uid, 'google_drive_authorization_code', auth_code, groups=['base.group_system']) - ir_config_param.set_param(cr, uid, 'google_drive_refresh_token', refresh_token, groups=['base.group_system']) diff --git a/addons/google_drive/models/res_config.py b/addons/google_drive/models/res_config.py new file mode 100644 index 00000000000..d0112824b48 --- /dev/null +++ b/addons/google_drive/models/res_config.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp import SUPERUSER_ID +from openerp.osv import fields, osv + + +class base_config_settings(osv.TransientModel): + _inherit = "base.config.settings" + + def _get_drive_uri(self, cr, uid, ids, field_name, arg, context=None): + return { + wizard_id: self.default_get(cr, uid, ['google_drive_uri']).get('google_drive_uri') + for wizard_id in ids + } + + def _get_wizard_ids(self, cr, uid, ids, context=None): + result = [] + if any(rec.key in ['google_drive_client_id', 'google_redirect_uri'] for rec in self.browse(cr, uid, ids, context=context)): + result.extend(self.pool['base.config.settings'].search(cr, uid, [], context=context)) + return result + + _columns = { + 'google_drive_authorization_code': fields.char('Authorization Code'), + 'google_drive_uri': fields.function(_get_drive_uri, string='URI', help="The URL to generate the authorization code from Google", type="char", store={ + 'ir.config_parameter': (_get_wizard_ids, None, 20), + }), # TODO: 1. in master, remove the store, there is no reason for this field to be stored. It's just a dynamic link. + # TODO: 2. when converted to the new API, the code to get the default value can be moved to the compute method directly, and the default value can be removed + # the only reason the default value is defined is because function fields are not computed in draft mode in the old API. + } + _defaults = { + 'google_drive_uri': lambda s, cr, uid, c: s.pool['google.service']._get_google_token_uri(cr, uid, 'drive', scope=s.pool['google.drive.config'].get_google_scope(), context=c), + 'google_drive_authorization_code': lambda s, cr, uid, c: s.pool['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'google_drive_authorization_code', context=c), + } + + def set_google_authorization_code(self, cr, uid, ids, context=None): + ir_config_param = self.pool['ir.config_parameter'] + config = self.browse(cr, uid, ids[0], context) + auth_code = config.google_drive_authorization_code + if auth_code and auth_code != ir_config_param.get_param(cr, uid, 'google_drive_authorization_code', context=context): + refresh_token = self.pool['google.service'].generate_refresh_token(cr, uid, 'drive', config.google_drive_authorization_code, context=context) + ir_config_param.set_param(cr, uid, 'google_drive_authorization_code', auth_code, groups=['base.group_system']) + ir_config_param.set_param(cr, uid, 'google_drive_refresh_token', refresh_token, groups=['base.group_system']) diff --git a/addons/google_drive/views/google_drive_views.xml b/addons/google_drive/views/google_drive_views.xml index 411f5a27c39..894004ab0f5 100644 --- a/addons/google_drive/views/google_drive_views.xml +++ b/addons/google_drive/views/google_drive_views.xml @@ -68,24 +68,6 @@ - - General Settings - base.config.settings - - - -
-
- - and paste it here - -
-
-
-
-
- diff --git a/addons/google_drive/views/res_config_views.xml b/addons/google_drive/views/res_config_views.xml new file mode 100644 index 00000000000..0b9d5d6b450 --- /dev/null +++ b/addons/google_drive/views/res_config_views.xml @@ -0,0 +1,22 @@ + + + + + General Settings + base.config.settings + + + +
+
+ + and paste it here + +
+
+
+
+
+ +