Skip to content

Commit

Permalink
[FIX] base_location_geonames_import: avoid code duplicates in country…
Browse files Browse the repository at this point in the history
… states
  • Loading branch information
Tisho99 committed Sep 3, 2024
1 parent 888fc0b commit 6f7b48f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions base_location_geonames_import/wizard/geonames_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _create_states(self, parsed_csv, search_states, max_import, country):
)
}
# States
state_vals_set = set()
state_vals_dict = dict()
state_dict = {}
for i, row in enumerate(parsed_csv):
if max_import and i == max_import:
Expand All @@ -145,14 +145,15 @@ def _create_states(self, parsed_csv, search_states, max_import, country):
state = states_map.get(code)
if not state:
state_vals = self.prepare_state(row, country)
state_vals_set.add(
(state_vals["name"], state_vals["code"], state_vals["country_id"])
)
state_vals_dict.update({
(state_vals["code"], state_vals["country_id"]):
(state_vals["name"], state_vals["code"], state_vals["country_id"])
})
else:
state_dict[state.code] = state
state_vals_list = [
{"name": name, "code": code, "country_id": country_id}
for name, code, country_id in state_vals_set
for name, code, country_id in state_vals_dict.values()
]
logger.info("Importing %d states", len(state_vals_list))
created_states = self.env["res.country.state"].create(state_vals_list)
Expand Down

0 comments on commit 6f7b48f

Please sign in to comment.