{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/58029360","id":58029360,"diff_hunk":"@@ -261,6 +263,112 @@ def _read_csv(self, record, options):\n             if any(x for x in row if x.strip())\n         )\n \n+    def _try_match_column(self, cr, uid, index, preview_values, fields, options):\n+        # If all values are empty in preview than can be any field\n+        if all([v == '' for v in preview_values]):\n+            return ['all']\n+        # If all values starts with __export__ this is probably an id\n+        if all(v.startswith('__export__') for v in preview_values):\n+            return ['id', 'many2many', 'many2one', 'one2many']\n+        # If all values can be cast to int type is either id, float or monetary\n+        # Exception: if we only have 1 and 0, it can also be a boolean\n+        try:\n+            field_type = ['id', 'integer', 'float', 'monetary', 'many2one', 'many2many', 'one2many']\n+            res = set(int(v) for v in preview_values)\n+            if set([0,1]).issuperset(res):\n+                field_type.append('boolean')\n+            return field_type\n+        except ValueError:\n+            pass\n+        # If all values are either True or False, type is boolean\n+        boolean = set([val.lower() in ('true','false','t','f','') for val in preview_values])\n+        if len(boolean) == 1 and True in boolean:\n+            return ['boolean']\n+        # If all values can be cast to float, type is either float or monetary\n+        try:\n+            thousand_separator = decimal_separator = False\n+            for val in preview_values:\n+                if val == '':\n+                    continue\n+                negative = False\n+                # Careful that some countries use () for negative so replace it by - sign\n+                if val.startswith('(') and val.endswith(')'):\n+                    val = val.replace('(','',1).replace(')','',1)\n+                    negative = True\n+                # We also might have the currency symbol left or right from the value\n+                val = self._remove_currency_symbol(cr, uid, val)\n+                if val:\n+                    val = '-'+val if negative else val\n+                    if options.get('float_thousand_separator', False) and options.get('float_decimal_separator', False):\n+                        val = val.replace(options.get('float_thousand_separator'), '').replace(options.get('float_decimal_separator'), '.')\n+                    # We are now sure that this is a float, but we still need to find the \n+                    # thousand and decimal separator\n+                    else:\n+                        if val.count('.') > 1:\n+                            options['float_thousand_separator'] = '.'\n+                            options['float_decimal_separator'] = ','\n+                        elif val.count(',') > 1:\n+                            options['float_thousand_separator'] = ','\n+                            options['float_decimal_separator'] = '.'\n+                        elif val.find('.') > val.find(','):\n+                            thousand_separator = ','\n+                            decimal_separator = '.'\n+                        elif val.find(',') > val.find('.'):\n+                            thousand_separator = '.'\n+                            decimal_separator = ','\n+                else:\n+                    # This is not a float so exit this try\n+                    float('a')\n+            if thousand_separator and not options.get('float_decimal_separator', False):","path":"addons/base_import/models.py","position":107,"original_position":107,"commit_id":"a30465fe85632dfa4a2672851ee76779c02c18c6","original_commit_id":"a30465fe85632dfa4a2672851ee76779c02c18c6","user":{"login":"xmo-odoo","id":7571158,"avatar_url":"https://avatars.githubusercontent.com/u/7571158?v=3","gravatar_id":"","url":"https://api.github.com/users/xmo-odoo","html_url":"https://github.com/xmo-odoo","followers_url":"https://api.github.com/users/xmo-odoo/followers","following_url":"https://api.github.com/users/xmo-odoo/following{/other_user}","gists_url":"https://api.github.com/users/xmo-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/xmo-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xmo-odoo/subscriptions","organizations_url":"https://api.github.com/users/xmo-odoo/orgs","repos_url":"https://api.github.com/users/xmo-odoo/repos","events_url":"https://api.github.com/users/xmo-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/xmo-odoo/received_events","type":"User","site_admin":false},"body":"default value unnecessary","created_at":"2016-03-31T10:05:16Z","updated_at":"2016-03-31T10:05:16Z","html_url":"https://github.com/odoo/odoo/pull/11548#discussion_r58029360","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/11548","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/58029360"},"html":{"href":"https://github.com/odoo/odoo/pull/11548#discussion_r58029360"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/11548"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/11548","id":64645066,"html_url":"https://github.com/odoo/odoo/pull/11548","diff_url":"https://github.com/odoo/odoo/pull/11548.diff","patch_url":"https://github.com/odoo/odoo/pull/11548.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/11548","number":11548,"state":"open","locked":false,"title":"[REF] base_import: simplify import by reducing choice for the columns…","user":{"login":"csnauwaert","id":7338483,"avatar_url":"https://avatars.githubusercontent.com/u/7338483?v=3","gravatar_id":"","url":"https://api.github.com/users/csnauwaert","html_url":"https://github.com/csnauwaert","followers_url":"https://api.github.com/users/csnauwaert/followers","following_url":"https://api.github.com/users/csnauwaert/following{/other_user}","gists_url":"https://api.github.com/users/csnauwaert/gists{/gist_id}","starred_url":"https://api.github.com/users/csnauwaert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csnauwaert/subscriptions","organizations_url":"https://api.github.com/users/csnauwaert/orgs","repos_url":"https://api.github.com/users/csnauwaert/repos","events_url":"https://api.github.com/users/csnauwaert/events{/privacy}","received_events_url":"https://api.github.com/users/csnauwaert/received_events","type":"User","site_admin":false},"body":"… based on heuristic\r\n\r\nautomatically try to detect type of columns from the first 10 rows of file:\r\nIf column only contains integer, only show, int, float, monetary, m2o, o2m, m2m fields in wizard\r\nIf column only contains true/false values, only show boolean fields in wizard\r\netc\r\n\r\nadd an advanced mode which is the same as previous import (show all fields)\r\n\r\nSupport different date format and float value with currency as well as float value with parenthesis to reprensent negative value.","created_at":"2016-03-30T15:17:11Z","updated_at":"2016-03-31T10:05:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"779473a018c6c15d7188c0a298e07dfdc3899070","assignee":{"login":"xmo-odoo","id":7571158,"avatar_url":"https://avatars.githubusercontent.com/u/7571158?v=3","gravatar_id":"","url":"https://api.github.com/users/xmo-odoo","html_url":"https://github.com/xmo-odoo","followers_url":"https://api.github.com/users/xmo-odoo/followers","following_url":"https://api.github.com/users/xmo-odoo/following{/other_user}","gists_url":"https://api.github.com/users/xmo-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/xmo-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xmo-odoo/subscriptions","organizations_url":"https://api.github.com/users/xmo-odoo/orgs","repos_url":"https://api.github.com/users/xmo-odoo/repos","events_url":"https://api.github.com/users/xmo-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/xmo-odoo/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/11548/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/11548/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/11548/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/a30465fe85632dfa4a2672851ee76779c02c18c6","head":{"label":"odoo-dev:master-improve-import-csv","ref":"master-improve-import-csv","sha":"a30465fe85632dfa4a2672851ee76779c02c18c6","user":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":19853934,"name":"odoo","full_name":"odoo-dev/odoo","owner":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo-dev/odoo","description":"RD Dev Repository","fork":true,"url":"https://api.github.com/repos/odoo-dev/odoo","forks_url":"https://api.github.com/repos/odoo-dev/odoo/forks","keys_url":"https://api.github.com/repos/odoo-dev/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo-dev/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo-dev/odoo/teams","hooks_url":"https://api.github.com/repos/odoo-dev/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo-dev/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo-dev/odoo/events","assignees_url":"https://api.github.com/repos/odoo-dev/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo-dev/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo-dev/odoo/tags","blobs_url":"https://api.github.com/repos/odoo-dev/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo-dev/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo-dev/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo-dev/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo-dev/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo-dev/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo-dev/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo-dev/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo-dev/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo-dev/odoo/subscription","commits_url":"https://api.github.com/repos/odoo-dev/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo-dev/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo-dev/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo-dev/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo-dev/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo-dev/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo-dev/odoo/merges","archive_url":"https://api.github.com/repos/odoo-dev/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo-dev/odoo/downloads","issues_url":"https://api.github.com/repos/odoo-dev/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo-dev/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo-dev/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo-dev/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo-dev/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo-dev/odoo/releases{/id}","deployments_url":"https://api.github.com/repos/odoo-dev/odoo/deployments","created_at":"2014-05-16T11:16:19Z","updated_at":"2016-03-15T11:14:00Z","pushed_at":"2016-03-31T10:03:37Z","git_url":"git://github.com/odoo-dev/odoo.git","ssh_url":"git@github.com:odoo-dev/odoo.git","clone_url":"https://github.com/odoo-dev/odoo.git","svn_url":"https://github.com/odoo-dev/odoo","homepage":"https://www.odoo.com","size":3647388,"stargazers_count":66,"watchers_count":66,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":25,"mirror_url":null,"open_issues_count":1,"forks":25,"open_issues":1,"watchers":66,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"0ffc61d8542c434d90a37220fa915107051ef899","user":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"repo":{"id":19745004,"name":"odoo","full_name":"odoo/odoo","owner":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo/odoo","description":"Odoo (formerly OpenERP). Open Source Apps To Grow Your Business.","fork":false,"url":"https://api.github.com/repos/odoo/odoo","forks_url":"https://api.github.com/repos/odoo/odoo/forks","keys_url":"https://api.github.com/repos/odoo/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo/odoo/teams","hooks_url":"https://api.github.com/repos/odoo/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo/odoo/events","assignees_url":"https://api.github.com/repos/odoo/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo/odoo/tags","blobs_url":"https://api.github.com/repos/odoo/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo/odoo/subscription","commits_url":"https://api.github.com/repos/odoo/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo/odoo/merges","archive_url":"https://api.github.com/repos/odoo/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo/odoo/downloads","issues_url":"https://api.github.com/repos/odoo/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo/odoo/releases{/id}","deployments_url":"https://api.github.com/repos/odoo/odoo/deployments","created_at":"2014-05-13T15:38:58Z","updated_at":"2016-03-31T04:35:34Z","pushed_at":"2016-03-31T10:02:53Z","git_url":"git://github.com/odoo/odoo.git","ssh_url":"git@github.com:odoo/odoo.git","clone_url":"https://github.com/odoo/odoo.git","svn_url":"https://github.com/odoo/odoo","homepage":"https://www.odoo.com","size":1645161,"stargazers_count":4010,"watchers_count":4010,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3863,"mirror_url":null,"open_issues_count":3262,"forks":3863,"open_issues":3262,"watchers":4010,"default_branch":"9.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/11548"},"html":{"href":"https://github.com/odoo/odoo/pull/11548"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/11548"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/11548/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/11548/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/11548/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/a30465fe85632dfa4a2672851ee76779c02c18c6"}}}}