{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/connector-interfaces/pulls/comments/23751725","id":23751725,"diff_hunk":"@@ -0,0 +1,131 @@\n+# -*- coding: utf-8 -*-\n+##############################################################################\n+#\n+#    Author: Nicolas Bessi\n+#    Copyright 2015 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 openerp.addons.connector.event import (on_record_write,\n+                                            on_record_create,\n+                                            on_record_unlink)\n+from ..consumer import delay_export, delay_deactivate\n+\n+\n+@on_record_create(model_names='connector.salesforce.product')\n+def export_sf_product(session, model_name, record_id, vals=None):\n+    \"\"\" Delay a job which export a product binding record.\n+    :param session: current session\n+    :type session: :py:class:`openerp.addons.connector.\n+                              session.ConnectorSession`\n+\n+    :param model_name: name of the binding model.\n+                       In our case `connector.salesforce.xxx`\n+    :type model_name: str\n+\n+    :record_id: The id of the binding model record\n+    :type record_id: int or long\n+    \"\"\"\n+\n+    record = session.browse(model_name, record_id)\n+    if record.backend_id.sf_product_master == 'erp':\n+        delay_export(session, model_name, record_id)\n+\n+\n+@on_record_unlink(model_names='connector.salesforce.product')\n+def deactivate_product(session, model_name, record_id):\n+    \"\"\" Delay a job which deactivate a binding product record\n+    on Salesforce\n+\n+    :param session: current session\n+    :type session: :py:class:`openerp.addons.connector.\n+                              session.ConnectorSession`\n+\n+    :param model_name: name of the binding model.\n+                       In our case `connector.salesforce.xxx`\n+    :type model_name: str\n+\n+    :record_id: The id of the binding model record\n+    :type record_id: int or long\n+    \"\"\"\n+\n+    record = session.browse(model_name, record_id)\n+    if record.backend_id.sf_product_master == 'erp':\n+        delay_deactivate(session, model_name, record_id)\n+\n+\n+@on_record_create(model_names='product.product')\n+def create_product_binding(session, model_name, record_id, vals=None):\n+    \"\"\"Create a binding entry for newly created product\n+    :param session: current session\n+    :type session: :py:class:`openerp.addons.connector.\n+                              session.ConnectorSession`\n+\n+    :param model_name: name of the binding model.\n+                       In our case `connector.salesforce.xxx`\n+    :type model_name: str\n+\n+    :record_id: The id of the binding model record\n+    :type record_id: int or long\n+    \"\"\"\n+\n+    record = session.browse(model_name, record_id)\n+    sf_product_model = 'connector.salesforce.product'\n+    backend_model = 'connector.salesforce.backend'\n+    backend_ids = session.search(backend_model, [])\n+    if not record.sale_ok or not record.active:\n+        return\n+    for backend in session.browse(backend_model, backend_ids):\n+        if backend.sf_product_master == 'erp':\n+            session.create(sf_product_model,\n+                           {'backend_id': backend.id,\n+                            'openerp_id': record_id})\n+\n+\n+@on_record_write(model_names='product.product')\n+def export_product(session, model_name, record_id, vals=None):\n+    \"\"\" Delay a job which export a binding record\n+    when related product is edited\n+    :param session: current session\n+    :type session: :py:class:`openerp.addons.connector.\n+                              session.ConnectorSession`\n+\n+    :param model_name: name of the binding model.\n+                       In our case `connector.salesforce.xxx`\n+    :type model_name: str\n+\n+    :record_id: The id of the binding model record\n+    :type record_id: int or long\n+    \"\"\"\n+    sf_product_model = 'connector.salesforce.product'\n+    backend_model = 'connector.salesforce.backend'\n+    backend_ids = session.search(backend_model, [])\n+    for backend in session.browse(backend_model, backend_ids):\n+        if backend.sf_product_master == 'erp':\n+            sf_prod_id = session.search(\n+                sf_product_model,\n+                [\n+                    ('backend_id', '=', backend.id),\n+                    ('openerp_id', '=', record_id)\n+                ]\n+            )","path":"connector_salesforce/salesforce_product/consumer.py","position":123,"original_position":123,"commit_id":"eed7759a6e95c411231dc8fc90784648f570210d","original_commit_id":"eed7759a6e95c411231dc8fc90784648f570210d","user":{"login":"guewen","id":417223,"avatar_url":"https://avatars.githubusercontent.com/u/417223?v=3","gravatar_id":"","url":"https://api.github.com/users/guewen","html_url":"https://github.com/guewen","followers_url":"https://api.github.com/users/guewen/followers","following_url":"https://api.github.com/users/guewen/following{/other_user}","gists_url":"https://api.github.com/users/guewen/gists{/gist_id}","starred_url":"https://api.github.com/users/guewen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guewen/subscriptions","organizations_url":"https://api.github.com/users/guewen/orgs","repos_url":"https://api.github.com/users/guewen/repos","events_url":"https://api.github.com/users/guewen/events{/privacy}","received_events_url":"https://api.github.com/users/guewen/received_events","type":"User","site_admin":false},"body":"`binder.to_backend()`","created_at":"2015-01-29T08:03:46Z","updated_at":"2015-01-29T08:03:46Z","html_url":"https://github.com/OCA/connector-interfaces/pull/11#discussion_r23751725","pull_request_url":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/OCA/connector-interfaces/pulls/comments/23751725"},"html":{"href":"https://github.com/OCA/connector-interfaces/pull/11#discussion_r23751725"},"pull_request":{"href":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11","id":28197606,"html_url":"https://github.com/OCA/connector-interfaces/pull/11","diff_url":"https://github.com/OCA/connector-interfaces/pull/11.diff","patch_url":"https://github.com/OCA/connector-interfaces/pull/11.patch","issue_url":"https://api.github.com/repos/OCA/connector-interfaces/issues/11","number":11,"state":"open","locked":false,"title":"Add Connector sales force","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-01-28T14:35:02Z","updated_at":"2015-01-29T08:03:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e69fdbdf89f4dfb20743f9f29925894a75af164a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11/commits","review_comments_url":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11/comments","review_comment_url":"https://api.github.com/repos/OCA/connector-interfaces/pulls/comments/{number}","comments_url":"https://api.github.com/repos/OCA/connector-interfaces/issues/11/comments","statuses_url":"https://api.github.com/repos/OCA/connector-interfaces/statuses/eed7759a6e95c411231dc8fc90784648f570210d","head":{"label":"nbessi:connector_sales_force","ref":"connector_sales_force","sha":"eed7759a6e95c411231dc8fc90784648f570210d","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":26436083,"name":"connector-interfaces","full_name":"nbessi/connector-interfaces","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-interfaces","description":"","fork":true,"url":"https://api.github.com/repos/nbessi/connector-interfaces","forks_url":"https://api.github.com/repos/nbessi/connector-interfaces/forks","keys_url":"https://api.github.com/repos/nbessi/connector-interfaces/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nbessi/connector-interfaces/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nbessi/connector-interfaces/teams","hooks_url":"https://api.github.com/repos/nbessi/connector-interfaces/hooks","issue_events_url":"https://api.github.com/repos/nbessi/connector-interfaces/issues/events{/number}","events_url":"https://api.github.com/repos/nbessi/connector-interfaces/events","assignees_url":"https://api.github.com/repos/nbessi/connector-interfaces/assignees{/user}","branches_url":"https://api.github.com/repos/nbessi/connector-interfaces/branches{/branch}","tags_url":"https://api.github.com/repos/nbessi/connector-interfaces/tags","blobs_url":"https://api.github.com/repos/nbessi/connector-interfaces/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nbessi/connector-interfaces/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nbessi/connector-interfaces/git/refs{/sha}","trees_url":"https://api.github.com/repos/nbessi/connector-interfaces/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nbessi/connector-interfaces/statuses/{sha}","languages_url":"https://api.github.com/repos/nbessi/connector-interfaces/languages","stargazers_url":"https://api.github.com/repos/nbessi/connector-interfaces/stargazers","contributors_url":"https://api.github.com/repos/nbessi/connector-interfaces/contributors","subscribers_url":"https://api.github.com/repos/nbessi/connector-interfaces/subscribers","subscription_url":"https://api.github.com/repos/nbessi/connector-interfaces/subscription","commits_url":"https://api.github.com/repos/nbessi/connector-interfaces/commits{/sha}","git_commits_url":"https://api.github.com/repos/nbessi/connector-interfaces/git/commits{/sha}","comments_url":"https://api.github.com/repos/nbessi/connector-interfaces/comments{/number}","issue_comment_url":"https://api.github.com/repos/nbessi/connector-interfaces/issues/comments/{number}","contents_url":"https://api.github.com/repos/nbessi/connector-interfaces/contents/{+path}","compare_url":"https://api.github.com/repos/nbessi/connector-interfaces/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nbessi/connector-interfaces/merges","archive_url":"https://api.github.com/repos/nbessi/connector-interfaces/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nbessi/connector-interfaces/downloads","issues_url":"https://api.github.com/repos/nbessi/connector-interfaces/issues{/number}","pulls_url":"https://api.github.com/repos/nbessi/connector-interfaces/pulls{/number}","milestones_url":"https://api.github.com/repos/nbessi/connector-interfaces/milestones{/number}","notifications_url":"https://api.github.com/repos/nbessi/connector-interfaces/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nbessi/connector-interfaces/labels{/name}","releases_url":"https://api.github.com/repos/nbessi/connector-interfaces/releases{/id}","created_at":"2014-11-10T12:48:04Z","updated_at":"2014-10-03T14:10:38Z","pushed_at":"2015-01-28T14:33:13Z","git_url":"git://github.com/nbessi/connector-interfaces.git","ssh_url":"git@github.com:nbessi/connector-interfaces.git","clone_url":"https://github.com/nbessi/connector-interfaces.git","svn_url":"https://github.com/nbessi/connector-interfaces","homepage":null,"size":480,"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":"7.0"}},"base":{"label":"OCA:7.0","ref":"7.0","sha":"5022e46ec44cb7ddc571558688ad7011519348d5","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":24750581,"name":"connector-interfaces","full_name":"OCA/connector-interfaces","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-interfaces","description":"","fork":false,"url":"https://api.github.com/repos/OCA/connector-interfaces","forks_url":"https://api.github.com/repos/OCA/connector-interfaces/forks","keys_url":"https://api.github.com/repos/OCA/connector-interfaces/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/connector-interfaces/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/connector-interfaces/teams","hooks_url":"https://api.github.com/repos/OCA/connector-interfaces/hooks","issue_events_url":"https://api.github.com/repos/OCA/connector-interfaces/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/connector-interfaces/events","assignees_url":"https://api.github.com/repos/OCA/connector-interfaces/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/connector-interfaces/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/connector-interfaces/tags","blobs_url":"https://api.github.com/repos/OCA/connector-interfaces/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/connector-interfaces/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/connector-interfaces/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/connector-interfaces/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/connector-interfaces/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/connector-interfaces/languages","stargazers_url":"https://api.github.com/repos/OCA/connector-interfaces/stargazers","contributors_url":"https://api.github.com/repos/OCA/connector-interfaces/contributors","subscribers_url":"https://api.github.com/repos/OCA/connector-interfaces/subscribers","subscription_url":"https://api.github.com/repos/OCA/connector-interfaces/subscription","commits_url":"https://api.github.com/repos/OCA/connector-interfaces/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/connector-interfaces/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/connector-interfaces/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/connector-interfaces/issues/comments/{number}","contents_url":"https://api.github.com/repos/OCA/connector-interfaces/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/connector-interfaces/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/connector-interfaces/merges","archive_url":"https://api.github.com/repos/OCA/connector-interfaces/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/connector-interfaces/downloads","issues_url":"https://api.github.com/repos/OCA/connector-interfaces/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/connector-interfaces/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/connector-interfaces/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/connector-interfaces/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/connector-interfaces/labels{/name}","releases_url":"https://api.github.com/repos/OCA/connector-interfaces/releases{/id}","created_at":"2014-10-03T07:46:15Z","updated_at":"2015-01-15T08:43:57Z","pushed_at":"2014-12-18T06:58:07Z","git_url":"git://github.com/OCA/connector-interfaces.git","ssh_url":"git@github.com:OCA/connector-interfaces.git","clone_url":"https://github.com/OCA/connector-interfaces.git","svn_url":"https://github.com/OCA/connector-interfaces","homepage":null,"size":517,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":6,"forks":11,"open_issues":6,"watchers":5,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11"},"html":{"href":"https://github.com/OCA/connector-interfaces/pull/11"},"issue":{"href":"https://api.github.com/repos/OCA/connector-interfaces/issues/11"},"comments":{"href":"https://api.github.com/repos/OCA/connector-interfaces/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/connector-interfaces/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/OCA/connector-interfaces/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/connector-interfaces/statuses/eed7759a6e95c411231dc8fc90784648f570210d"}}}}