{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/account-payment/pulls/comments/52426358","id":52426358,"diff_hunk":"@@ -0,0 +1,121 @@\n+# -*- coding: utf-8 -*-\n+# © 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza\n+# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html\n+\n+from openupgradelib import openupgrade\n+from openerp import pooler, SUPERUSER_ID\n+\n+column_renames = {\n+    'payment_mode': [\n+        ('type', None),\n+    ],\n+}\n+\n+\n+def migrate_payment_types(pool, cr, uid):\n+    # Add manually payment needed columns\n+    cr.execute('ALTER TABLE account_invoice ADD COLUMN payment_mode_id int')\n+    cr.execute('ALTER TABLE payment_mode ADD COLUMN active bool')\n+    # Remove some constraints\n+    cr.execute('ALTER TABLE payment_mode ALTER journal DROP NOT NULL')\n+    cr.execute('ALTER TABLE payment_mode ALTER bank_id DROP NOT NULL')\n+    cr.execute('ALTER TABLE bank_type_payment_type_rel DROP CONSTRAINT '\n+               'bank_type_payment_type_rel_pay_type_id_fkey')\n+    # Rename many2many table\n+    cr.execute('ALTER TABLE bank_type_payment_type_rel RENAME TO '\n+               'bank_type_payment_type_rel_old')\n+    cr.execute('ALTER INDEX bank_type_payment_type_rel_pay_type_id_index '\n+               'RENAME TO bank_type_payment_type_rel_pay_type_id_index_old')\n+    cr.execute('ALTER INDEX bank_type_payment_type_rel_bank_type_id_index '\n+               'RENAME TO bank_type_payment_type_rel_bank_type_id_index_old')\n+    # Switch payment types by payment modes\n+    cr.execute(\"SELECT id, name, active, company_id FROM payment_type\")\n+    payment_types = cr.fetchall()\n+    for payment_type in payment_types:\n+        if payment_type[3]:\n+            applicable_companies_ids = [payment_type[3]]\n+        else:\n+            cr.execute(\"SELECT id FROM res_company\")\n+            applicable_companies_ids = [x[0] for x in cr.fetchall()]\n+        for company_id in applicable_companies_ids:\n+            # Update payment modes\n+            cr.execute(\"\"\"SELECT id, name FROM payment_mode\n+                          WHERE type=%s\"\"\", (payment_type[0], ))\n+            payment_modes = cr.fetchall()\n+            for payment_mode in payment_modes:\n+                openupgrade.logged_query(\n+                    cr,\n+                    \"\"\"\n+                    UPDATE payment_mode\n+                    SET name=%s, active=%s\n+                    WHERE id=%s\"\"\", (\n+                        \"%s (%s)\" % (payment_type[1], payment_mode[1]),\n+                        payment_type[2], payment_mode[0])\n+                )\n+            # Create at least one payment mode for each payment type\n+            if not payment_modes:\n+                # Search for a journal\n+                cr.execute(\"\"\"SELECT id FROM account_journal\n+                              WHERE active=TRUE\n+                              AND company_id=%s\n+                              AND type='bank'\n+                              LIMIT 1\"\"\",\n+                           (company_id, ))\n+                row = cr.fetchone()\n+                journal_id = row and row[0] or None\n+                # Search for a bank account\n+                cr.execute(\"\"\"SELECT rpb.id FROM res_partner_bank rpb\n+                              INNER JOIN res_partner rp ON rpb.partner_id=rp.id\n+                              INNER JOIN res_company rc ON rc.partner_id=rp.id\n+                              WHERE rc.id=%s\n+                              LIMIT 1\"\"\", (company_id, ))\n+                row = cr.fetchone()\n+                bank_id = row and row[0] or None\n+                # Create the payment mode\n+                openupgrade.logged_query(\n+                    cr,\n+                    \"\"\"\n+                    INSERT INTO payment_mode\n+                    (%s, name, active, journal, bank_id, company_id)\n+                    VALUES (%%s, %%s, %%s, %%s, %%s)\n+                    RETURNING id;\"\"\" % openupgrade.get_legacy_name('type'),\n+                    (payment_type[0], payment_type[1], payment_type[2],\n+                     journal_id, bank_id, company_id))","path":"account_payment_extension/migrations/8.0.1.0.0/pre-migration.py","position":83,"original_position":83,"commit_id":"ff4fbf3cb3958f8a2b0cc2c25024563ce54d27b8","original_commit_id":"ff4fbf3cb3958f8a2b0cc2c25024563ce54d27b8","user":{"login":"cubells","id":4386443,"avatar_url":"https://avatars.githubusercontent.com/u/4386443?v=3","gravatar_id":"","url":"https://api.github.com/users/cubells","html_url":"https://github.com/cubells","followers_url":"https://api.github.com/users/cubells/followers","following_url":"https://api.github.com/users/cubells/following{/other_user}","gists_url":"https://api.github.com/users/cubells/gists{/gist_id}","starred_url":"https://api.github.com/users/cubells/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cubells/subscriptions","organizations_url":"https://api.github.com/users/cubells/orgs","repos_url":"https://api.github.com/users/cubells/repos","events_url":"https://api.github.com/users/cubells/events{/privacy}","received_events_url":"https://api.github.com/users/cubells/received_events","type":"User","site_admin":false},"body":"This pull works like a charm but I've have to change this insert code in order to be able to run it. For me works this:\r\n\r\n```\r\n                # Create the payment mode\r\n                cr.execute(\r\n                    \"\"\"\r\n                    INSERT INTO payment_mode\r\n                    (id, name, active, journal, bank_id, company_id)\r\n                    VALUES (%s, '%s', %s, %s, %s, %s)\r\n                    RETURNING id;\"\"\" %\r\n                    (payment_type[0], payment_type[1], payment_type[2],\r\n                     journal_id, bank_id, company_id,))\r\n```","created_at":"2016-02-10T08:19:24Z","updated_at":"2016-02-10T08:19:24Z","html_url":"https://github.com/OCA/account-payment/pull/35#discussion_r52426358","pull_request_url":"https://api.github.com/repos/OCA/account-payment/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/OCA/account-payment/pulls/comments/52426358"},"html":{"href":"https://github.com/OCA/account-payment/pull/35#discussion_r52426358"},"pull_request":{"href":"https://api.github.com/repos/OCA/account-payment/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/account-payment/pulls/35","id":35518423,"html_url":"https://github.com/OCA/account-payment/pull/35","diff_url":"https://github.com/OCA/account-payment/pull/35.diff","patch_url":"https://github.com/OCA/account-payment/pull/35.patch","issue_url":"https://api.github.com/repos/OCA/account-payment/issues/35","number":35,"state":"open","locked":false,"title":"[ADD] account_payment_extension: Migration scripts to bank-payment modules","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","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":"Migration scripts for account_payment_extension v7 set of modules\r\n=================================================================\r\n\r\nThis module includes the needed migration script for making a smooth transition\r\nfrom v7 _account_payment_extension_ module to the set of v8 bank-payment\r\nmodules.\r\n\r\nThis module doesn't provide any functionality at user level.\r\n\r\nInstallation\r\n============\r\n\r\nYou need OpenUpgrade for using these scripts. Put this module in a path\r\nincluded on OpenUpgrade addons path. You need also to have accesible the\r\nrepository bank-payment from https://github.com/OCA/bank-payment.\r\n\r\nStart the OpenUpgrade migration and the conversion will be automatically done,\r\nand this module will be automatically uninstall.\r\n","created_at":"2015-05-15T14:36:14Z","updated_at":"2016-02-10T08:19:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"984f0968404799a7a2abd21357e38c971a871ca0","assignee":null,"milestone":{"url":"https://api.github.com/repos/OCA/account-payment/milestones/3","html_url":"https://github.com/OCA/account-payment/milestones/8.0","labels_url":"https://api.github.com/repos/OCA/account-payment/milestones/3/labels","id":985603,"number":3,"title":"8.0","description":"","creator":{"login":"max3903","id":939952,"avatar_url":"https://avatars.githubusercontent.com/u/939952?v=3","gravatar_id":"","url":"https://api.github.com/users/max3903","html_url":"https://github.com/max3903","followers_url":"https://api.github.com/users/max3903/followers","following_url":"https://api.github.com/users/max3903/following{/other_user}","gists_url":"https://api.github.com/users/max3903/gists{/gist_id}","starred_url":"https://api.github.com/users/max3903/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/max3903/subscriptions","organizations_url":"https://api.github.com/users/max3903/orgs","repos_url":"https://api.github.com/users/max3903/repos","events_url":"https://api.github.com/users/max3903/events{/privacy}","received_events_url":"https://api.github.com/users/max3903/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":2,"state":"open","created_at":"2015-02-19T02:01:43Z","updated_at":"2015-09-18T14:49:28Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/OCA/account-payment/pulls/35/commits","review_comments_url":"https://api.github.com/repos/OCA/account-payment/pulls/35/comments","review_comment_url":"https://api.github.com/repos/OCA/account-payment/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/account-payment/issues/35/comments","statuses_url":"https://api.github.com/repos/OCA/account-payment/statuses/ff4fbf3cb3958f8a2b0cc2c25024563ce54d27b8","head":{"label":"pedrobaeza:8.0-account_payment_extension-migration","ref":"8.0-account_payment_extension-migration","sha":"ff4fbf3cb3958f8a2b0cc2c25024563ce54d27b8","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","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},"repo":{"id":21419007,"name":"account-payment","full_name":"pedrobaeza/account-payment","owner":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","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},"private":false,"html_url":"https://github.com/pedrobaeza/account-payment","description":"","fork":true,"url":"https://api.github.com/repos/pedrobaeza/account-payment","forks_url":"https://api.github.com/repos/pedrobaeza/account-payment/forks","keys_url":"https://api.github.com/repos/pedrobaeza/account-payment/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pedrobaeza/account-payment/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pedrobaeza/account-payment/teams","hooks_url":"https://api.github.com/repos/pedrobaeza/account-payment/hooks","issue_events_url":"https://api.github.com/repos/pedrobaeza/account-payment/issues/events{/number}","events_url":"https://api.github.com/repos/pedrobaeza/account-payment/events","assignees_url":"https://api.github.com/repos/pedrobaeza/account-payment/assignees{/user}","branches_url":"https://api.github.com/repos/pedrobaeza/account-payment/branches{/branch}","tags_url":"https://api.github.com/repos/pedrobaeza/account-payment/tags","blobs_url":"https://api.github.com/repos/pedrobaeza/account-payment/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pedrobaeza/account-payment/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pedrobaeza/account-payment/git/refs{/sha}","trees_url":"https://api.github.com/repos/pedrobaeza/account-payment/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pedrobaeza/account-payment/statuses/{sha}","languages_url":"https://api.github.com/repos/pedrobaeza/account-payment/languages","stargazers_url":"https://api.github.com/repos/pedrobaeza/account-payment/stargazers","contributors_url":"https://api.github.com/repos/pedrobaeza/account-payment/contributors","subscribers_url":"https://api.github.com/repos/pedrobaeza/account-payment/subscribers","subscription_url":"https://api.github.com/repos/pedrobaeza/account-payment/subscription","commits_url":"https://api.github.com/repos/pedrobaeza/account-payment/commits{/sha}","git_commits_url":"https://api.github.com/repos/pedrobaeza/account-payment/git/commits{/sha}","comments_url":"https://api.github.com/repos/pedrobaeza/account-payment/comments{/number}","issue_comment_url":"https://api.github.com/repos/pedrobaeza/account-payment/issues/comments{/number}","contents_url":"https://api.github.com/repos/pedrobaeza/account-payment/contents/{+path}","compare_url":"https://api.github.com/repos/pedrobaeza/account-payment/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pedrobaeza/account-payment/merges","archive_url":"https://api.github.com/repos/pedrobaeza/account-payment/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pedrobaeza/account-payment/downloads","issues_url":"https://api.github.com/repos/pedrobaeza/account-payment/issues{/number}","pulls_url":"https://api.github.com/repos/pedrobaeza/account-payment/pulls{/number}","milestones_url":"https://api.github.com/repos/pedrobaeza/account-payment/milestones{/number}","notifications_url":"https://api.github.com/repos/pedrobaeza/account-payment/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pedrobaeza/account-payment/labels{/name}","releases_url":"https://api.github.com/repos/pedrobaeza/account-payment/releases{/id}","deployments_url":"https://api.github.com/repos/pedrobaeza/account-payment/deployments","created_at":"2014-07-02T09:38:50Z","updated_at":"2014-06-25T14:25:30Z","pushed_at":"2016-01-27T13:07:17Z","git_url":"git://github.com/pedrobaeza/account-payment.git","ssh_url":"git@github.com:pedrobaeza/account-payment.git","clone_url":"https://github.com/pedrobaeza/account-payment.git","svn_url":"https://github.com/pedrobaeza/account-payment","homepage":null,"size":1772,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"OCA:8.0","ref":"8.0","sha":"c95dbe5f0a24e55ca8c459136dde0c3ac3ab10e9","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":20921772,"name":"account-payment","full_name":"OCA/account-payment","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/account-payment","description":"","fork":false,"url":"https://api.github.com/repos/OCA/account-payment","forks_url":"https://api.github.com/repos/OCA/account-payment/forks","keys_url":"https://api.github.com/repos/OCA/account-payment/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/account-payment/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/account-payment/teams","hooks_url":"https://api.github.com/repos/OCA/account-payment/hooks","issue_events_url":"https://api.github.com/repos/OCA/account-payment/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/account-payment/events","assignees_url":"https://api.github.com/repos/OCA/account-payment/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/account-payment/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/account-payment/tags","blobs_url":"https://api.github.com/repos/OCA/account-payment/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/account-payment/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/account-payment/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/account-payment/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/account-payment/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/account-payment/languages","stargazers_url":"https://api.github.com/repos/OCA/account-payment/stargazers","contributors_url":"https://api.github.com/repos/OCA/account-payment/contributors","subscribers_url":"https://api.github.com/repos/OCA/account-payment/subscribers","subscription_url":"https://api.github.com/repos/OCA/account-payment/subscription","commits_url":"https://api.github.com/repos/OCA/account-payment/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/account-payment/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/account-payment/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/account-payment/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/account-payment/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/account-payment/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/account-payment/merges","archive_url":"https://api.github.com/repos/OCA/account-payment/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/account-payment/downloads","issues_url":"https://api.github.com/repos/OCA/account-payment/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/account-payment/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/account-payment/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/account-payment/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/account-payment/labels{/name}","releases_url":"https://api.github.com/repos/OCA/account-payment/releases{/id}","deployments_url":"https://api.github.com/repos/OCA/account-payment/deployments","created_at":"2014-06-17T12:05:42Z","updated_at":"2016-02-03T05:36:55Z","pushed_at":"2016-02-09T21:39:07Z","git_url":"git://github.com/OCA/account-payment.git","ssh_url":"git@github.com:OCA/account-payment.git","clone_url":"https://github.com/OCA/account-payment.git","svn_url":"https://github.com/OCA/account-payment","homepage":null,"size":2393,"stargazers_count":14,"watchers_count":14,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":18,"forks":52,"open_issues":18,"watchers":14,"default_branch":"9.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/account-payment/pulls/35"},"html":{"href":"https://github.com/OCA/account-payment/pull/35"},"issue":{"href":"https://api.github.com/repos/OCA/account-payment/issues/35"},"comments":{"href":"https://api.github.com/repos/OCA/account-payment/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/account-payment/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/account-payment/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/account-payment/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/account-payment/statuses/ff4fbf3cb3958f8a2b0cc2c25024563ce54d27b8"}}}}