{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/36520682","id":36520682,"diff_hunk":"@@ -196,123 +189,291 @@ def reducer(self, _key, values):\n                     value[10] = ''\n \n                 record = OrderItemRecord(*value)\n-\n                 orderitems.append(record)\n             else:\n                 if value[6] == '\\\\N':\n                     value[6] = None\n                 transactions.append(TransactionRecord(*value))\n+        return orderitems, transactions\n+\n+    def _get_status_for_orders_without_transactions(self, orderitems):\n+        \"\"\"\n+        Return a status for each orderitem when there are no transactions.\n+\n+        Orders without transactions happens when an order is begun but\n+        the user changes their mind.  Also included are registrations\n+        that have no cost, so having no transactions is actually a\n+        reasonable state.\n+\n+        More are due to a difference in the timing of the orders and\n+        the transaction extraction.  At present, the orders are\n+        pulled at whatever time the task is run, and they are dumped.\n+        For transactions, the granularity is daily: we only have up\n+        through yesterday's.  So there may be orders from today that\n+        don't yet have transactions downloaded.\n+\n+        There are also some professional-ed entries that have\n+        transactions in a different account.\n+\n+        \"\"\"\n+        for orderitem in orderitems:\n+            order_status = 'ERROR_ORDER_NOT_BALANCED'\n+            orderitem_status = 'ERROR_NO_TRANSACTION'\n+            transaction_status = 'NO_TRANSACTION'\n+            if self._orderitem_is_professional_ed(orderitem):\n+                orderitem_status = 'NO_TRANS_PROFESSIONAL'\n+            elif Decimal(orderitem.line_item_unit_price) == 0.0:\n+                order_status = 'ORDER_BALANCED'\n+                orderitem_status = 'NO_COST'\n+            orderitem_status = self._add_orderitem_status_to_code(orderitem, orderitem_status)\n+            code = (order_status, orderitem_status, transaction_status)\n+            yield code, orderitem\n+\n+    def _get_status_for_transactions_without_orderitems(self, transactions, trans_balance):\n+        \"\"\"\n+        Return a status for each transaction when there are no orderitems.\n+\n+        This is likely when the transaction pull is newer than the\n+        order pull, or if a shoppingcart basket was charged that was\n+        not marked as a purchased order.  In the latter case, if the\n+        charge was later refunded and the current balance is zero,\n+        then no further action is needed.  Otherwise either the order\n+        needs to be updated (to reflect that they did actually receive\n+        what they ordered), or the balance should be refunded (because\n+        they never received what they were charged for).\n+\n+        \"\"\"\n+        order_code = 'NO_ORDER_ZERO_BALANCE' if trans_balance == 0 else 'ERROR_NO_ORDER_NONZERO_BALANCE'\n+        for transaction in transactions:\n+            trans_code = 'PURCHASE_SOMETHING' if Decimal(transaction.amount) > 0.0 else 'REFUND_SOMETHING'","path":"edx/analytics/tasks/reports/reconcile.py","position":146,"original_position":146,"commit_id":"001c78c1156945befc15340c7146ef404683999b","original_commit_id":"001c78c1156945befc15340c7146ef404683999b","user":{"login":"mulby","id":627177,"avatar_url":"https://avatars.githubusercontent.com/u/627177?v=3","gravatar_id":"","url":"https://api.github.com/users/mulby","html_url":"https://github.com/mulby","followers_url":"https://api.github.com/users/mulby/followers","following_url":"https://api.github.com/users/mulby/following{/other_user}","gists_url":"https://api.github.com/users/mulby/gists{/gist_id}","starred_url":"https://api.github.com/users/mulby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulby/subscriptions","organizations_url":"https://api.github.com/users/mulby/orgs","repos_url":"https://api.github.com/users/mulby/repos","events_url":"https://api.github.com/users/mulby/events{/privacy}","received_events_url":"https://api.github.com/users/mulby/received_events","type":"User","site_admin":false},"body":"Also, IMHO this should be `>= 0.0` since a $0 transaction is a purchase (you've given them something for free)\r\n\r\nSide note: not sure it's possible to have $0 purchases...","created_at":"2015-08-07T13:56:52Z","updated_at":"2015-08-07T13:56:52Z","html_url":"https://github.com/edx/edx-analytics-pipeline/pull/122#discussion_r36520682","pull_request_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/36520682"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/122#discussion_r36520682"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122","id":38342386,"html_url":"https://github.com/edx/edx-analytics-pipeline/pull/122","diff_url":"https://github.com/edx/edx-analytics-pipeline/pull/122.diff","patch_url":"https://github.com/edx/edx-analytics-pipeline/pull/122.patch","issue_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/122","number":122,"state":"open","locked":false,"title":"Handle multiple orderitems and transactions","user":{"login":"brianhw","id":2534095,"avatar_url":"https://avatars.githubusercontent.com/u/2534095?v=3","gravatar_id":"","url":"https://api.github.com/users/brianhw","html_url":"https://github.com/brianhw","followers_url":"https://api.github.com/users/brianhw/followers","following_url":"https://api.github.com/users/brianhw/following{/other_user}","gists_url":"https://api.github.com/users/brianhw/gists{/gist_id}","starred_url":"https://api.github.com/users/brianhw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianhw/subscriptions","organizations_url":"https://api.github.com/users/brianhw/orgs","repos_url":"https://api.github.com/users/brianhw/repos","events_url":"https://api.github.com/users/brianhw/events{/privacy}","received_events_url":"https://api.github.com/users/brianhw/received_events","type":"User","site_admin":false},"body":"Fully coded, but not yet fully validated.  Would like eyes on it, at your convenience.\r\n\r\n@mulby @jab5569 ","created_at":"2015-06-23T14:27:34Z","updated_at":"2015-08-07T13:56:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ca101d5dd3c68583f576803dda1ea95de841cfa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122/commits","review_comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122/comments","review_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/122/comments","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/001c78c1156945befc15340c7146ef404683999b","head":{"label":"edx:brian/reconcile-multi","ref":"brian/reconcile-multi","sha":"001c78c1156945befc15340c7146ef404683999b","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2015-08-06T14:38:09Z","pushed_at":"2015-08-06T21:54:13Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":5651,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":7,"forks":21,"open_issues":7,"watchers":9,"default_branch":"master"}},"base":{"label":"edx:financial-reporting","ref":"financial-reporting","sha":"37d5cf4d74f77dfe96c4309c07e59bb332beae76","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2015-08-06T14:38:09Z","pushed_at":"2015-08-06T21:54:13Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":5651,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":7,"forks":21,"open_issues":7,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/122"},"issue":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/122"},"comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/122/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/122/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/001c78c1156945befc15340c7146ef404683999b"}}}}