diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index 646d837625..acf9d0423c 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -1016,6 +1016,16 @@ class ModelStorage(Model): elif value: return value + def convert_multiselection(value): + if isinstance(value, str) and value: + return next(csv.reader( + value.splitlines(), + delimiter=',', + quoting=csv.QUOTE_NONE, + escapechar='\\')) + else: + return value + try: return locals()['convert_%s' % ftype](value) except KeyError: diff --git a/trytond/trytond/tests/import_data.py b/trytond/trytond/tests/import_data.py index 6c7a333436..672e4f90fa 100644 --- a/trytond/trytond/tests/import_data.py +++ b/trytond/trytond/tests/import_data.py @@ -69,6 +69,16 @@ class ImportDataSelection(ModelSQL): ], 'Selection') +class ImportDataMultiSelection(ModelSQL): + "Import Data MultiSelection" + __name__ = 'test.import_data.multiselection' + multiselection = fields.MultiSelection([ + ('select1', "Select 1"), + ('select2', "Select 2"), + ('select3', "Select 3"), + ], "MultiSelection") + + class ImportDataMany2OneTarget(ModelSQL): "Import Data Many2One Target" __name__ = 'test.import_data.many2one.target' @@ -180,6 +190,7 @@ def register(module): ImportDataDateTime, ImportDataTimeDelta, ImportDataSelection, + ImportDataMultiSelection, ImportDataMany2OneTarget, ImportDataMany2One, ImportDataMany2ManyTarget, diff --git a/trytond/trytond/tests/test_importdata.py b/trytond/trytond/tests/test_importdata.py index 1f0ef93506..c2bf37df88 100644 --- a/trytond/trytond/tests/test_importdata.py +++ b/trytond/trytond/tests/test_importdata.py @@ -265,6 +265,28 @@ class ImportDataTestCase(unittest.TestCase): Selection.import_data(['selection'], [['select1'], ['select2']]), 2) + @with_transaction() + def test_multiselection(self): + 'Test multiselection' + pool = Pool() + MultiSelection = pool.get('test.import_data.multiselection') + + for value in ['select1', 'select1,select2', '']: + with self.subTest(value=value): + self.assertEqual( + MultiSelection.import_data( + ['multiselection'], [[value]]), 1) + + @with_transaction() + def test_multiselection_many_rows(self): + 'Test multiselection many rows' + pool = Pool() + MultiSelection = pool.get('test.import_data.multiselection') + + self.assertEqual( + MultiSelection.import_data( + ['multiselection'], [['select1'], ['select1,select2']]), 2) + @with_transaction() def test_many2one(self): 'Test many2one'