diff options
| author | Denis Ledoux <dle@openerp.com> | 2013-06-25 12:58:19 +0200 |
|---|---|---|
| committer | Denis Ledoux <dle@openerp.com> | 2013-06-25 12:58:19 +0200 |
| commit | 0bca00c42c87c093e7ff54d7542c0f7fd083253c (patch) | |
| tree | 399a23674ec3c55d8450ffb5522b12c9ee96f0e9 /addons/google_docs | |
| parent | b4a9b23f8e9e76d20bc3ef2d550b3a652dc12663 (diff) | |
[FIX]google_docs: generic function moved in base account
bzr revid: dle@openerp.com-20130625105819-l8d2zu0vf4tzne2t
Diffstat (limited to 'addons/google_docs')
| -rw-r--r-- | addons/google_docs/__openerp__.py | 2 | ||||
| -rw-r--r-- | addons/google_docs/google_docs.py | 48 | ||||
| -rw-r--r-- | addons/google_docs/google_docs_data.xml | 21 | ||||
| -rw-r--r-- | addons/google_docs/res_config_user_view.xml | 2 | ||||
| -rw-r--r-- | addons/google_docs/static/src/js/gdocs.js | 2 |
5 files changed, 22 insertions, 53 deletions
diff --git a/addons/google_docs/__openerp__.py b/addons/google_docs/__openerp__.py index 2536edb823b..8e4b2fa612e 100644 --- a/addons/google_docs/__openerp__.py +++ b/addons/google_docs/__openerp__.py @@ -39,7 +39,7 @@ 'demo': [ 'google_docs_demo.xml' ], - 'depends': ['base_setup'], + 'depends': ['base_setup', 'google_base_account'], 'description': """ Integrate google document to OpenERP record. ============================================ diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 63a3a423a34..d6cfb3dfe4a 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -68,16 +68,16 @@ class config(osv.osv): def copy_doc(self, cr, uid, ids, res_id, tamplate_id, name_gdocs, res_model, context=None): ir_config = self.pool[ 'ir.config_parameter' ] - google_client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_client_id') - google_client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_client_secret') - google_refresh_token = ir_config.get_param(cr, SUPERUSER_ID, 'google_refresh_token') + google_docs_client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_docs_client_id') + google_docs_client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_docs_client_secret') + google_docs_refresh_token = ir_config.get_param(cr, SUPERUSER_ID, 'google_docs_refresh_token') google_web_base_url = ir_config.get_param(cr, SUPERUSER_ID, 'web.base.url') #For Getting New Access Token With help of old Refresh Token headers = {"Content-type": "application/x-www-form-urlencoded"} - data = dict(client_id = google_client_id, - refresh_token = google_refresh_token, - client_secret = google_client_secret, + data = dict(client_id = google_docs_client_id, + refresh_token = google_docs_refresh_token, + client_secret = google_docs_client_secret, grant_type = "refresh_token") data = urllib.urlencode(data) resp, content = Http().request("https://accounts.google.com/o/oauth2/token", "POST", data, headers) @@ -172,7 +172,7 @@ class config(osv.osv): result = {} for config_id in ids: config = self.pool['ir.config_parameter'] - result[config_id] = config.get_param(cr, SUPERUSER_ID, 'google_client_id') + result[config_id] = config.get_param(cr, SUPERUSER_ID, 'google_docs_client_id') return result _columns = { @@ -181,7 +181,7 @@ class config(osv.osv): 'filter_id' : fields.many2one('ir.filters', 'Filter'), 'gdocs_template_url': fields.char('Template URL', required=True, size=1024), 'gdocs_resource_id' : fields.function(_resource_get, type="char" , string='Resource Id'), - 'google_client_id' : fields.function(_client_id_get, type="char" , string='Google Client '), + 'google_docs_client_id' : fields.function(_client_id_get, type="char" , string='Google Client '), 'name_template': fields.char('Google Drive Name Pattern', size=64, help='Choose how the new google drive will be named, on google side. Eg. gdoc_%(field_name)s', required=True), } @@ -209,36 +209,10 @@ class config(osv.osv): config() + class base_config_settings(osv.osv): _inherit = "base.config.settings" - - def onchange_authorization_code(self, cr, uid, ids, authorization_code, context=None): - res = {} - if authorization_code: - ir_config = self.pool['ir.config_parameter'] - google_client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_client_id') - google_client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_client_secret') - google_redirect_uri = ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri') - - #Get the Refresh Token From Google And store it in ir.config_parameter - headers = {"Content-type": "application/x-www-form-urlencoded"} - data = dict(code=authorization_code, client_id=google_client_id, client_secret=google_client_secret,redirect_uri=google_redirect_uri,grant_type="authorization_code") - data = urllib.urlencode(data) - resp, content = Http().request("https://accounts.google.com/o/oauth2/token", "POST", data,headers) - content=json.loads(content) - if 'refresh_token' in content.keys(): - ir_config.set_param(cr, uid, 'google_refresh_token', content['refresh_token']) - return res - - def get_default_authorization_code(self, cr, uid, ids, context=None): - authorization_code = self.pool.get("ir.config_parameter").get_param(cr, uid, "authorization_code", context=context) - return {'authorization_code': authorization_code} - def set_authorization_code(self, cr, uid, ids, context=None): - config_parameters = self.pool.get("ir.config_parameter") - for record in self.browse(cr, uid, ids, context=context): - config_parameters.set_param(cr, uid, "authorization_code", record.authorization_code or '', context=context) - _columns = { - 'authorization_code': fields.char('Paste Generated "Authorization Code" from google to here', size=124), - }
\ No newline at end of file + 'google_docs_authorization_code': fields.char('Paste Generated "Authorization Code" from google to here', size=124), + } diff --git a/addons/google_docs/google_docs_data.xml b/addons/google_docs/google_docs_data.xml index 5ec29c12a7c..f674f0a8a31 100644 --- a/addons/google_docs/google_docs_data.xml +++ b/addons/google_docs/google_docs_data.xml @@ -2,28 +2,23 @@ <openerp> <data noupdate="1"> - <record id="config_google_client_id" model="ir.config_parameter"> - <field name="key">google_client_id</field> + <record id="config_google_docs_client_id" model="ir.config_parameter"> + <field name="key">google_docs_client_id</field> <field name="value">39623646228-eg3ggo3mk6o40m7rguobi3rkl9frh4tb.apps.googleusercontent.com</field> </record> - <record id="config_google_client_secret" model="ir.config_parameter"> - <field name="key">google_client_secret</field> + <record id="config_google_docs_client_secret" model="ir.config_parameter"> + <field name="key">google_docs_client_secret</field> <field name="value">Ul-PtmnSWs3euWs20fdono0e</field> </record> - <record id="config_google_redirect_uri" model="ir.config_parameter"> - <field name="key">google_redirect_uri</field> - <field name="value">urn:ietf:wg:oauth:2.0:oob</field> - </record> - - <record id="config_refresh_token" model="ir.config_parameter"> - <field name="key">google_refresh_token</field> + <record id="config_google_docs_refresh_token" model="ir.config_parameter"> + <field name="key">google_docs_refresh_token</field> <field name="value">-</field> </record> - <record id="config_authorization_code" model="ir.config_parameter"> - <field name="key">authorization_code</field> + <record id="config_google_docs_authorization_code" model="ir.config_parameter"> + <field name="key">google_docs_authorization_code</field> <field name="value">-</field> </record> </data> diff --git a/addons/google_docs/res_config_user_view.xml b/addons/google_docs/res_config_user_view.xml index 06a729125ab..50560be4a11 100644 --- a/addons/google_docs/res_config_user_view.xml +++ b/addons/google_docs/res_config_user_view.xml @@ -79,7 +79,7 @@ <!-- Need to generate client id, redirect url from Google Account (API console) and replace below link. Limitation on Number of request: 10 lacks per day. --> Click here to <a href="https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=39623646228-eg3ggo3mk6o40m7rguobi3rkl9frh4tb.apps.googleusercontent.com" target="_blank"><b>Generate Google Authorization Code</b></a><br/> <group> - <field name="authorization_code" on_change="onchange_authorization_code(authorization_code)"/> + <field name="google_docs_authorization_code" on_change="onchange_google_authorization_code('docs', google_docs_authorization_code)"/>'' </group> Configure your templates and link your google document to OpenERP records <button type="action" name="%(google_docs.action_google_docs_users_config)d" string="Configure Template" class="oe_link" /> </p> diff --git a/addons/google_docs/static/src/js/gdocs.js b/addons/google_docs/static/src/js/gdocs.js index 9d15cb37a2b..24385b3b85e 100644 --- a/addons/google_docs/static/src/js/gdocs.js +++ b/addons/google_docs/static/src/js/gdocs.js @@ -56,7 +56,7 @@ openerp.google_docs = function (instance, m) { on_google_doc: function (doc_item) { var self = this; self.config = doc_item; - var loaded = self.fetch('google.docs.config', ['gdocs_resource_id', 'google_client_id'], [['id', '=', doc_item.config_id]]) + var loaded = self.fetch('google.docs.config', ['gdocs_resource_id', 'google_docs_client_id'], [['id', '=', doc_item.config_id]]) .then(function (configs) { var ds = new instance.web.DataSet(self, 'google.docs.config'); ds.call('get_google_doc_name', [[doc_item.config_id], doc_item.res_id,configs[0].gdocs_resource_id]).done(function (r) { |
