diff --git a/addons/crm/crm_action_rule_demo.xml b/addons/crm/crm_action_rule_demo.xml index 7204f666db5..569b2d676e0 100644 --- a/addons/crm/crm_action_rule_demo.xml +++ b/addons/crm/crm_action_rule_demo.xml @@ -14,13 +14,7 @@ True ir.actions.server email - object.user_id.email - Reminder on Lead: [[object.id ]] [[object.partner_id and 'of ' +object.partner_id.name or '']] - Warning unprocessed incoming lead is more than 5 day old. -Name: [[object.name ]] -ID: [[object.id ]] -Description: [[object.description]] - + Set Auto Reminder on leads which are not open since 5 days. diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 46a3f6e199e..c0f003f9792 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -945,42 +945,6 @@ class crm_lead(format_address, osv.osv): vals.update(onchange_stage_values) return super(crm_lead, self).write(cr, uid, ids, vals, context=context) - def new_mail_send(self, cr, uid, ids, context=None): - ''' - This function opens a window to compose an email, with the edi sale template message loaded by default - ''' - assert len(ids) == 1, 'This option should only be used for a single id at a time.' - ir_model_data = self.pool.get('ir.model.data') - try: - template_id = ir_model_data.get_object_reference(cr, uid, 'crm', 'email_template_opportunity_mail')[1] - except ValueError: - template_id = False - try: - compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1] - except ValueError: - compose_form_id = False - if context is None: - context = {} - ctx = context.copy() - ctx.update({ - 'default_model': 'crm.lead', - 'default_res_id': ids[0], - 'default_use_template': bool(template_id), - 'default_template_id': template_id, - 'default_composition_mode': 'comment', - }) - return { - 'name': _('Compose Email'), - 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'mail.compose.message', - 'views': [(compose_form_id, 'form')], - 'view_id': compose_form_id, - 'target': 'new', - 'context': ctx, - } - # ---------------------------------------- # Mail Gateway # ---------------------------------------- diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml index 92914542d9d..219ff2cdeee 100644 --- a/addons/crm/crm_lead_data.xml +++ b/addons/crm/crm_lead_data.xml @@ -220,6 +220,20 @@ ${not object.partner_id and object.email_from} + + Reminder to User + + + admin@example.com + ${object.user_id != False and object.user_id.email} + Reminder on Lead: ${object.id} from ${object.partner_id != False and object.partner_id.name or object.contact_name} + This opportunity did not have any activity since at least 5 days. Here are some details:

