diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 758385d66cb..91c6d6608fd 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -612,6 +612,13 @@
+
\n" +" " +"点击创建新客户分组\n" +"
\n" +" " +"创建指定的分类用于赋值给你的联系人\n" +" " +"以便更好管理你和他们的联系。分组工具\n" +" " +"可以根据你预设的条件给联系人分配组。\n" +"
\n" +" " #. module: crm #: field:crm.opportunity2phonecall,contact_name:0 @@ -445,16 +462,16 @@ msgid "#Opportunities" msgstr "#商机" #. module: crm -#: code:addons/crm/crm_lead.py:624 +#: code:addons/crm/crm_lead.py:640 #, python-format msgid "" "Please select more than one element (lead or opportunity) from the list view." -msgstr "" +msgstr "请从列表视图中选择一个以上元素(线索或机会)。" #. module: crm #: view:crm.lead:0 msgid "Leads that are assigned to one of the sale teams I manage, or to me" -msgstr "" +msgstr "分配给我锁管理的某个销售队伍,或给我的线索。" #. module: crm #: field:crm.lead,partner_address_email:0 @@ -473,6 +490,16 @@ msgid "" " \n" " " msgstr "" +"\n" +" " +"点击创建新的销售团队\n" +"
\n" +" " +"使用销售团队,把不同销售员或部门组织成独立的团队。\n" +" " +"每个团队会使用自己的商机列表工作。\n" +" \n" +" " #. module: crm #: model:process.transition,note:crm.process_transition_opportunitymeeting0 @@ -511,7 +538,7 @@ msgstr "邮件" #. module: crm #: model:mail.message.subtype,description:crm.mt_lead_stage msgid "Stage changed" -msgstr "" +msgstr "任务阶段已改变" #. module: crm #: selection:crm.lead.report,creation_month:0 @@ -572,7 +599,7 @@ msgstr "合并" #. module: crm #: model:email.template,subject:crm.email_template_opportunity_mail msgid "Opportunity ${object.name | h})" -msgstr "" +msgstr "商机${object.name | h})" #. module: crm #: view:crm.case.categ:0 @@ -590,6 +617,8 @@ msgid "" "Reminder on Lead: [[object.id ]] [[object.partner_id and 'of ' " "+object.partner_id.name or '']]" msgstr "" +"线索:[[object.id ]] [[object.partner_id and 'of ' +object.partner_id.name or " +"'']]的提醒" #. module: crm #: view:crm.segmentation:0 @@ -630,6 +659,13 @@ msgid "" " \n" " " msgstr "" +"\n" +" 点击创建新类型\n" +"
\n" +" " +"创建指定的电话类型,更好地定义系统中记录的电话类型\n" +"
\n" +" " #. module: crm #: help:crm.case.section,reply_to:0 @@ -712,7 +748,7 @@ msgid "Statistics Dashboard" msgstr "统计控制台" #. module: crm -#: code:addons/crm/crm_lead.py:861 +#: code:addons/crm/crm_lead.py:878 #: model:crm.case.stage,name:crm.stage_lead2 #: selection:crm.case.stage,type:0 #: view:crm.lead:0 @@ -738,7 +774,7 @@ msgstr "转为商机" #. module: crm #: model:ir.model,name:crm.model_sale_config_settings msgid "sale.config.settings" -msgstr "" +msgstr "sale.config.settings" #. module: crm #: view:crm.segmentation:0 @@ -759,7 +795,7 @@ msgstr "查询电话访问" #: view:crm.lead.report:0 msgid "" "Leads/Opportunities that are assigned to one of the sale teams I manage" -msgstr "" +msgstr "分配给我所管理的某个销售团队的线索/商机。" #. module: crm #: field:calendar.attendee,categ_id:0 @@ -772,7 +808,7 @@ msgid "Exclusive" msgstr "唯一的" #. module: crm -#: code:addons/crm/crm_lead.py:584 +#: code:addons/crm/crm_lead.py:600 #, python-format msgid "From %s : %s" msgstr "发自: %s:%s" @@ -866,7 +902,7 @@ msgstr "标记为已赢得" #. module: crm #: model:ir.filters,name:crm.filter_usa_lead msgid "Leads from USA" -msgstr "" +msgstr "来自USA的线索" #. module: crm #: view:crm.lead:0 @@ -917,7 +953,7 @@ msgstr "参考" msgid "" "Opportunities that are assigned to either me or one of the sale teams I " "manage" -msgstr "" +msgstr "分配给我或者我管理的某个销售团队的商机。" #. module: crm #: help:crm.case.section,resource_calendar_id:0 @@ -940,7 +976,7 @@ msgid "Next Action" msgstr "下一动作" #. module: crm -#: code:addons/crm/crm_lead.py:763 +#: code:addons/crm/crm_lead.py:780 #, python-format msgid "Partner set to %s." msgstr "" @@ -983,6 +1019,8 @@ msgid "" "Allows you to track your customers/suppliers claims and grievances.\n" " This installs the module crm_claim." msgstr "" +"允许你记录客户/供应商的索赔和抱怨。\n" +" 将安装crm_claim模块" #. module: crm #: model:crm.case.stage,name:crm.stage_lead6 @@ -1030,10 +1068,10 @@ msgid "Creation Date" msgstr "创建日期" #. module: crm -#: code:addons/crm/crm_lead.py:698 +#: code:addons/crm/crm_lead.py:715 #, python-format msgid "Lead converted into an Opportunity" -msgstr "" +msgstr "线索 已转换成商机" #. module: crm #: selection:crm.segmentation.line,expr_name:0 @@ -1094,7 +1132,7 @@ msgstr "删除" #. module: crm #: model:mail.message.subtype,description:crm.mt_lead_create msgid "Opportunity created" -msgstr "" +msgstr "商机已创建" #. module: crm #: view:crm.lead:0 @@ -1123,6 +1161,17 @@ msgid "" " \n" " " msgstr "" +"\n" +" 点击创建新的商机\n" +"
\n" +" OpenERP帮你记录你的销售管道\n" +" 跟踪潜在销售并更好地预测未来收益\n" +"
\n" +" 你可以对商机安排会议或电话,\n" +" 将他们转化成报价单,附上相关\n" +" 文档,跟踪所有的讨论等等。\n" +"
\n" +" " #. module: crm #: field:crm.segmentation,partner_id:0 @@ -1186,13 +1235,13 @@ msgstr "如果你勾选了这里,这个阶段会作为每个销售团队的默 msgid "" "This field is used to distinguish stages related to Leads from stages " "related to Opportunities, or to specify stages available for both types." -msgstr "" +msgstr "此域用于区分用于线索的阶段和用于商机的阶段,或者指示同时可用于两个类型。" #. module: crm #: model:mail.message.subtype,name:crm.mt_lead_create #: model:mail.message.subtype,name:crm.mt_salesteam_lead msgid "Lead Created" -msgstr "" +msgstr "线索已创建" #. module: crm #: help:crm.segmentation,sales_purchase_active:0 @@ -1217,7 +1266,9 @@ msgid "Days to Close" msgstr "结束日期" #. module: crm +#: code:addons/crm/crm_lead.py:1057 #: field:crm.case.section,complete_name:0 +#, python-format msgid "unknown" msgstr "未知" @@ -1264,7 +1315,7 @@ msgid "" "progress the Status is set to 'Open'. When the case is over, the Status is " "set to 'Done'. If the case needs to be reviewed then the Status is set to " "'Pending'." -msgstr "" +msgstr "当一个创建时,状态设为‘草稿’。如果此案在进行中,被设为‘打开‘。当案子结束,状态被设为’结束‘。如果需要被审阅,状态被设为’等待‘" #. module: crm #: model:crm.case.section,name:crm.crm_case_section_1 @@ -1300,7 +1351,7 @@ msgid "Lead Description" msgstr "销售线索描述" #. module: crm -#: code:addons/crm/crm_lead.py:565 +#: code:addons/crm/crm_lead.py:581 #, python-format msgid "Merged opportunities" msgstr "合并商机" @@ -1373,7 +1424,7 @@ msgstr "待办事项" #. module: crm #: model:mail.message.subtype,description:crm.mt_lead_lost msgid "Opportunity lost" -msgstr "" +msgstr "丢掉的商机" #. module: crm #: field:crm.lead2opportunity.partner,action:0 @@ -1422,7 +1473,7 @@ msgstr "用户" #. module: crm #: model:mail.message.subtype,name:crm.mt_lead_stage msgid "Stage Changed" -msgstr "" +msgstr "阶段已改变" #. module: crm #: field:crm.case.stage,section_ids:0 @@ -1495,7 +1546,7 @@ msgstr "信息和通信历史记录" #. module: crm #: view:crm.lead:0 msgid "Show Countries" -msgstr "" +msgstr "显示国家" #. module: crm #: view:crm.lead:0 @@ -1567,7 +1618,7 @@ msgid "" "The status of your document will automatically change regarding the selected " "stage. For example, if a stage is related to the status 'Close', when your " "document reaches this stage, it is automatically closed." -msgstr "" +msgstr "文档的状态会根据选中的阶段自动改变。如果一个阶段关联了‘关闭’状态,当文档到达这个阶段就自动被关闭。" #. module: crm #: view:crm.lead2opportunity.partner.mass:0 @@ -1588,7 +1639,7 @@ msgstr "通话月份" #: code:addons/crm/crm_phonecall.py:290 #, python-format msgid "Partner has been created." -msgstr "" +msgstr "合作伙伴已创建" #. module: crm #: field:sale.config.settings,module_crm_claim:0 @@ -1602,6 +1653,7 @@ msgid "" "the treatment delays or number of leads per state. You can sort out your " "leads analysis by different groups to get accurate grained analysis." msgstr "" +"线索分析允许你检查不同的关联CRM的信息,例如延迟或每个状态的线索的数量。你可以使用不同的分组对线索分析进行整理已获得精确细致的分析结果。" #. module: crm #: model:crm.case.categ,name:crm.categ_oppor3 @@ -1822,7 +1874,7 @@ msgstr "销售团队" #. module: crm #: field:crm.case.stage,case_default:0 msgid "Default to New Sales Team" -msgstr "" +msgstr "默认分配给新建销售团队" #. module: crm #: view:crm.lead:0 @@ -1861,10 +1913,10 @@ msgid "Leads" msgstr "线索" #. module: crm -#: code:addons/crm/crm_lead.py:563 +#: code:addons/crm/crm_lead.py:579 #, python-format msgid "Merged leads" -msgstr "" +msgstr "合并的线索" #. module: crm #: model:crm.case.categ,name:crm.categ_oppor5 @@ -1887,7 +1939,7 @@ msgstr "待办" #: model:mail.message.subtype,name:crm.mt_lead_convert_to_opportunity #: model:mail.message.subtype,name:crm.mt_salesteam_lead_opportunity msgid "Lead to Opportunity" -msgstr "" +msgstr "线索到商机" #. module: crm #: field:crm.lead,user_email:0 @@ -1955,7 +2007,6 @@ msgid "Global CC" msgstr "完整抄送" #. module: crm -#: view:crm.lead:0 #: view:crm.phonecall:0 #: model:ir.actions.act_window,name:crm.crm_case_categ_phone0 #: model:ir.ui.menu,name:crm.menu_crm_case_phone @@ -2089,7 +2140,7 @@ msgstr "转换选项" msgid "" "Follow this salesteam to automatically track the events associated to users " "of this team." -msgstr "" +msgstr "跟踪此销售团队,自动跟踪此团队中用户关联的事件。" #. module: crm #: view:crm.lead:0 @@ -2101,7 +2152,7 @@ msgstr "地址" msgid "" "The email address associated with this team. New emails received will " "automatically create new leads assigned to the team." -msgstr "" +msgstr "此邮件地址关联此团队。收到的新邮件将自动创建线索并分配给此团队。" #. module: crm #: view:crm.lead:0 @@ -2193,13 +2244,24 @@ msgid "" " \n" " " msgstr "" +"\n" +" 点击安排一个销售电话\n" +"
\n" +" " +"OpenERP允许你容易地定义销售团队要打的\n" +" 电话并根据跟踪处理。 " +" \n" +"
\n" +" 你可以使用导入功能来导入新列表\n" +"
\n" +" " #. module: crm #: help:crm.case.stage,fold:0 msgid "" "This stage is not visible, for example in status bar or kanban view, when " "there are no records in that stage to display." -msgstr "" +msgstr "此阶段无记录可显示时,在状态栏或看板视图等处不可见。" #. module: crm #: field:crm.lead.report,nbr:0 @@ -2245,7 +2307,7 @@ msgstr "运行中" #. module: crm #: model:mail.message.subtype,description:crm.mt_lead_convert_to_opportunity msgid "Lead converted into an opportunity" -msgstr "" +msgstr "装换成商机的线索" #. module: crm #: view:crm.lead:0 @@ -2255,7 +2317,7 @@ msgstr "未分配的线索" #. module: crm #: model:mail.message.subtype,description:crm.mt_lead_won msgid "Opportunity won" -msgstr "" +msgstr "获胜的商机" #. module: crm #: field:crm.case.categ,object_id:0 @@ -2321,7 +2383,7 @@ msgstr "在这报表中,你能分析你的销售团队在电话访问上的业 #. module: crm #: field:crm.case.stage,fold:0 msgid "Fold by Default" -msgstr "" +msgstr "默认折叠" #. module: crm #: field:crm.case.stage,state:0 @@ -2357,7 +2419,7 @@ msgstr "已确认" #. module: crm #: model:ir.model,name:crm.model_crm_partner_binding msgid "Handle partner binding or generation in CRM wizards." -msgstr "" +msgstr "在CRM向导中处理合作伙伴的绑定或生成。" #. module: crm #: model:ir.actions.act_window,name:crm.act_oppor_stage_user @@ -2408,11 +2470,23 @@ msgid "" " \n" " " msgstr "" +"\n" +" 点击创建一个未验证的线索。\n" +"
\n" +" 如果你在创建一个商机或者客户前\n" +" 需要验证,使用线索。可以是一张收到的\n" +" 名片,网站上收到的一个联系方式,或者\n" +" 你导入系统的一个文件数据。\n" +"
\n" +" 一旦被确定,线索可以被装换成商机\n" +" 以及/或者你的地址簿中的新客户。\n" +"
\n" +" " #. module: crm #: field:sale.config.settings,fetchmail_lead:0 msgid "Create leads from incoming mails" -msgstr "" +msgstr "从收到的邮件创建线索" #. module: crm #: view:crm.lead:0 @@ -2480,6 +2554,19 @@ msgid "" " \n" " " msgstr "" +"\n" +" 点击创建电话总结\n" +"
\n" +" OpenERP " +"允许你快速记录打入的电话,用来\n" +" " +"跟踪与用户沟通的历史,或通知另一个销售团队。\n" +"
\n" +" " +"为了跟踪处理一个电话,你可以触发请求另一次电话,\n" +" 一次会议或者一个商机。\n" +"
\n" +" " #. module: crm #: model:process.node,note:crm.process_node_leads0 @@ -2526,6 +2613,20 @@ msgid "" " \n" " " msgstr "" +"\n" +" " +"点击新建一个销售标签\n" +"
\n" +" " +"创建指定的适合公司活动的标签\n" +" " +"用于更好地分析你的线索和商机。\n" +" " +"标签分类可以反映你的商品结构或者\n" +" " +"不同的销售类型。\n" +"
\n" +" " #. module: crm #: selection:crm.lead.report,creation_month:0 @@ -2538,7 +2639,7 @@ msgstr "8月" #: model:mail.message.subtype,name:crm.mt_lead_lost #: model:mail.message.subtype,name:crm.mt_salesteam_lead_lost msgid "Opportunity Lost" -msgstr "" +msgstr "丢失的商机" #. module: crm #: field:crm.lead.report,deadline_month:0 @@ -2634,7 +2735,7 @@ msgstr "通话日志" #: model:mail.message.subtype,name:crm.mt_lead_won #: model:mail.message.subtype,name:crm.mt_salesteam_lead_won msgid "Opportunity Won" -msgstr "" +msgstr "获胜的商机" #. module: crm #: model:ir.actions.act_window,name:crm.crm_case_section_act_tree @@ -2773,7 +2874,7 @@ msgstr "电话访问" #. module: crm #: view:crm.phonecall.report:0 msgid "Phone calls that are assigned to one of the sale teams I manage" -msgstr "" +msgstr "分配给某个我所管理的销售团队的电话。" #. module: crm #: view:crm.lead:0 @@ -2848,6 +2949,19 @@ msgid "" " \n" " " msgstr "" +"\n" +" " +"点击定义一个新渠道\n" +"
\n" +" " +"使用渠道来记录你的线索和商机的来源。\n" +" " +"主要用于市场工作相关的销售分析报告。\n" +"
\n" +" " +"渠道例子:公司网站,电话,市场活动,经销商等\n" +"
\n" +" " #. module: crm #: view:crm.lead:0 @@ -2885,7 +2999,7 @@ msgid "Working Hours" msgstr "工作时间" #. module: crm -#: code:addons/crm/crm_lead.py:968 +#: code:addons/crm/crm_lead.py:986 #: view:crm.lead:0 #: field:crm.lead2opportunity.partner,partner_id:0 #: field:crm.lead2opportunity.partner.mass,partner_id:0 @@ -3007,7 +3121,7 @@ msgstr "时事通信" #. module: crm #: model:mail.message.subtype,name:crm.mt_salesteam_lead_stage msgid "Opportunity Stage Changed" -msgstr "" +msgstr "商机状态已改变" #. module: crm #: model:ir.actions.act_window,help:crm.crm_lead_stage_act @@ -3021,6 +3135,16 @@ msgid "" "
\n" " " msgstr "" +"\n" +" " +"点击设置你的线索/商机管道的新阶段。\n" +"
\n" +" " +"阶段允许销售人员记录特定的线索或商机\n" +" " +"在销售循环中的位置。\n" +"
\n" +" " #~ msgid "My Draft " #~ msgstr "我的草稿 " diff --git a/addons/crm_partner_assign/i18n/zh_CN.po b/addons/crm_partner_assign/i18n/zh_CN.po index af764d72747..d69d52029fc 100644 --- a/addons/crm_partner_assign/i18n/zh_CN.po +++ b/addons/crm_partner_assign/i18n/zh_CN.po @@ -8,14 +8,14 @@ msgstr "" "Project-Id-Version: openobject-addons\n" "Report-Msgid-Bugs-To: FULL NAME+ 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. +
++ Your template does not defined any email_from. Please update your template. +
+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/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 @@