summaryrefslogtreecommitdiff
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
parent009578d5eefc99f15ca571f856b36be67bb09167 (diff)
[MOV] google_drive : move code to split file per model
-rw-r--r--addons/google_drive/__openerp__.py1
-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
-rw-r--r--addons/google_drive/views/google_drive_views.xml18
-rw-r--r--addons/google_drive/views/res_config_views.xml22
6 files changed, 67 insertions, 56 deletions
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 @@
</field>
</record>
- <record id="inherited_google_view_general_configuration" model="ir.ui.view">
- <field name="name">General Settings</field>
- <field name="model">base.config.settings</field>
- <field name="inherit_id" ref="base_setup.view_general_configuration" />
- <field name="arch" type="xml">
- <xpath expr="//div[@name='module_google_drive']" position="after">
- <div attrs="{'invisible': [('module_google_drive','=',False)]}">
- <div class="oe_inline">
- <field name="google_drive_uri" widget="url" text="Generate Google Authorization Code" class="oe_inline oe_bold"/>
- and paste it here
- <field name="google_drive_authorization_code" class="oe_inline" />
- </div>
- <button type="action" name="%(google_drive.action_google_drive_users_config)d" string="Configure your templates" class="oe_link" />
- </div>
- </xpath>
- </field>
- </record>
-
<menuitem name='Google Drive' id='menu_google_drive_config' parent='base.menu_administration' />
<menuitem id='menu_google_drive_model_config' parent='menu_google_drive_config' action='action_google_drive_users_config' />
</data>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+
+ <record id="inherited_google_view_general_configuration" model="ir.ui.view">
+ <field name="name">General Settings</field>
+ <field name="model">base.config.settings</field>
+ <field name="inherit_id" ref="base_setup.view_general_configuration" />
+ <field name="arch" type="xml">
+ <xpath expr="//div[@name='module_google_drive']" position="after">
+ <div attrs="{'invisible': [('module_google_drive','=',False)]}">
+ <div class="oe_inline">
+ <field name="google_drive_uri" widget="url" text="Generate Google Authorization Code" class="oe_inline oe_bold"/>
+ and paste it here
+ <field name="google_drive_authorization_code" class="oe_inline" />
+ </div>
+ <button type="action" name="%(google_drive.action_google_drive_users_config)d" string="Configure your templates" class="oe_link" />
+ </div>
+ </xpath>
+ </field>
+ </record>
+
+</odoo>