+
    +
  • Name: ${object.name}
  • +
  • ID: ${object.id}
  • +
  • Description: ${object.description}
  • +
]]>
+
diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index cb4302166a1..aa5aac76b9d 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -408,7 +408,7 @@ diff --git a/addons/crm/i18n/hu.po b/addons/crm/i18n/hu.po index 0289fac77cf..791273361eb 100644 --- a/addons/crm/i18n/hu.po +++ b/addons/crm/i18n/hu.po @@ -7,14 +7,14 @@ msgstr "" "Project-Id-Version: OpenERP Server 6.0dev\n" "Report-Msgid-Bugs-To: support@openerp.com\n" "POT-Creation-Date: 2012-12-21 17:04+0000\n" -"PO-Revision-Date: 2013-07-09 07:36+0000\n" +"PO-Revision-Date: 2013-07-25 13:52+0000\n" "Last-Translator: krnkris \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2013-07-10 05:25+0000\n" -"X-Generator: Launchpad (build 16696)\n" +"X-Launchpad-Export-Date: 2013-07-26 05:14+0000\n" +"X-Generator: Launchpad (build 16700)\n" #. module: crm #: model:crm.case.stage,name:crm.stage_lead3 @@ -241,7 +241,7 @@ msgstr "Kilép" #: view:crm.lead:0 #: field:crm.lead,state_id:0 msgid "State" -msgstr "Állapot" +msgstr "Állam/Megye" #. module: crm #: field:res.partner,meeting_count:0 diff --git a/addons/email_template/__init__.py b/addons/email_template/__init__.py index d1cf5b28431..3f091fd8645 100644 --- a/addons/email_template/__init__.py +++ b/addons/email_template/__init__.py @@ -22,5 +22,6 @@ import email_template import wizard import res_partner +import ir_actions # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/__openerp__.py b/addons/email_template/__openerp__.py index 1dc3baaf63c..b7977660134 100644 --- a/addons/email_template/__openerp__.py +++ b/addons/email_template/__openerp__.py @@ -59,6 +59,7 @@ campaigns on any OpenERP document. 'wizard/email_template_preview_view.xml', 'email_template_view.xml', 'res_partner_view.xml', + 'ir_actions_view.xml', 'wizard/mail_compose_message_view.xml', 'security/ir.model.access.csv' ], diff --git a/addons/email_template/doc/changelog.rst b/addons/email_template/doc/changelog.rst new file mode 100644 index 00000000000..77e342c920a --- /dev/null +++ b/addons/email_template/doc/changelog.rst @@ -0,0 +1,12 @@ +.. _changelog: + +Changelog +========= + +`trunk (saas-2)` +---------------- + + - ``mail.compose.message``: added support of ``mail_server_id`` from template + - Server action update + + - added `email` server action type, now entirely based on email templates. \ No newline at end of file diff --git a/addons/email_template/doc/index.rst b/addons/email_template/doc/index.rst new file mode 100644 index 00000000000..58cf9413601 --- /dev/null +++ b/addons/email_template/doc/index.rst @@ -0,0 +1,13 @@ +Email Template module documentation +=================================== + +Email Template documentation topics +''''''''''''''''''''''''''''''''''' + +Changelog +''''''''' + +.. toctree:: + :maxdepth: 1 + + changelog.rst diff --git a/addons/email_template/ir_actions.py b/addons/email_template/ir_actions.py new file mode 100644 index 00000000000..bd860785da4 --- /dev/null +++ b/addons/email_template/ir_actions.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2013 OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import fields, osv + + +class actions_server(osv.Model): + """ Add email option in server actions. """ + _name = 'ir.actions.server' + _inherit = ['ir.actions.server'] + + def _get_states(self, cr, uid, context=None): + res = super(actions_server, self)._get_states(cr, uid, context=context) + res.insert(0, ('email', 'Send Email')) + return res + + _columns = { + 'email_from': fields.char('From', + help="Sender address; define the template to see its value. If not set, the default " + "value will be the author's email alias if configured, or email address."), + 'email_to': fields.char('To (Emails)', + help="Comma-separated recipient addresses; define the template to see its value"), + 'partner_to': fields.char('To (Partners)', + help="Comma-separated ids of recipient partners; define the template to see its value"), + 'subject': fields.char('Subject', + help="Email subject; define the template to see its value"), + 'body_html': fields.text('Body', + help="Rich-text/HTML version of the message; define the template to see its value"), + 'template_id': fields.many2one('email.template', 'Email Template', ondelete='set null', + help="Define the email template to use for the email to send.") + } + + def on_change_template_id(self, cr, uid, ids, template_id, context=None): + """ Render the raw template in the server action fields. """ + if template_id: + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids'] + template_values = self.pool.get('email.template').read(cr, uid, template_id, fields, context) + values = dict((field, template_values[field]) for field in fields if template_values.get(field)) + if not values.get('email_from'): + return {'warning': {'title': 'Incomplete template', 'message': 'Your template should define email_from'}, 'value': values} + else: + values = self.default_get(cr, uid, ['subject', 'body_html', 'email_from', 'email_to', 'partner_to'], context=context) + + return {'value': values} + + def create(self, cr, uid, values, context=None): + if values.get('template_id'): + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids'] + template_values = self.pool.get('email.template').read(cr, uid, values.get('template_id'), fields, context) + values.update(dict((field, template_values[field]) for field in fields if template_values.get(field))) + return super(actions_server, self).create(cr, uid, values, context=context) + + def write(self, cr, uid, ids, values, context=None): + if values.get('template_id'): + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids'] + template_values = self.pool.get('email.template').read(cr, uid, values.get('template_id'), fields, context) + values.update(dict((field, template_values[field]) for field in fields if template_values.get(field))) + return super(actions_server, self).write(cr, uid, ids, values, context=context) + + def run_action_email(self, cr, uid, action, eval_context=None, context=None): + if not action.template_id or not context.get('active_id'): + return False + self.pool['email.template'].send_mail(cr, uid, action.template_id.id, context.get('active_id'), + force_send=False, raise_exception=False, context=context) + return False + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/ir_actions_view.xml b/addons/email_template/ir_actions_view.xml new file mode 100644 index 00000000000..fae9c364312 --- /dev/null +++ b/addons/email_template/ir_actions_view.xml @@ -0,0 +1,49 @@ + + + + + + ir.actions.server.form + ir.actions.server + + + + +

+ Please set the Base Model before setting the action details. +

+ + +

+ Choose a template to display its values. +

+

+ The values displayed hereunder are informative. When sending the email, the values + will be taken from the email template. +

+
+ + +
+
+
+
+ +
+
diff --git a/addons/email_template/tests/__init__.py b/addons/email_template/tests/__init__.py index d63c5634cc3..9418985b06c 100644 --- a/addons/email_template/tests/__init__.py +++ b/addons/email_template/tests/__init__.py @@ -18,10 +18,11 @@ # along with this program. If not, see . # ############################################################################## -from . import test_mail +from . import test_mail, test_ir_actions checks = [ test_mail, + test_ir_actions, ] # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/email_template/tests/test_ir_actions.py b/addons/email_template/tests/test_ir_actions.py new file mode 100644 index 00000000000..d323ee36c1f --- /dev/null +++ b/addons/email_template/tests/test_ir_actions.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 2013-TODAY OpenERP S.A. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.addons.base.tests.test_ir_actions import TestServerActionsBase + + +class TestServerActionsEmail(TestServerActionsBase): + + def test_00_state_email(self): + """ Test ir.actions.server email type """ + cr, uid = self.cr, self.uid + + # create email_template + template_id = self.registry('email.template').create(cr, uid, { + 'name': 'TestTemplate', + 'email_from': 'myself@example.com', + 'email_to': 'brigitte@example.com', + 'partner_to': '[%s]' % self.test_partner_id, + 'model_id': self.res_partner_model_id, + 'subject': 'About ${object.name}', + 'body_html': '

Dear ${object.name}, your parent is ${object.parent_id and object.parent_id.name or "False"}

', + }) + + self.ir_actions_server.write(cr, uid, self.act_id, { + 'state': 'email', + 'template_id': template_id, + }) + run_res = self.ir_actions_server.run(cr, uid, [self.act_id], context=self.context) + self.assertFalse(run_res, 'ir_actions_server: email server action correctly finished should return False') + + # check an email is waiting for sending + mail_ids = self.registry('mail.mail').search(cr, uid, [('subject', '=', 'About TestingPartner')]) + self.assertEqual(len(mail_ids), 1, 'ir_actions_server: TODO') + # check email content + mail = self.registry('mail.mail').browse(cr, uid, mail_ids[0]) + self.assertEqual(mail.body, '

Dear TestingPartner, your parent is False

', + 'ir_actions_server: TODO') diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py index 746c2cc55f6..92bf7c3aedf 100644 --- a/addons/email_template/wizard/mail_compose_message.py +++ b/addons/email_template/wizard/mail_compose_message.py @@ -22,6 +22,7 @@ from openerp import tools from openerp.osv import osv, fields + def _reopen(self, res_id, model): return {'type': 'ir.actions.act_window', 'view_mode': 'form', @@ -34,7 +35,8 @@ def _reopen(self, res_id, model): 'context': { 'default_model': model, }, - } + } + class mail_compose_message(osv.TransientModel): _inherit = 'mail.compose.message' @@ -58,7 +60,7 @@ class mail_compose_message(osv.TransientModel): context = {} wizard_context = dict(context) for wizard in self.browse(cr, uid, ids, context=context): - if wizard.template_id and not wizard.template_id.user_signature: + if wizard.template_id: wizard_context['mail_notify_user_signature'] = False # template user_signature is added when generating body_html if not wizard.attachment_ids or wizard.composition_mode == 'mass_mail' or not wizard.template_id: continue @@ -75,7 +77,7 @@ class mail_compose_message(osv.TransientModel): """ - mass_mailing: we cannot render, so return the template values - normal mode: return rendered values """ if template_id and composition_mode == 'mass_mail': - fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids'] + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'mail_server_id'] template_values = self.pool.get('email.template').read(cr, uid, template_id, fields, context) values = dict((field, template_values[field]) for field in fields if template_values.get(field)) elif template_id: @@ -95,7 +97,7 @@ class mail_compose_message(osv.TransientModel): } values['attachment_ids'].append(ir_attach_obj.create(cr, uid, data_attach, context=context)) else: - values = self.default_get(cr, uid, ['subject', 'body', 'email_from', 'email_to', 'email_cc', 'partner_to', 'reply_to', 'attachment_ids'], context=context) + values = self.default_get(cr, uid, ['subject', 'body', 'email_from', 'email_to', 'email_cc', 'partner_to', 'reply_to', 'attachment_ids', 'mail_server_id'], context=context) if values.get('body_html'): values['body'] = values.pop('body_html') @@ -150,7 +152,7 @@ class mail_compose_message(osv.TransientModel): mail.compose.message, transform email_cc and email_to into partner_ids """ template_values = self.pool.get('email.template').generate_email(cr, uid, template_id, res_id, context=context) # filter template values - fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'attachments'] + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'attachments', 'mail_server_id'] values = dict((field, template_values[field]) for field in fields if template_values.get(field)) values['body'] = values.pop('body_html', '') diff --git a/addons/google_base_account/google_base_account.py b/addons/google_base_account/google_base_account.py index a6cf67bbe62..50fbf233ce6 100644 --- a/addons/google_base_account/google_base_account.py +++ b/addons/google_base_account/google_base_account.py @@ -28,7 +28,7 @@ import urllib2 import simplejson -class google_service(osv.osv): +class google_service(osv.osv_memory): _name = 'google.service' def generate_refresh_token(self, cr, uid, service, authorization_code, context=None): @@ -51,10 +51,10 @@ class google_service(osv.osv): content = simplejson.loads(content) return content.get('refresh_token') - def _get_google_token_uri(self, cr, uid, service, context=None): + def _get_google_token_uri(self, cr, uid, service, scope, context=None): ir_config = self.pool['ir.config_parameter'] params = { - 'scope': 'https://www.googleapis.com/auth/drive', + 'scope': scope, 'redirect_uri': ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri'), 'client_id': ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service), 'response_type': 'code', diff --git a/addons/google_drive/google_drive.py b/addons/google_drive/google_drive.py index 1dc6b25f27c..8bc487ada7c 100644 --- a/addons/google_drive/google_drive.py +++ b/addons/google_drive/google_drive.py @@ -54,58 +54,69 @@ class config(osv.osv): attachment = attach_pool.browse(cr, uid, attach_ids[0], context) url = attachment.url else: - url = self.copy_doc(cr, uid, res_id, template_id, name_gdocs, model.model, context) + url = self.copy_doc(cr, uid, res_id, template_id, name_gdocs, model.model, context).get('url') return url - def copy_doc(self, cr, uid, res_id, template_id, name_gdocs, res_model, context=None): + def get_access_token(self, cr, uid, scope=None, context=None): ir_config = self.pool['ir.config_parameter'] google_drive_refresh_token = ir_config.get_param(cr, SUPERUSER_ID, 'google_drive_refresh_token') + group_config = self.pool['ir.model.data'].get_object_reference(cr, uid, 'base', 'group_erp_manager')[1] + user = self.pool['res.users'].read(cr, uid, uid, "groups_id") if not google_drive_refresh_token: - raise self.pool.get('res.config.settings').get_config_warning(cr, _("You haven't configured 'Authorization Code' generated from google, Please generate and configure it in %(menu:base_setup.menu_general_configuration)s."), context=context) + if group_config in user['groups_id']: + raise self.pool.get('res.config.settings').get_config_warning(cr, _("You haven't configured 'Authorization Code' generated from google, Please generate and configure it in %(menu:base_setup.menu_general_configuration)s."), context=context) + else: + raise osv.except_osv(_('Error!'), _("Google Drive is not yet configured. Please contact your administrator.")) google_drive_client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_drive_client_id') google_drive_client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_drive_client_secret') - 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", "Accept-Encoding": "gzip, deflate"} - data = dict(client_id=google_drive_client_id, - refresh_token=google_drive_refresh_token, - client_secret=google_drive_client_secret, - grant_type="refresh_token") - data = urllib.urlencode(data) + data = urllib.urlencode(dict(client_id=google_drive_client_id, + refresh_token=google_drive_refresh_token, + client_secret=google_drive_client_secret, + grant_type="refresh_token", + scope=scope or 'https://www.googleapis.com/auth/drive')) + headers = {"Content-type": "application/x-www-form-urlencoded", "Accept-Encoding": "gzip, deflate"} try: req = urllib2.Request('https://accounts.google.com/o/oauth2/token', data, headers) content = urllib2.urlopen(req).read() except urllib2.HTTPError: - raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during the token generation. Please request again an authorization code in %(menu:base_setup.menu_general_configuration)s."), context=context) + if group_config in user['groups_id']: + raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during the token generation. Please request again an authorization code in %(menu:base_setup.menu_general_configuration)s."), context=context) + else: + raise osv.except_osv(_('Error!'), _("Google Drive is not yet configured. Please contact your administrator.")) content = json.loads(content) + return content.get('access_token') + def copy_doc(self, cr, uid, res_id, template_id, name_gdocs, res_model, context=None): + ir_config = self.pool['ir.config_parameter'] + google_web_base_url = ir_config.get_param(cr, SUPERUSER_ID, 'web.base.url') + access_token = self.get_access_token(cr, uid, context=context) # Copy template in to drive with help of new access token - if 'access_token' in content: - request_url = "https://www.googleapis.com/drive/v2/files/%s?fields=parents/id&access_token=%s" % (template_id, content['access_token']) - try: - req = urllib2.Request(request_url, None, headers) - parents = urllib2.urlopen(req).read() - except urllib2.HTTPError: - raise self.pool.get('res.config.settings').get_config_warning(cr, _("The Google Template cannot be found. Maybe it has been deleted."), context=context) - parents_dict = json.loads(parents) + request_url = "https://www.googleapis.com/drive/v2/files/%s?fields=parents/id&access_token=%s" % (template_id, access_token) + headers = {"Content-type": "application/x-www-form-urlencoded", "Accept-Encoding": "gzip, deflate"} + try: + req = urllib2.Request(request_url, None, headers) + parents = urllib2.urlopen(req).read() + except urllib2.HTTPError: + raise self.pool.get('res.config.settings').get_config_warning(cr, _("The Google Template cannot be found. Maybe it has been deleted."), context=context) + parents_dict = json.loads(parents) - record_url = "Click on link to open Record in OpenERP\n %s/?db=%s#id=%s&model=%s" % (google_web_base_url, cr.dbname, res_id, res_model) - data = {"title": name_gdocs, "description": record_url, "parents": parents_dict['parents']} - request_url = "https://www.googleapis.com/drive/v2/files/%s/copy?access_token=%s" % (template_id, content['access_token']) - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - data_json = json.dumps(data) - # resp, content = Http().request(request_url, "POST", data_json, headers) - req = urllib2.Request(request_url, data_json, headers) - content = urllib2.urlopen(req).read() - content = json.loads(content) - res = False - if 'alternateLink' in content.keys(): - attach_pool = self.pool.get("ir.attachment") - attach_vals = {'res_model': res_model, 'name': name_gdocs, 'res_id': res_id, 'type': 'url', 'url': content['alternateLink']} - attach_pool.create(cr, uid, attach_vals) - res = content['alternateLink'] + record_url = "Click on link to open Record in OpenERP\n %s/?db=%s#id=%s&model=%s" % (google_web_base_url, cr.dbname, res_id, res_model) + data = {"title": name_gdocs, "description": record_url, "parents": parents_dict['parents']} + request_url = "https://www.googleapis.com/drive/v2/files/%s/copy?access_token=%s" % (template_id, access_token) + headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} + data_json = json.dumps(data) + # resp, content = Http().request(request_url, "POST", data_json, headers) + req = urllib2.Request(request_url, data_json, headers) + content = urllib2.urlopen(req).read() + content = json.loads(content) + res = {} + if content.get('alternateLink'): + attach_pool = self.pool.get("ir.attachment") + attach_vals = {'res_model': res_model, 'name': name_gdocs, 'res_id': res_id, 'type': 'url', 'url': content['alternateLink']} + res['id'] = attach_pool.create(cr, uid, attach_vals) + res['url'] = content['alternateLink'] return res def get_google_drive_config(self, cr, uid, res_model, res_id, context=None): @@ -166,6 +177,7 @@ class config(osv.osv): 'google_drive_resource_id': fields.function(_resource_get, type="char", string='Resource Id'), 'google_drive_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), + 'active': fields.boolean('Active'), } def onchange_model_id(self, cr, uid, ids, model_id, context=None): @@ -179,6 +191,7 @@ class config(osv.osv): _defaults = { 'name_template': 'Document %(name)s', + 'active': True, } def _check_model_id(self, cr, uid, ids, context=None): @@ -191,6 +204,9 @@ class config(osv.osv): (_check_model_id, 'Model of selected filter is not matching with model of current template.', ['model_id', 'filter_id']), ] + def get_google_scope(self): + return 'https://www.googleapis.com/auth/drive' + config() @@ -202,7 +218,7 @@ class base_config_settings(osv.osv): 'google_drive_uri': fields.char('URI', readonly=True, help="The URL to generate the authorization code from Google"), } _defaults = { - 'google_drive_uri': lambda s, cr, uid, c: s.pool['google.service']._get_google_token_uri(cr, uid, 'drive', context=c), + '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), } def set_google_authorization_code(self, cr, uid, ids, context=None): diff --git a/addons/google_drive/google_drive_data.xml b/addons/google_drive/google_drive_data.xml index c9266547969..b1f9883c149 100644 --- a/addons/google_drive/google_drive_data.xml +++ b/addons/google_drive/google_drive_data.xml @@ -4,12 +4,12 @@ google_drive_client_id - 39623646228-eg3ggo3mk6o40m7rguobi3rkl9frh4tb.apps.googleusercontent.com + 598905559630.apps.googleusercontent.com google_drive_client_secret - Ul-PtmnSWs3euWs20fdono0e + vTmou73c-njP-1qCxm7qx7QE diff --git a/addons/google_drive/res_config_user_view.xml b/addons/google_drive/res_config_user_view.xml index 728ef03c5dd..dc563a76c2b 100644 --- a/addons/google_drive/res_config_user_view.xml +++ b/addons/google_drive/res_config_user_view.xml @@ -23,6 +23,7 @@ +