{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/comments/38960264","id":38960264,"diff_hunk":"@@ -0,0 +1,111 @@\n+# -*- coding: utf-8 -*-\n+##############################################################################\n+#\n+#    OpenERP, Open Source Management Solution\n+#    This module copyright (C) 2013-2015 Therp BV (<http://therp.nl>).\n+#\n+#    @autors: Stefan Rijnhart, Ronald Portier\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+\n+from lxml import etree\n+from openerp import models, api, exceptions, _\n+from openerp.tools import ormcache\n+\n+\n+class ResPartner(models.Model):\n+    _inherit = 'res.partner'\n+\n+    @ormcache(skiparg=2)\n+    def get_provider_obj(self):\n+        self._cr.execute(\"\"\"\n+                SELECT value FROM ir_config_parameter\n+                WHERE key = %s\"\"\", ('l10n_nl_postcodeapi.apikey',))\n+        row = self._cr.fetchone()\n+        if row and row[0] != 'Your API key' and row[0].strip():\n+            from pyPostcode import Api\n+            provider = Api(row[0].strip())\n+            test = provider.getaddress('1053NJ', '334T')\n+            if not test or not test._data:\n+                raise exceptions.Warning(\n+                    _('Error'),\n+                    _('Could not verify the connection with the address '\n+                      'lookup service (if you want to get rid of this '\n+                      'message, please rename or delete the system parameter '\n+                      '\\'l10n_nl_postcodeapi.apikey\\').'))\n+            return provider\n+        return False\n+\n+    @ormcache(skiparg=1)\n+    def get_province(self, province):\n+        \"\"\" Return the province or empty recordset \"\"\"\n+        if not province:\n+            return self.env['res.country.state']\n+        res = self.env['res.country.state'].search([('name', '=', province)])\n+        return res[0] if res else res\n+\n+    @api.onchange('zip', 'street_number', 'country_id')\n+    def on_change_zip_street_number(self):\n+        \"\"\"\n+        Normalize the zip code, check on the partner's country and\n+        if all is well, request address autocompletion data.\n+\n+        NB. postal_code is named 'zip' in OpenERP, but is this a reserved\n+        keyword in Python\n+        \"\"\"\n+        postal_code = self.zip and self.zip.replace(' ', '')\n+        if (not (postal_code and self.street_number)\n+                or (self.country_id and\n+                    self.country_id != self.env.ref('base.nl'))):\n+            return {}\n+\n+        provider_obj = self.get_provider_obj()\n+        if not provider_obj:\n+            return {}\n+        pc_info = provider_obj.getaddress(postal_code, self.street_number)\n+        if not pc_info or not pc_info._data:\n+            return {}\n+        self.street_name = pc_info._data['street']\n+        self.city = pc_info._data['town']\n+        self.state_id = self.get_province(pc_info._province)\n+\n+    @api.model\n+    def fields_view_get(\n+            self, view_id=None, view_type='form',\n+            toolbar=False, submenu=False):\n+        \"\"\" Address fields can be all over the place due to module\n+        interaction. For improved compatibility add the onchange method here,\n+        not in a view.\"\"\"\n+        res = super(ResPartner, self).fields_view_get(\n+            view_id=view_id, view_type=view_type,\n+            toolbar=toolbar, submenu=submenu)\n+        if view_type != 'form':\n+            return res\n+\n+        def inject_onchange(arch):\n+            arch = etree.fromstring(arch)\n+            for field in ['zip', 'street_number']:","path":"l10n_nl_postcodeapi/models/res_partner.py","position":100,"original_position":100,"commit_id":"d8c053320c9c1cb6d7ba881731931fddbcdd47b4","original_commit_id":"d8c053320c9c1cb6d7ba881731931fddbcdd47b4","user":{"login":"StefanRijnhart","id":1033124,"avatar_url":"https://avatars.githubusercontent.com/u/1033124?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanRijnhart","html_url":"https://github.com/StefanRijnhart","followers_url":"https://api.github.com/users/StefanRijnhart/followers","following_url":"https://api.github.com/users/StefanRijnhart/following{/other_user}","gists_url":"https://api.github.com/users/StefanRijnhart/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanRijnhart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanRijnhart/subscriptions","organizations_url":"https://api.github.com/users/StefanRijnhart/orgs","repos_url":"https://api.github.com/users/StefanRijnhart/repos","events_url":"https://api.github.com/users/StefanRijnhart/events{/privacy}","received_events_url":"https://api.github.com/users/StefanRijnhart/received_events","type":"User","site_admin":false},"body":"But you could be right, it might be wise to add country_id here.","created_at":"2015-09-08T18:14:15Z","updated_at":"2015-09-08T18:14:15Z","html_url":"https://github.com/OCA/l10n-netherlands/pull/19#discussion_r38960264","pull_request_url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19","_links":{"self":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/comments/38960264"},"html":{"href":"https://github.com/OCA/l10n-netherlands/pull/19#discussion_r38960264"},"pull_request":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19","id":42680105,"html_url":"https://github.com/OCA/l10n-netherlands/pull/19","diff_url":"https://github.com/OCA/l10n-netherlands/pull/19.diff","patch_url":"https://github.com/OCA/l10n-netherlands/pull/19.patch","issue_url":"https://api.github.com/repos/OCA/l10n-netherlands/issues/19","number":19,"state":"open","locked":false,"title":"8.0 l10n_nl_postcodeapi","user":{"login":"StefanRijnhart","id":1033124,"avatar_url":"https://avatars.githubusercontent.com/u/1033124?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanRijnhart","html_url":"https://github.com/StefanRijnhart","followers_url":"https://api.github.com/users/StefanRijnhart/followers","following_url":"https://api.github.com/users/StefanRijnhart/following{/other_user}","gists_url":"https://api.github.com/users/StefanRijnhart/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanRijnhart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanRijnhart/subscriptions","organizations_url":"https://api.github.com/users/StefanRijnhart/orgs","repos_url":"https://api.github.com/users/StefanRijnhart/repos","events_url":"https://api.github.com/users/StefanRijnhart/events{/privacy}","received_events_url":"https://api.github.com/users/StefanRijnhart/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-18T09:53:28Z","updated_at":"2015-09-08T18:14:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e206fd0bd49442dc3e6b24597f9e0e99d114d525","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19/commits","review_comments_url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19/comments","review_comment_url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/l10n-netherlands/issues/19/comments","statuses_url":"https://api.github.com/repos/OCA/l10n-netherlands/statuses/d8c053320c9c1cb6d7ba881731931fddbcdd47b4","head":{"label":"StefanRijnhart:8.0-l10n_nl_postcodeapi","ref":"8.0-l10n_nl_postcodeapi","sha":"d8c053320c9c1cb6d7ba881731931fddbcdd47b4","user":{"login":"StefanRijnhart","id":1033124,"avatar_url":"https://avatars.githubusercontent.com/u/1033124?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanRijnhart","html_url":"https://github.com/StefanRijnhart","followers_url":"https://api.github.com/users/StefanRijnhart/followers","following_url":"https://api.github.com/users/StefanRijnhart/following{/other_user}","gists_url":"https://api.github.com/users/StefanRijnhart/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanRijnhart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanRijnhart/subscriptions","organizations_url":"https://api.github.com/users/StefanRijnhart/orgs","repos_url":"https://api.github.com/users/StefanRijnhart/repos","events_url":"https://api.github.com/users/StefanRijnhart/events{/privacy}","received_events_url":"https://api.github.com/users/StefanRijnhart/received_events","type":"User","site_admin":false},"repo":{"id":26432277,"name":"l10n-netherlands","full_name":"StefanRijnhart/l10n-netherlands","owner":{"login":"StefanRijnhart","id":1033124,"avatar_url":"https://avatars.githubusercontent.com/u/1033124?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanRijnhart","html_url":"https://github.com/StefanRijnhart","followers_url":"https://api.github.com/users/StefanRijnhart/followers","following_url":"https://api.github.com/users/StefanRijnhart/following{/other_user}","gists_url":"https://api.github.com/users/StefanRijnhart/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanRijnhart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanRijnhart/subscriptions","organizations_url":"https://api.github.com/users/StefanRijnhart/orgs","repos_url":"https://api.github.com/users/StefanRijnhart/repos","events_url":"https://api.github.com/users/StefanRijnhart/events{/privacy}","received_events_url":"https://api.github.com/users/StefanRijnhart/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/StefanRijnhart/l10n-netherlands","description":"Odoo Dutch Localization","fork":true,"url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands","forks_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/forks","keys_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/keys{/key_id}","collaborators_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/teams","hooks_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/hooks","issue_events_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/issues/events{/number}","events_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/events","assignees_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/assignees{/user}","branches_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/branches{/branch}","tags_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/tags","blobs_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/git/refs{/sha}","trees_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/git/trees{/sha}","statuses_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/statuses/{sha}","languages_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/languages","stargazers_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/stargazers","contributors_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/contributors","subscribers_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/subscribers","subscription_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/subscription","commits_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/commits{/sha}","git_commits_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/git/commits{/sha}","comments_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/comments{/number}","issue_comment_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/issues/comments{/number}","contents_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/contents/{+path}","compare_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/compare/{base}...{head}","merges_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/merges","archive_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/downloads","issues_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/issues{/number}","pulls_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/pulls{/number}","milestones_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/milestones{/number}","notifications_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/labels{/name}","releases_url":"https://api.github.com/repos/StefanRijnhart/l10n-netherlands/releases{/id}","created_at":"2014-11-10T10:42:51Z","updated_at":"2014-11-05T08:27:38Z","pushed_at":"2015-09-02T13:25:37Z","git_url":"git://github.com/StefanRijnhart/l10n-netherlands.git","ssh_url":"git@github.com:StefanRijnhart/l10n-netherlands.git","clone_url":"https://github.com/StefanRijnhart/l10n-netherlands.git","svn_url":"https://github.com/StefanRijnhart/l10n-netherlands","homepage":"","size":193,"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:8.0","ref":"8.0","sha":"246fafcf7847f090cd9c80f769bd6de5e7cfa4ab","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":26018902,"name":"l10n-netherlands","full_name":"OCA/l10n-netherlands","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/l10n-netherlands","description":"Odoo Dutch Localization","fork":false,"url":"https://api.github.com/repos/OCA/l10n-netherlands","forks_url":"https://api.github.com/repos/OCA/l10n-netherlands/forks","keys_url":"https://api.github.com/repos/OCA/l10n-netherlands/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/l10n-netherlands/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/l10n-netherlands/teams","hooks_url":"https://api.github.com/repos/OCA/l10n-netherlands/hooks","issue_events_url":"https://api.github.com/repos/OCA/l10n-netherlands/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/l10n-netherlands/events","assignees_url":"https://api.github.com/repos/OCA/l10n-netherlands/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/l10n-netherlands/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/l10n-netherlands/tags","blobs_url":"https://api.github.com/repos/OCA/l10n-netherlands/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/l10n-netherlands/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/l10n-netherlands/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/l10n-netherlands/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/l10n-netherlands/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/l10n-netherlands/languages","stargazers_url":"https://api.github.com/repos/OCA/l10n-netherlands/stargazers","contributors_url":"https://api.github.com/repos/OCA/l10n-netherlands/contributors","subscribers_url":"https://api.github.com/repos/OCA/l10n-netherlands/subscribers","subscription_url":"https://api.github.com/repos/OCA/l10n-netherlands/subscription","commits_url":"https://api.github.com/repos/OCA/l10n-netherlands/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/l10n-netherlands/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/l10n-netherlands/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/l10n-netherlands/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/l10n-netherlands/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/l10n-netherlands/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/l10n-netherlands/merges","archive_url":"https://api.github.com/repos/OCA/l10n-netherlands/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/l10n-netherlands/downloads","issues_url":"https://api.github.com/repos/OCA/l10n-netherlands/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/l10n-netherlands/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/l10n-netherlands/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/l10n-netherlands/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/l10n-netherlands/labels{/name}","releases_url":"https://api.github.com/repos/OCA/l10n-netherlands/releases{/id}","created_at":"2014-10-31T14:15:15Z","updated_at":"2015-08-27T13:01:04Z","pushed_at":"2015-09-02T13:25:37Z","git_url":"git://github.com/OCA/l10n-netherlands.git","ssh_url":"git@github.com:OCA/l10n-netherlands.git","clone_url":"https://github.com/OCA/l10n-netherlands.git","svn_url":"https://github.com/OCA/l10n-netherlands","homepage":"","size":642,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":7,"forks":12,"open_issues":7,"watchers":5,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19"},"html":{"href":"https://github.com/OCA/l10n-netherlands/pull/19"},"issue":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/issues/19"},"comments":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/issues/19/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/pulls/19/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/l10n-netherlands/statuses/d8c053320c9c1cb6d7ba881731931fddbcdd47b4"}}}}