diff --git a/base_location_geonames_import/__manifest__.py b/base_location_geonames_import/__manifest__.py index c2d6f86b3..415c08e06 100644 --- a/base_location_geonames_import/__manifest__.py +++ b/base_location_geonames_import/__manifest__.py @@ -6,7 +6,7 @@ { 'name': 'Base Location Geonames Import', - 'version': '9.0.1.0.0', + 'version': '9.0.1.0.1', 'category': 'Partner Management', 'license': 'AGPL-3', 'summary': 'Import better zip entries from Geonames', diff --git a/base_location_geonames_import/tests/test_base_location_geonames_import.py b/base_location_geonames_import/tests/test_base_location_geonames_import.py index f15b7bcad..cf6455505 100644 --- a/base_location_geonames_import/tests/test_base_location_geonames_import.py +++ b/base_location_geonames_import/tests/test_base_location_geonames_import.py @@ -14,27 +14,28 @@ class TestBaseLocationGeonamesImport(common.TransactionCase): }) def test_import_country(self): - self.wizard.with_context(max_import=10).run_import() - state_domain = [ - ('code', '=', '01'), + max_import = 10 + self.wizard.with_context(max_import=max_import).run_import() + # Look if there are imported states for the country + state_count = self.env['res.country.state'].search_count([ ('country_id', '=', self.country.id) - ] - states = self.env['res.country.state'].search(state_domain) - self.assertEqual(len(states), 1) - zip_domain = [ - ('name', '=', '98000'), - ('city', '=', 'Jardin Exotique'), - ('state_id', '=', states[0].id), - ('country_id', '=', self.country.id), - ] - zips = self.env['res.better.zip'].search(zip_domain) - self.assertEqual(len(zips), 1) + ]) + self.assertTrue(state_count) + # Look if the are imported zips + zip_count = self.env['res.better.zip'].search_count([ + ('country_id', '=', self.country.id) + ]) + self.assertEqual(zip_count, max_import) # Reimport again to see that there's no duplicates - self.wizard.with_context(max_import=10).run_import() - states = self.env['res.country.state'].search(state_domain) - self.assertEqual(len(states), 1) - zips = self.env['res.better.zip'].search(zip_domain) - self.assertEqual(len(zips), 1) + self.wizard.with_context(max_import=max_import).run_import() + state_count2 = self.env['res.country.state'].search_count([ + ('country_id', '=', self.country.id) + ]) + self.assertEqual(state_count, state_count2) + zip_count = self.env['res.better.zip'].search_count([ + ('country_id', '=', self.country.id) + ]) + self.assertEqual(zip_count, max_import) def test_delete_old_entries(self): zip_entry = self.env['res.better.zip'].create({ diff --git a/base_location_geonames_import/wizard/geonames_import.py b/base_location_geonames_import/wizard/geonames_import.py index 5948b85e7..d0f1cc285 100644 --- a/base_location_geonames_import/wizard/geonames_import.py +++ b/base_location_geonames_import/wizard/geonames_import.py @@ -133,7 +133,7 @@ class BetterZipGeonamesImport(models.TransientModel): zip_code = self.create_better_zip(row, self.country_id) if zip_code in zips_to_delete: zips_to_delete -= zip_code - if max_import and i == max_import: + if max_import and (i + 1) == max_import: break data_file.close() if zips_to_delete and not max_import: