summaryrefslogtreecommitdiff
path: root/addons/google_drive/models
diff options
context:
space:
mode:
authorJérome Maes <jem@openerp.com>2016-05-04 11:47:32 +0200
committerJérome Maes <jem@openerp.com>2016-05-31 09:09:22 +0200
commitb581e2004f0921f95c6ac10a64b76abf7a80f2e9 (patch)
tree21255925791f5fe0619377b64f54faaa96ccb612 /addons/google_drive/models
parent009578d5eefc99f15ca571f856b36be67bb09167 (diff)
[MOV] google_drive : move code to split file per model
Diffstat (limited to 'addons/google_drive/models')
-rw-r--r--addons/google_drive/models/__init__.py1
-rw-r--r--addons/google_drive/models/google_drive.py38
-rw-r--r--addons/google_drive/models/res_config.py43
3 files changed, 44 insertions, 38 deletions
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'])