Skip to content

Commit

Permalink
[FIX] improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolausweingartmair committed Dec 30, 2023
1 parent 5a89fda commit c261e4f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions base_iso3166/models/res_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ class ResCountry(models.Model):

@api.depends("code")
def _compute_codes(self):
for country in self:
self.code_alpha3 = False
self.code_numeric = False

for country in self.filtered("code"):
c = False
for country_type in ["countries", "historic_countries"]:
try:
c = getattr(pycountry, country_type).get(alpha_2=country.code)
except KeyError:
c = getattr(pycountry, country_type).get(alpha2=country.code)
if c:
break
if country.code:
for country_type in ["countries", "historic_countries"]:
res = getattr(pycountry, country_type)
try:
c = res.get(alpha_2=country.code)
except KeyError:
break
if c:
country.code_alpha3 = getattr(c, "alpha_3", getattr(c, "alpha3", False))
country.code_numeric = c.numeric
else:
country.code_alpha3 = False
country.code_numeric = False

0 comments on commit c261e4f

Please sign in to comment.