From e1769cbea9dc9b13453f507321b4de2e86de2d36 Mon Sep 17 00:00:00 2001 From: amoyaux Date: Tue, 10 Oct 2017 14:01:41 +0200 Subject: [FIX] base_import: parse date and float for relational fields Use case to reproduce: -> Import a file with a float using a coma related to the model (for example the product.supplierinfo/price) It happens because the method that parse the date and float field only compare them to the main imported model. This commit complete the method by using a recursion on relational model in order to also parse the relational subfields. --- addons/base_import/tests/test_base_import.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'addons/base_import/tests') diff --git a/addons/base_import/tests/test_base_import.py b/addons/base_import/tests/test_base_import.py index 891fc3e7671..f858101fef3 100644 --- a/addons/base_import/tests/test_base_import.py +++ b/addons/base_import/tests/test_base_import.py @@ -402,7 +402,33 @@ class test_convert_import_data(TransactionCase): # if results empty, no errors self.assertItemsEqual(results, []) + def test_parse_relational_fields(self): + """ Ensure that relational fields float and date are correctly + parsed during the import call. + """ + import_wizard = self.env['base_import.import'].create({ + 'res_model': 'res.partner', + 'file': 'name,parent_id/id,parent_id/date,parent_id/credit_limit\n' + '"foo","__export__.res_partner_1","2017年10月12日","5,69"\n', + 'file_type': 'text/csv' + }) + options = { + 'date_format': '%Y年%m月%d日', + 'quoting': '"', + 'separator': ',', + 'float_decimal_separator': ',', + 'float_thousand_separator': '.', + 'headers': True + } + data, import_fields = import_wizard._convert_import_data( + ['name', 'parent_id/.id', 'parent_id/date', 'parent_id/credit_limit'], + options + ) + result = import_wizard._parse_import_data(data, import_fields, options) + # Check if the data 5,69 as been correctly parsed. + self.assertEqual(float(result[0][-1]), 5.69) + self.assertEqual(str(result[0][-2]), '2017-10-12') def test_filtered(self): """ If ``False`` is provided as field mapping for a column, -- cgit v1.2.3