[FIX]google_docs: generic function moved in base account
bzr revid: dle@openerp.com-20130625105819-l8d2zu0vf4tzne2t
This commit is contained in:
parent
b4a9b23f8e
commit
0bca00c42c
|
@ -30,7 +30,7 @@ The module adds google user in res user.
|
|||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base'],
|
||||
'depends': ['base_setup'],
|
||||
'data': [
|
||||
'google_base_account_view.xml',
|
||||
'wizard/google_login_view.xml',
|
||||
|
|
|
@ -19,8 +19,14 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields,osv
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
from httplib2 import Http
|
||||
import urllib
|
||||
import simplejson
|
||||
|
||||
|
||||
class res_users(osv.osv):
|
||||
_inherit = "res.users"
|
||||
_columns = {
|
||||
|
@ -28,5 +34,35 @@ class res_users(osv.osv):
|
|||
'gmail_password': fields.char('Password', size=64),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
class base_config_settings(osv.osv):
|
||||
_inherit = "base.config.settings"
|
||||
|
||||
def onchange_google_authorization_code(self, cr, uid, ids, service, authorization_code, context=None):
|
||||
res = {}
|
||||
if authorization_code:
|
||||
ir_config = self.pool['ir.config_parameter']
|
||||
client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service)
|
||||
client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_secret' % service)
|
||||
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=client_id, client_secret=client_secret, redirect_uri=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 = simplejson.loads(content)
|
||||
if 'refresh_token' in content.keys():
|
||||
ir_config.set_param(cr, uid, 'google_%s_refresh_token' % service, content['refresh_token'])
|
||||
return res
|
||||
|
||||
# def get_default_google_authorization_code(self, cr, uid, ids, service, context=None):
|
||||
# authorization_code = self.pool.get("ir.config_parameter").get_param(cr, uid, "google_%s_authorization_code" % service, context=context)
|
||||
# return {'authorization_code': authorization_code}
|
||||
|
||||
# def set_google_authorization_code(self, cr, uid, ids, service, context=None):
|
||||
# config_parameters = self.pool.get("ir.config_parameter")
|
||||
# for record in self.read(cr, uid, ids, ['google_%s_authorization_code' % service], context=context):
|
||||
# config_parameters.set_param(cr, uid, "google_%s_authorization_code" % service, record['google_%s_authorization_code' % service] or '', context=context)
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -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.
|
||||
============================================
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
'google_docs_authorization_code': fields.char('Paste Generated "Authorization Code" from google to here', size=124),
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue