{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/connector-salesforce/pulls/comments/36742905","id":36742905,"diff_hunk":"@@ -0,0 +1,407 @@\n+# -*- coding: utf-8 -*-\n+##############################################################################\n+#\n+#    Author: Nicolas Bessi\n+#    Copyright 2014 Camptocamp SA\n+#\n+#    This program is free software: you can redistribute it and/or modify\n+#    it under the terms of the GNU Affero General Public License as\n+#    published by the Free Software Foundation, either version 3 of the\n+#    License, or (at your option) any later version.\n+#\n+#    This program is distributed in the hope that it will be useful,\n+#    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#    GNU Affero General Public License for more details.\n+#\n+#    You should have received a copy of the GNU Affero General Public License\n+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+##############################################################################\n+from __future__ import absolute_import\n+import simplejson\n+from ..lib.oauth2_utils import SalesforceOauth2MAnager\n+from openerp import models, fields, api, exceptions\n+from openerp.tools.translate import _\n+from openerp.addons.connector import session as csession, connector\n+from ..unit.importer_synchronizer import batch_import, delayed_batch_import\n+from ..unit.exporter_synchronizer import batch_export, delayed_batch_export\n+\n+\n+class SalesforceBackend(models.Model):\n+    \"\"\"Salesforce backend\n+\n+    Please refer to connector backend documentation\n+\n+    There are 2 supported ways to access a Salesforce instance\n+    Oauth2 flow\n+    -----------\n+    In order to use it you have to add a remote application in Salesforce\n+    and enable Oauth login.\n+\n+    The created remote access app must have following parameters:\n+\n+    Permitted Users -->\tAll users may self-authorize\n+    Callback URL --> public_odoo_url/salesforce/oauth\n+\n+\n+    Once done you have to manage your app ensure the\n+    `Refresh token is valid until revoked` parameter is set.\n+\n+    The following authentication method are still exprimental\n+\n+    User Password flow\n+    ------------------\n+    This flow allows a user to connect to api using SOAP access\n+    in order to get a token. This approach is simpler but less secure\n+    The first step is to pass the domain of your Salesforce instance\n+    and an access token straight in Odoo backend.\n+\n+    You must have the full URL e.g (https://na1.salesforce.com)\n+    of your instance.\n+\n+    There are also two means of authentication:\n+    - Using username, password and security token\n+    - Using IP filtering, username, password and organizationId\n+    \"\"\"\n+\n+    _name = \"connector.salesforce.backend\"\n+    _inherit = \"connector.backend\"\n+    _description = \"\"\"Salesforce Backend\"\"\"\n+    _backend_type = \"salesforce\"\n+\n+    @api.model\n+    def _select_versions(self):\n+        \"\"\" Available versions\n+\n+        Can be inherited to add custom versions.\n+\n+        :return: list of tuple of available versions\n+        :rtype: list\n+        \"\"\"\n+        return self._select_versions_hook()\n+\n+    @api.model\n+    def _select_versions_hook(self):\n+        \"\"\" Available versions\n+\n+        Can be inherited to add custom versions.\n+\n+        :return: list of tuple of available versions\n+        :rtype: list\n+        \"\"\"\n+        return [('15', \"Winter'15\")]\n+\n+    authentication_method = fields.Selection(\n+        [\n+            ('pwd_token', 'Based on User, Password, Token'),\n+            ('oauth2', 'OAuth 2'),\n+            ('ip_filtering', 'Based on IP Filter and OrganizationId')\n+        ],\n+        string='Authentication Method',\n+        default='oauth2',\n+    )\n+\n+    name = fields.Char(\n+        'Name',\n+        required=True\n+    )\n+\n+    version = fields.Selection(\n+        selection='_select_versions',\n+        string='Version',\n+        required=True\n+    )\n+\n+    url = fields.Char(\n+        'URL',\n+        required=True,\n+    )\n+\n+    username = fields.Char(\n+        'User Name',\n+    )\n+\n+    password = fields.Char(\n+        'Password',\n+    )\n+\n+    consumer_key = fields.Char(\n+        'OAuth2 Consumer Key',\n+    )\n+\n+    consumer_secret = fields.Char(\n+        'OAuth2 secret',\n+    )\n+\n+    consumer_code = fields.Char(\n+        'OAuth2 client authorization code'\n+    )\n+    consumer_refresh_token = fields.Char(\n+        'OAuth2 Refresh Token'\n+    )\n+    consumer_token = fields.Char(\n+        'OAuth2 Token'\n+    )\n+    callback_url = fields.Char(\n+        'Public secure URL of Odoo (HTTPS)',\n+    )\n+    security_token = fields.Char(\n+        'Password flow Security API token',\n+    )\n+\n+    organization_uuid = fields.Char('OrganizationId')\n+\n+    sandbox = fields.Boolean(\n+        'Connect on sandbox instance',\n+    )\n+\n+    @api.model\n+    def _enforce_param(self, param_name):\n+        \"\"\"Ensure configuration parameter is set on backend record\n+\n+        :param param_name: name of parameter to validate\n+        :type param_name: str\n+\n+        :return: True is parameter is set or raise an exception\n+        :rtype: bool\n+        \"\"\"\n+        self.ensure_one()\n+        if not getattr(self, param_name, None):\n+            f_model = self.env['ir.model.fields']\n+            field = f_model.search(\n+                [('model', '=', self._name),\n+                 ('name', '=', param_name)],\n+            )\n+            if len(field) == 1:","path":"connector_salesforce/salesforce_backend/backend_model.py","position":176,"original_position":176,"commit_id":"62fc4052adfc35d54f9bfdbbc3702e68c079f165","original_commit_id":"62fc4052adfc35d54f9bfdbbc3702e68c079f165","user":{"login":"nbessi","id":147671,"avatar_url":"https://avatars.githubusercontent.com/u/147671?v=3","gravatar_id":"","url":"https://api.github.com/users/nbessi","html_url":"https://github.com/nbessi","followers_url":"https://api.github.com/users/nbessi/followers","following_url":"https://api.github.com/users/nbessi/following{/other_user}","gists_url":"https://api.github.com/users/nbessi/gists{/gist_id}","starred_url":"https://api.github.com/users/nbessi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbessi/subscriptions","organizations_url":"https://api.github.com/users/nbessi/orgs","repos_url":"https://api.github.com/users/nbessi/repos","events_url":"https://api.github.com/users/nbessi/events{/privacy}","received_events_url":"https://api.github.com/users/nbessi/received_events","type":"User","site_admin":false},"body":"Fun fact I just check in DB and in ir_models.py there is no constraints that ensure unicity...","created_at":"2015-08-11T13:18:46Z","updated_at":"2015-08-11T13:18:46Z","html_url":"https://github.com/OCA/connector-salesforce/pull/2#discussion_r36742905","pull_request_url":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/OCA/connector-salesforce/pulls/comments/36742905"},"html":{"href":"https://github.com/OCA/connector-salesforce/pull/2#discussion_r36742905"},"pull_request":{"href":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2","id":34163392,"html_url":"https://github.com/OCA/connector-salesforce/pull/2","diff_url":"https://github.com/OCA/connector-salesforce/pull/2.diff","patch_url":"https://github.com/OCA/connector-salesforce/pull/2.patch","issue_url":"https://api.github.com/repos/OCA/connector-salesforce/issues/2","number":2,"state":"open","locked":false,"title":"Connector salesforce 80","user":{"login":"nbessi","id":147671,"avatar_url":"https://avatars.githubusercontent.com/u/147671?v=3","gravatar_id":"","url":"https://api.github.com/users/nbessi","html_url":"https://github.com/nbessi","followers_url":"https://api.github.com/users/nbessi/followers","following_url":"https://api.github.com/users/nbessi/following{/other_user}","gists_url":"https://api.github.com/users/nbessi/gists{/gist_id}","starred_url":"https://api.github.com/users/nbessi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbessi/subscriptions","organizations_url":"https://api.github.com/users/nbessi/orgs","repos_url":"https://api.github.com/users/nbessi/repos","events_url":"https://api.github.com/users/nbessi/events{/privacy}","received_events_url":"https://api.github.com/users/nbessi/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-27T12:20:02Z","updated_at":"2015-08-11T13:18:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"24026818e1bb0c555f4f88d3b7d623ffd8fea19f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2/commits","review_comments_url":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2/comments","review_comment_url":"https://api.github.com/repos/OCA/connector-salesforce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/connector-salesforce/issues/2/comments","statuses_url":"https://api.github.com/repos/OCA/connector-salesforce/statuses/62fc4052adfc35d54f9bfdbbc3702e68c079f165","head":{"label":"nbessi:connector_salesforce_80","ref":"connector_salesforce_80","sha":"62fc4052adfc35d54f9bfdbbc3702e68c079f165","user":{"login":"nbessi","id":147671,"avatar_url":"https://avatars.githubusercontent.com/u/147671?v=3","gravatar_id":"","url":"https://api.github.com/users/nbessi","html_url":"https://github.com/nbessi","followers_url":"https://api.github.com/users/nbessi/followers","following_url":"https://api.github.com/users/nbessi/following{/other_user}","gists_url":"https://api.github.com/users/nbessi/gists{/gist_id}","starred_url":"https://api.github.com/users/nbessi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbessi/subscriptions","organizations_url":"https://api.github.com/users/nbessi/orgs","repos_url":"https://api.github.com/users/nbessi/repos","events_url":"https://api.github.com/users/nbessi/events{/privacy}","received_events_url":"https://api.github.com/users/nbessi/received_events","type":"User","site_admin":false},"repo":{"id":34253756,"name":"connector-salesforce","full_name":"nbessi/connector-salesforce","owner":{"login":"nbessi","id":147671,"avatar_url":"https://avatars.githubusercontent.com/u/147671?v=3","gravatar_id":"","url":"https://api.github.com/users/nbessi","html_url":"https://github.com/nbessi","followers_url":"https://api.github.com/users/nbessi/followers","following_url":"https://api.github.com/users/nbessi/following{/other_user}","gists_url":"https://api.github.com/users/nbessi/gists{/gist_id}","starred_url":"https://api.github.com/users/nbessi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbessi/subscriptions","organizations_url":"https://api.github.com/users/nbessi/orgs","repos_url":"https://api.github.com/users/nbessi/repos","events_url":"https://api.github.com/users/nbessi/events{/privacy}","received_events_url":"https://api.github.com/users/nbessi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nbessi/connector-salesforce","description":"Connect Salesforce with Odoo","fork":true,"url":"https://api.github.com/repos/nbessi/connector-salesforce","forks_url":"https://api.github.com/repos/nbessi/connector-salesforce/forks","keys_url":"https://api.github.com/repos/nbessi/connector-salesforce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nbessi/connector-salesforce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nbessi/connector-salesforce/teams","hooks_url":"https://api.github.com/repos/nbessi/connector-salesforce/hooks","issue_events_url":"https://api.github.com/repos/nbessi/connector-salesforce/issues/events{/number}","events_url":"https://api.github.com/repos/nbessi/connector-salesforce/events","assignees_url":"https://api.github.com/repos/nbessi/connector-salesforce/assignees{/user}","branches_url":"https://api.github.com/repos/nbessi/connector-salesforce/branches{/branch}","tags_url":"https://api.github.com/repos/nbessi/connector-salesforce/tags","blobs_url":"https://api.github.com/repos/nbessi/connector-salesforce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nbessi/connector-salesforce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nbessi/connector-salesforce/git/refs{/sha}","trees_url":"https://api.github.com/repos/nbessi/connector-salesforce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nbessi/connector-salesforce/statuses/{sha}","languages_url":"https://api.github.com/repos/nbessi/connector-salesforce/languages","stargazers_url":"https://api.github.com/repos/nbessi/connector-salesforce/stargazers","contributors_url":"https://api.github.com/repos/nbessi/connector-salesforce/contributors","subscribers_url":"https://api.github.com/repos/nbessi/connector-salesforce/subscribers","subscription_url":"https://api.github.com/repos/nbessi/connector-salesforce/subscription","commits_url":"https://api.github.com/repos/nbessi/connector-salesforce/commits{/sha}","git_commits_url":"https://api.github.com/repos/nbessi/connector-salesforce/git/commits{/sha}","comments_url":"https://api.github.com/repos/nbessi/connector-salesforce/comments{/number}","issue_comment_url":"https://api.github.com/repos/nbessi/connector-salesforce/issues/comments{/number}","contents_url":"https://api.github.com/repos/nbessi/connector-salesforce/contents/{+path}","compare_url":"https://api.github.com/repos/nbessi/connector-salesforce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nbessi/connector-salesforce/merges","archive_url":"https://api.github.com/repos/nbessi/connector-salesforce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nbessi/connector-salesforce/downloads","issues_url":"https://api.github.com/repos/nbessi/connector-salesforce/issues{/number}","pulls_url":"https://api.github.com/repos/nbessi/connector-salesforce/pulls{/number}","milestones_url":"https://api.github.com/repos/nbessi/connector-salesforce/milestones{/number}","notifications_url":"https://api.github.com/repos/nbessi/connector-salesforce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nbessi/connector-salesforce/labels{/name}","releases_url":"https://api.github.com/repos/nbessi/connector-salesforce/releases{/id}","created_at":"2015-04-20T10:21:23Z","updated_at":"2015-03-05T13:20:36Z","pushed_at":"2015-05-27T15:17:34Z","git_url":"git://github.com/nbessi/connector-salesforce.git","ssh_url":"git@github.com:nbessi/connector-salesforce.git","clone_url":"https://github.com/nbessi/connector-salesforce.git","svn_url":"https://github.com/nbessi/connector-salesforce","homepage":null,"size":621,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"8.0"}},"base":{"label":"OCA:8.0","ref":"8.0","sha":"5186da7f24fbe59408c79cbcac99a6f804d0348e","user":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"repo":{"id":31714650,"name":"connector-salesforce","full_name":"OCA/connector-salesforce","owner":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OCA/connector-salesforce","description":"Connect Salesforce with Odoo","fork":false,"url":"https://api.github.com/repos/OCA/connector-salesforce","forks_url":"https://api.github.com/repos/OCA/connector-salesforce/forks","keys_url":"https://api.github.com/repos/OCA/connector-salesforce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/connector-salesforce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/connector-salesforce/teams","hooks_url":"https://api.github.com/repos/OCA/connector-salesforce/hooks","issue_events_url":"https://api.github.com/repos/OCA/connector-salesforce/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/connector-salesforce/events","assignees_url":"https://api.github.com/repos/OCA/connector-salesforce/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/connector-salesforce/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/connector-salesforce/tags","blobs_url":"https://api.github.com/repos/OCA/connector-salesforce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/connector-salesforce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/connector-salesforce/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/connector-salesforce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/connector-salesforce/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/connector-salesforce/languages","stargazers_url":"https://api.github.com/repos/OCA/connector-salesforce/stargazers","contributors_url":"https://api.github.com/repos/OCA/connector-salesforce/contributors","subscribers_url":"https://api.github.com/repos/OCA/connector-salesforce/subscribers","subscription_url":"https://api.github.com/repos/OCA/connector-salesforce/subscription","commits_url":"https://api.github.com/repos/OCA/connector-salesforce/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/connector-salesforce/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/connector-salesforce/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/connector-salesforce/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/connector-salesforce/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/connector-salesforce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/connector-salesforce/merges","archive_url":"https://api.github.com/repos/OCA/connector-salesforce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/connector-salesforce/downloads","issues_url":"https://api.github.com/repos/OCA/connector-salesforce/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/connector-salesforce/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/connector-salesforce/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/connector-salesforce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/connector-salesforce/labels{/name}","releases_url":"https://api.github.com/repos/OCA/connector-salesforce/releases{/id}","created_at":"2015-03-05T13:20:36Z","updated_at":"2015-03-05T13:20:36Z","pushed_at":"2015-07-24T20:58:23Z","git_url":"git://github.com/OCA/connector-salesforce.git","ssh_url":"git@github.com:OCA/connector-salesforce.git","clone_url":"https://github.com/OCA/connector-salesforce.git","svn_url":"https://github.com/OCA/connector-salesforce","homepage":null,"size":718,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2"},"html":{"href":"https://github.com/OCA/connector-salesforce/pull/2"},"issue":{"href":"https://api.github.com/repos/OCA/connector-salesforce/issues/2"},"comments":{"href":"https://api.github.com/repos/OCA/connector-salesforce/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/connector-salesforce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/connector-salesforce/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/connector-salesforce/statuses/62fc4052adfc35d54f9bfdbbc3702e68c079f165"}}}}