{"action":"created","comment":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/comments/80125230","id":80125230,"diff_hunk":"@@ -164,5 +163,51 @@ def update_payment_state\n     def round_money(n)\n       (n * 100).round / 100.0\n     end\n+\n+    def update_promotions\n+      [*line_items, *shipments, order].each do |item|\n+        promotion_adjustments = item.adjustments.select(&:promotion?)\n+\n+        promotion_adjustments.each(&:update!)\n+        Spree::Config.promotion_chooser_class.new(promotion_adjustments).update\n+        item.promo_total = promotion_adjustments.select(&:eligible?).sum(&:amount)\n+      end\n+    end\n+\n+    def update_taxes\n+      [*line_items, *shipments].each do |item|\n+        tax_adjustments = item.adjustments.select(&:tax?)\n+\n+        tax_adjustments.each(&:update!)\n+        item.included_tax_total   = tax_adjustments.select(&:included?).sum(&:amount)\n+        item.additional_tax_total = tax_adjustments.reject(&:included?).sum(&:amount)\n+      end\n+    end\n+\n+    def update_cancellations\n+      [*line_items, *shipments].each do |item|\n+        item.adjustments.select(&:cancellation?).each(&:update!)\n+      end\n+    end\n+\n+    def update_item_totals\n+      [*line_items, *shipments].each do |item|\n+        item_cancellation_total = item.adjustments.select(&:cancellation?).sum(&:amount)\n+\n+        item.adjustment_total = item.promo_total +\n+                                item.additional_tax_total +\n+                                item_cancellation_total\n+\n+        if item.changed?","path":"core/app/models/spree/order_updater.rb","position":55,"original_position":55,"commit_id":"a2d800096a6dcb8e33609fbba11c13892ba27034","original_commit_id":"a2d800096a6dcb8e33609fbba11c13892ba27034","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"Use next to skip iteration.","created_at":"2016-09-22T20:08:32Z","updated_at":"2016-09-22T20:08:32Z","html_url":"https://github.com/solidusio/solidus/pull/1466#discussion_r80125230","pull_request_url":"https://api.github.com/repos/solidusio/solidus/pulls/1466","_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments/80125230"},"html":{"href":"https://github.com/solidusio/solidus/pull/1466#discussion_r80125230"},"pull_request":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1466"}}},"pull_request":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/1466","id":86405336,"html_url":"https://github.com/solidusio/solidus/pull/1466","diff_url":"https://github.com/solidusio/solidus/pull/1466.diff","patch_url":"https://github.com/solidusio/solidus/pull/1466.patch","issue_url":"https://api.github.com/repos/solidusio/solidus/issues/1466","number":1466,"state":"open","locked":false,"title":"Break ItemAdjustments apart and put the logic in OrderUpdater","user":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"body":"This sets up tax updates in `OrderUpdater` so that all tax updates for an order\r\nhappen at the same time.\r\n\r\nWith `ItemAdjustments` we updated items in this order:\r\n\r\n    - item 1\r\n      - update promotions\r\n      - update taxes\r\n      - update cancellations\r\n      - update totals\r\n    - item 2\r\n      - update promotions\r\n      - update taxes\r\n      - update cancellations\r\n      - update totals\r\n\r\nHowever, we need to invoke tax calculation on the order as a whole\r\n(even though the results will be calculated & stored at the line/shipment level) in\r\norder to provide a good extension point for external tax services. See #1252.\r\nThat means we need to do this:\r\n\r\n    - update promotions\r\n      - item 1\r\n      - item 2\r\n    - update taxes\r\n      - item 1\r\n      - item 2\r\n    - update cancellations\r\n      - item 1\r\n      - item 2\r\n    - update totals\r\n      - item 1\r\n      - item 2\r\n\r\nI couldn't think of a reasonable way to refactor ItemAdjustments to be\r\nable to do the above, without breaking backward compatibility in a\r\nsignificant way. And if we're going to break backward compatibility\r\nthen moving this logic into OrderUpdater seemed like a better change\r\nto me as a first step.\r\n\r\nOnce we have this in place we can start working on providing an\r\nextension point in the \"update taxes\" step where external tax services\r\ncan be plugged in.","created_at":"2016-09-22T20:08:24Z","updated_at":"2016-09-22T20:08:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e933ec3d09b90ae32357f026c15aed2d14992776","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/solidusio/solidus/pulls/1466/commits","review_comments_url":"https://api.github.com/repos/solidusio/solidus/pulls/1466/comments","review_comment_url":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solidusio/solidus/issues/1466/comments","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/a2d800096a6dcb8e33609fbba11c13892ba27034","head":{"label":"jordan-brough:split-up-item-adjustments","ref":"split-up-item-adjustments","sha":"a2d800096a6dcb8e33609fbba11c13892ba27034","user":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"repo":{"id":37918071,"name":"solidus","full_name":"jordan-brough/solidus","owner":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jordan-brough/solidus","description":"Solidus e-commerce system","fork":true,"url":"https://api.github.com/repos/jordan-brough/solidus","forks_url":"https://api.github.com/repos/jordan-brough/solidus/forks","keys_url":"https://api.github.com/repos/jordan-brough/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jordan-brough/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jordan-brough/solidus/teams","hooks_url":"https://api.github.com/repos/jordan-brough/solidus/hooks","issue_events_url":"https://api.github.com/repos/jordan-brough/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/jordan-brough/solidus/events","assignees_url":"https://api.github.com/repos/jordan-brough/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/jordan-brough/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/jordan-brough/solidus/tags","blobs_url":"https://api.github.com/repos/jordan-brough/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jordan-brough/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jordan-brough/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/jordan-brough/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jordan-brough/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/jordan-brough/solidus/languages","stargazers_url":"https://api.github.com/repos/jordan-brough/solidus/stargazers","contributors_url":"https://api.github.com/repos/jordan-brough/solidus/contributors","subscribers_url":"https://api.github.com/repos/jordan-brough/solidus/subscribers","subscription_url":"https://api.github.com/repos/jordan-brough/solidus/subscription","commits_url":"https://api.github.com/repos/jordan-brough/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/jordan-brough/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/jordan-brough/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/jordan-brough/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/jordan-brough/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/jordan-brough/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jordan-brough/solidus/merges","archive_url":"https://api.github.com/repos/jordan-brough/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jordan-brough/solidus/downloads","issues_url":"https://api.github.com/repos/jordan-brough/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/jordan-brough/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/jordan-brough/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/jordan-brough/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jordan-brough/solidus/labels{/name}","releases_url":"https://api.github.com/repos/jordan-brough/solidus/releases{/id}","deployments_url":"https://api.github.com/repos/jordan-brough/solidus/deployments","created_at":"2015-06-23T12:36:58Z","updated_at":"2016-08-16T17:39:55Z","pushed_at":"2016-09-22T19:47:08Z","git_url":"git://github.com/jordan-brough/solidus.git","ssh_url":"git@github.com:jordan-brough/solidus.git","clone_url":"https://github.com/jordan-brough/solidus.git","svn_url":"https://github.com/jordan-brough/solidus","homepage":"","size":68693,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"master"}},"base":{"label":"solidusio:master","ref":"master","sha":"ae0ea34fc45429d746e7f0689db05b605f815dc9","user":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"repo":{"id":30985840,"name":"solidus","full_name":"solidusio/solidus","owner":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solidusio/solidus","description":"Solidus, Rails eCommerce System","fork":false,"url":"https://api.github.com/repos/solidusio/solidus","forks_url":"https://api.github.com/repos/solidusio/solidus/forks","keys_url":"https://api.github.com/repos/solidusio/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solidusio/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solidusio/solidus/teams","hooks_url":"https://api.github.com/repos/solidusio/solidus/hooks","issue_events_url":"https://api.github.com/repos/solidusio/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/solidusio/solidus/events","assignees_url":"https://api.github.com/repos/solidusio/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/solidusio/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/solidusio/solidus/tags","blobs_url":"https://api.github.com/repos/solidusio/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solidusio/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solidusio/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/solidusio/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/solidusio/solidus/languages","stargazers_url":"https://api.github.com/repos/solidusio/solidus/stargazers","contributors_url":"https://api.github.com/repos/solidusio/solidus/contributors","subscribers_url":"https://api.github.com/repos/solidusio/solidus/subscribers","subscription_url":"https://api.github.com/repos/solidusio/solidus/subscription","commits_url":"https://api.github.com/repos/solidusio/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/solidusio/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/solidusio/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/solidusio/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/solidusio/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/solidusio/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solidusio/solidus/merges","archive_url":"https://api.github.com/repos/solidusio/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solidusio/solidus/downloads","issues_url":"https://api.github.com/repos/solidusio/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/solidusio/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/solidusio/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/solidusio/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solidusio/solidus/labels{/name}","releases_url":"https://api.github.com/repos/solidusio/solidus/releases{/id}","deployments_url":"https://api.github.com/repos/solidusio/solidus/deployments","created_at":"2015-02-18T20:41:58Z","updated_at":"2016-09-22T20:02:05Z","pushed_at":"2016-09-22T20:08:24Z","git_url":"git://github.com/solidusio/solidus.git","ssh_url":"git@github.com:solidusio/solidus.git","clone_url":"https://github.com/solidusio/solidus.git","svn_url":"https://github.com/solidusio/solidus","homepage":"https://solidus.io/","size":70939,"stargazers_count":1082,"watchers_count":1082,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":336,"mirror_url":null,"open_issues_count":178,"forks":336,"open_issues":178,"watchers":1082,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1466"},"html":{"href":"https://github.com/solidusio/solidus/pull/1466"},"issue":{"href":"https://api.github.com/repos/solidusio/solidus/issues/1466"},"comments":{"href":"https://api.github.com/repos/solidusio/solidus/issues/1466/comments"},"review_comments":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1466/comments"},"review_comment":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/1466/commits"},"statuses":{"href":"https://api.github.com/repos/solidusio/solidus/statuses/a2d800096a6dcb8e33609fbba11c13892ba27034"}}}}
{"actor":{"display_login":"houndci-bot"}}