{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/account-invoicing/pulls/comments/198668073","pull_request_review_id":132640684,"id":198668073,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5ODY2ODA3Mw==","diff_hunk":"@@ -127,15 +127,35 @@ def _compute_qty_refunded(self):\n         'move_ids.returned_move_ids.state',\n     )\n     def _compute_qty_returned(self):\n+        \"\"\"Made through read_group for not impacting in performance.\"\"\"\n+        ProductUom = self.env['product.uom']\n+        StockMove = self.env['stock.move']\n+        groups = StockMove.read_group(\n+            [('origin_returned_move_id.purchase_line_id', 'in', self.ids),\n+             ('state', '=', 'done'),\n+             ('location_id.usage', '!=', 'supplier')],\n+            ['origin_returned_move_id', 'product_uom_qty', 'product_uom'],\n+            ['origin_returned_move_id', 'product_uom'], lazy=False,\n+        )\n+        p = self._prefetch\n+        # load all moves records at once on first access\n+        origin_move_ids = set(g['origin_returned_move_id'][0] for g in groups)\n+        StockMove.browse(origin_move_ids).with_prefetch(p)\n+        # load all UoM records at once on first access\n+        uom_ids = set(g['product_uom'][0] for g in groups)\n+        ProductUom.browse(list(uom_ids)).with_prefetch(p)\n+        line_qtys = {}\n+        for g in groups:\n+            uom = ProductUom.browse(g[\"product_uom\"][0]).with_prefetch(p)\n+            move = StockMove.browse(\n+                g['origin_returned_move_id'][0]\n+            ).with_prefetch(p)\n+            line_qtys.setdefault(move.purchase_line_id.id, 0)\n+            line_qtys[move.purchase_line_id.id] += uom._compute_quantity(","path":"purchase_stock_picking_return_invoicing/models/purchase_order.py","position":28,"original_position":28,"commit_id":"41660fba6ef961e918d0bef35590c69f6baf4d2b","original_commit_id":"41660fba6ef961e918d0bef35590c69f6baf4d2b","user":{"login":"pedrobaeza","id":7165771,"node_id":"MDQ6VXNlcjcxNjU3NzE=","avatar_url":"https://avatars2.githubusercontent.com/u/7165771?v=4","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"body":"The same is evaluated on the `_compute_quantity` method, so no gain adding that lines","created_at":"2018-06-27T23:12:10Z","updated_at":"2018-06-27T23:12:10Z","html_url":"https://github.com/OCA/account-invoicing/pull/395#discussion_r198668073","pull_request_url":"https://api.github.com/repos/OCA/account-invoicing/pulls/395","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/OCA/account-invoicing/pulls/comments/198668073"},"html":{"href":"https://github.com/OCA/account-invoicing/pull/395#discussion_r198668073"},"pull_request":{"href":"https://api.github.com/repos/OCA/account-invoicing/pulls/395"}},"in_reply_to_id":198666405},"pull_request":{"url":"https://api.github.com/repos/OCA/account-invoicing/pulls/395","id":197646441,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk3NjQ2NDQx","html_url":"https://github.com/OCA/account-invoicing/pull/395","diff_url":"https://github.com/OCA/account-invoicing/pull/395.diff","patch_url":"https://github.com/OCA/account-invoicing/pull/395.patch","issue_url":"https://api.github.com/repos/OCA/account-invoicing/issues/395","number":395,"state":"open","locked":false,"title":"[10.0][IMP] purchase_stock_picking_returm_invoicing: Improve perf for qty_returned field","user":{"login":"pedrobaeza","id":7165771,"node_id":"MDQ6VXNlcjcxNjU3NzE=","avatar_url":"https://avatars2.githubusercontent.com/u/7165771?v=4","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"body":"This field is computed very slow with previous code. I have improved the speed through several techniques like read_group and shared prefetching. It might be less readable, but incredibly faster compared with the previous code.\r\n\r\ncc @Tecnativa","created_at":"2018-06-27T07:58:59Z","updated_at":"2018-06-27T23:12:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d368f0076746936757a6ce9e965a64619767dfad","assignee":null,"assignees":[],"requested_reviewers":[{"login":"mreficent","id":25005517,"node_id":"MDQ6VXNlcjI1MDA1NTE3","avatar_url":"https://avatars3.githubusercontent.com/u/25005517?v=4","gravatar_id":"","url":"https://api.github.com/users/mreficent","html_url":"https://github.com/mreficent","followers_url":"https://api.github.com/users/mreficent/followers","following_url":"https://api.github.com/users/mreficent/following{/other_user}","gists_url":"https://api.github.com/users/mreficent/gists{/gist_id}","starred_url":"https://api.github.com/users/mreficent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mreficent/subscriptions","organizations_url":"https://api.github.com/users/mreficent/orgs","repos_url":"https://api.github.com/users/mreficent/repos","events_url":"https://api.github.com/users/mreficent/events{/privacy}","received_events_url":"https://api.github.com/users/mreficent/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/OCA/account-invoicing/pulls/395/commits","review_comments_url":"https://api.github.com/repos/OCA/account-invoicing/pulls/395/comments","review_comment_url":"https://api.github.com/repos/OCA/account-invoicing/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/account-invoicing/issues/395/comments","statuses_url":"https://api.github.com/repos/OCA/account-invoicing/statuses/41660fba6ef961e918d0bef35590c69f6baf4d2b","head":{"label":"Tecnativa:10.0-purchase_stock_picking_returm_invoicing-perf","ref":"10.0-purchase_stock_picking_returm_invoicing-perf","sha":"41660fba6ef961e918d0bef35590c69f6baf4d2b","user":{"login":"Tecnativa","id":18120193,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE4MTIwMTkz","avatar_url":"https://avatars2.githubusercontent.com/u/18120193?v=4","gravatar_id":"","url":"https://api.github.com/users/Tecnativa","html_url":"https://github.com/Tecnativa","followers_url":"https://api.github.com/users/Tecnativa/followers","following_url":"https://api.github.com/users/Tecnativa/following{/other_user}","gists_url":"https://api.github.com/users/Tecnativa/gists{/gist_id}","starred_url":"https://api.github.com/users/Tecnativa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tecnativa/subscriptions","organizations_url":"https://api.github.com/users/Tecnativa/orgs","repos_url":"https://api.github.com/users/Tecnativa/repos","events_url":"https://api.github.com/users/Tecnativa/events{/privacy}","received_events_url":"https://api.github.com/users/Tecnativa/received_events","type":"Organization","site_admin":false},"repo":{"id":59533057,"node_id":"MDEwOlJlcG9zaXRvcnk1OTUzMzA1Nw==","name":"account-invoicing","full_name":"Tecnativa/account-invoicing","owner":{"login":"Tecnativa","id":18120193,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE4MTIwMTkz","avatar_url":"https://avatars2.githubusercontent.com/u/18120193?v=4","gravatar_id":"","url":"https://api.github.com/users/Tecnativa","html_url":"https://github.com/Tecnativa","followers_url":"https://api.github.com/users/Tecnativa/followers","following_url":"https://api.github.com/users/Tecnativa/following{/other_user}","gists_url":"https://api.github.com/users/Tecnativa/gists{/gist_id}","starred_url":"https://api.github.com/users/Tecnativa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tecnativa/subscriptions","organizations_url":"https://api.github.com/users/Tecnativa/orgs","repos_url":"https://api.github.com/users/Tecnativa/repos","events_url":"https://api.github.com/users/Tecnativa/events{/privacy}","received_events_url":"https://api.github.com/users/Tecnativa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Tecnativa/account-invoicing","description":"Odoo Invoicing Extension Addons","fork":true,"url":"https://api.github.com/repos/Tecnativa/account-invoicing","forks_url":"https://api.github.com/repos/Tecnativa/account-invoicing/forks","keys_url":"https://api.github.com/repos/Tecnativa/account-invoicing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tecnativa/account-invoicing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tecnativa/account-invoicing/teams","hooks_url":"https://api.github.com/repos/Tecnativa/account-invoicing/hooks","issue_events_url":"https://api.github.com/repos/Tecnativa/account-invoicing/issues/events{/number}","events_url":"https://api.github.com/repos/Tecnativa/account-invoicing/events","assignees_url":"https://api.github.com/repos/Tecnativa/account-invoicing/assignees{/user}","branches_url":"https://api.github.com/repos/Tecnativa/account-invoicing/branches{/branch}","tags_url":"https://api.github.com/repos/Tecnativa/account-invoicing/tags","blobs_url":"https://api.github.com/repos/Tecnativa/account-invoicing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tecnativa/account-invoicing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tecnativa/account-invoicing/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tecnativa/account-invoicing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tecnativa/account-invoicing/statuses/{sha}","languages_url":"https://api.github.com/repos/Tecnativa/account-invoicing/languages","stargazers_url":"https://api.github.com/repos/Tecnativa/account-invoicing/stargazers","contributors_url":"https://api.github.com/repos/Tecnativa/account-invoicing/contributors","subscribers_url":"https://api.github.com/repos/Tecnativa/account-invoicing/subscribers","subscription_url":"https://api.github.com/repos/Tecnativa/account-invoicing/subscription","commits_url":"https://api.github.com/repos/Tecnativa/account-invoicing/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tecnativa/account-invoicing/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tecnativa/account-invoicing/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tecnativa/account-invoicing/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tecnativa/account-invoicing/contents/{+path}","compare_url":"https://api.github.com/repos/Tecnativa/account-invoicing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tecnativa/account-invoicing/merges","archive_url":"https://api.github.com/repos/Tecnativa/account-invoicing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tecnativa/account-invoicing/downloads","issues_url":"https://api.github.com/repos/Tecnativa/account-invoicing/issues{/number}","pulls_url":"https://api.github.com/repos/Tecnativa/account-invoicing/pulls{/number}","milestones_url":"https://api.github.com/repos/Tecnativa/account-invoicing/milestones{/number}","notifications_url":"https://api.github.com/repos/Tecnativa/account-invoicing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tecnativa/account-invoicing/labels{/name}","releases_url":"https://api.github.com/repos/Tecnativa/account-invoicing/releases{/id}","deployments_url":"https://api.github.com/repos/Tecnativa/account-invoicing/deployments","created_at":"2016-05-24T02:13:53Z","updated_at":"2016-05-24T02:13:55Z","pushed_at":"2018-06-27T22:37:34Z","git_url":"git://github.com/Tecnativa/account-invoicing.git","ssh_url":"git@github.com:Tecnativa/account-invoicing.git","clone_url":"https://github.com/Tecnativa/account-invoicing.git","svn_url":"https://github.com/Tecnativa/account-invoicing","homepage":"","size":4316,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":1,"open_issues":0,"watchers":0,"default_branch":"9.0"}},"base":{"label":"OCA:10.0","ref":"10.0","sha":"53cf3d889acdc7a5ac85b028e8a7d7ba0940efec","user":{"login":"OCA","id":7600578,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc2MDA1Nzg=","avatar_url":"https://avatars1.githubusercontent.com/u/7600578?v=4","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":20881777,"node_id":"MDEwOlJlcG9zaXRvcnkyMDg4MTc3Nw==","name":"account-invoicing","full_name":"OCA/account-invoicing","owner":{"login":"OCA","id":7600578,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc2MDA1Nzg=","avatar_url":"https://avatars1.githubusercontent.com/u/7600578?v=4","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/account-invoicing","description":"Odoo Invoicing Extension Addons","fork":false,"url":"https://api.github.com/repos/OCA/account-invoicing","forks_url":"https://api.github.com/repos/OCA/account-invoicing/forks","keys_url":"https://api.github.com/repos/OCA/account-invoicing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/account-invoicing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/account-invoicing/teams","hooks_url":"https://api.github.com/repos/OCA/account-invoicing/hooks","issue_events_url":"https://api.github.com/repos/OCA/account-invoicing/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/account-invoicing/events","assignees_url":"https://api.github.com/repos/OCA/account-invoicing/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/account-invoicing/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/account-invoicing/tags","blobs_url":"https://api.github.com/repos/OCA/account-invoicing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/account-invoicing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/account-invoicing/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/account-invoicing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/account-invoicing/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/account-invoicing/languages","stargazers_url":"https://api.github.com/repos/OCA/account-invoicing/stargazers","contributors_url":"https://api.github.com/repos/OCA/account-invoicing/contributors","subscribers_url":"https://api.github.com/repos/OCA/account-invoicing/subscribers","subscription_url":"https://api.github.com/repos/OCA/account-invoicing/subscription","commits_url":"https://api.github.com/repos/OCA/account-invoicing/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/account-invoicing/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/account-invoicing/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/account-invoicing/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/account-invoicing/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/account-invoicing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/account-invoicing/merges","archive_url":"https://api.github.com/repos/OCA/account-invoicing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/account-invoicing/downloads","issues_url":"https://api.github.com/repos/OCA/account-invoicing/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/account-invoicing/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/account-invoicing/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/account-invoicing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/account-invoicing/labels{/name}","releases_url":"https://api.github.com/repos/OCA/account-invoicing/releases{/id}","deployments_url":"https://api.github.com/repos/OCA/account-invoicing/deployments","created_at":"2014-06-16T10:59:46Z","updated_at":"2018-06-27T02:36:10Z","pushed_at":"2018-06-27T20:04:34Z","git_url":"git://github.com/OCA/account-invoicing.git","ssh_url":"git@github.com:OCA/account-invoicing.git","clone_url":"https://github.com/OCA/account-invoicing.git","svn_url":"https://github.com/OCA/account-invoicing","homepage":"","size":4930,"stargazers_count":49,"watchers_count":49,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":231,"mirror_url":null,"archived":false,"open_issues_count":107,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":231,"open_issues":107,"watchers":49,"default_branch":"11.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/account-invoicing/pulls/395"},"html":{"href":"https://github.com/OCA/account-invoicing/pull/395"},"issue":{"href":"https://api.github.com/repos/OCA/account-invoicing/issues/395"},"comments":{"href":"https://api.github.com/repos/OCA/account-invoicing/issues/395/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/account-invoicing/pulls/395/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/account-invoicing/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/account-invoicing/pulls/395/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/account-invoicing/statuses/41660fba6ef961e918d0bef35590c69f6baf4d2b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pedrobaeza"}}