From 245b5afcfdb0b86f88637fdab901b8307a97a16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=A9al?= Date: Tue, 12 May 2015 14:36:27 +0200 Subject: [PATCH] [FIX] base_import: prioritise field name over string When importing csv data, the column name is matched on the field name and string attribute. For some fields (e.g. name & display_name), you could get a match on both the string and technical field name for different fields The order of the fields is not deterministic as stored in a dictionnary so different results were possible at different import. The technical name should be prioritised (more stable, unique constraint). Fixes #6657 --- addons/base_import/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/base_import/models.py b/addons/base_import/models.py index 9778391521a..784ae7f49f1 100644 --- a/addons/base_import/models.py +++ b/addons/base_import/models.py @@ -158,12 +158,19 @@ class ir_import(orm.TransientModel): all the fields to traverse :rtype: list(Field) """ + string_match = None for field in fields: # FIXME: should match all translations & original # TODO: use string distance (levenshtein? hamming?) - if header.lower() == field['name'].lower() \ - or header.lower() == field['string'].lower(): + if header.lower() == field['name'].lower(): return [field] + if header.lower() == field['string'].lower(): + # matching string are not reliable way because + # strings have no unique constraint + string_match = field + if string_match: + # this behavior is only applied if there is no matching field['name'] + return [string_match] if '/' not in header: return []