Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

Fix/currency krone labels (#1640)

JacosVerksted1346d7ce4243
diff --git a/.github/scripts/test_update_currencies.py b/.github/scripts/test_update_currencies.py
index 40ac343b..2113fe1d 100644
--- a/.github/scripts/test_update_currencies.py
+++ b/.github/scripts/test_update_currencies.py
@@ -61,6 +61,48 @@ class CountriesToCurrenciesTests(unittest.TestCase):
'decimals': 2,
}], result)
+ def test_prefers_canonical_currency_entries_for_duplicate_codes(self):
+ result = update_currencies.countries_to_currencies([
+ {
+ 'names': {'common': 'Denmark'},
+ 'currencies': [{
+ 'code': 'DKK',
+ 'name': 'Danish krone',
+ 'symbol': 'kr.',
+ }],
+ },
+ {
+ 'names': {'common': 'Greenland'},
+ 'currencies': [{
+ 'code': 'DKK',
+ 'name': 'krone',
+ 'symbol': 'kr',
+ }],
+ },
+ {
+ 'names': {'common': 'Norway'},
+ 'currencies': [{
+ 'code': 'NOK',
+ 'name': 'Norwegian krone',
+ 'symbol': 'kr',
+ }],
+ },
+ {
+ 'names': {'common': 'Svalbard and Jan Mayen'},
+ 'currencies': [{
+ 'code': 'NOK',
+ 'name': 'krone',
+ 'symbol': 'kr',
+ }],
+ },
+ ], {'DKK': 2, 'NOK': 2})
+
+ deduped = {currency['code']: currency for currency in result}
+ self.assertEqual('Danish krone', deduped['DKK']['name'])
+ self.assertEqual('Denmark', deduped['DKK']['local'])
+ self.assertEqual('Norwegian krone', deduped['NOK']['name'])
+ self.assertEqual('Norway', deduped['NOK']['local'])
+
def test_rejects_old_currency_object_shape(self):
with self.assertRaisesRegex(ValueError, 'currencies must be a JSON list'):
update_currencies.countries_to_currencies([
diff --git a/.github/scripts/update_currencies.py b/.github/scripts/update_currencies.py
index 08d5fa8f..f046556d 100644
--- a/.github/scripts/update_currencies.py
+++ b/.github/scripts/update_currencies.py
@@ -26,6 +26,15 @@ CURRENCY_DECIMAL_OVERRIDES = {
"JPY": 0, # Japanese Yen has no decimal places
"BHD": 3, # Bahraini Dinar uses 3 decimal places
}
+
+# Some currency codes are shared by a country and one or more territories.
+# Prefer the canonical country entry so the app does not expose generic names
+# such as "Krone" for DKK/NOK after runtime deduplication by code.
+CANONICAL_CURRENCY_LOCALS = {
+ "DKK": "Denmark",
+ "NOK": "Norway",
+}
+
DEFAULT_DECIMALS = 2
MIN_DECIMALS = 0
MAX_DECIMALS = 6
@@ -156,6 +165,29 @@ def parse_country_page(payload):
return countries, meta
+def canonicalize_currency_rows(results):
+ canonical_by_code = {
+ row['code']: row
+ for row in results
+ if CANONICAL_CURRENCY_LOCALS.get(row['code']) == row['local']
+ }
+
+ canonicalized = []
+ for row in results:
+ canonical = canonical_by_code.get(row['code'])
+ if canonical is None:
+ canonicalized.append(row)
+ continue
+
+ updated = row.copy()
+ updated['local'] = canonical['local']
+ updated['name'] = canonical['name']
+ updated['symbol'] = canonical['symbol']
+ canonicalized.append(updated)
+
+ return canonicalized
+
+
def countries_to_currencies(countries, iso_data):
results = []
for country in countries:
@@ -205,7 +237,7 @@ def countries_to_currencies(countries, iso_data):
})
# sort by country name for consistency
- return sorted(results, key=lambda x: x['local'].lower())
+ return sorted(canonicalize_currency_rows(results), key=lambda x: x['local'].lower())
def fetch_currencies():
diff --git a/backend/internal/core/currencies/currencies.json b/backend/internal/core/currencies/currencies.json
index bef6987c..77f47d57 100644
--- a/backend/internal/core/currencies/currencies.json
+++ b/backend/internal/core/currencies/currencies.json
@@ -447,6 +447,20 @@
"name": "Danish krone",
"decimals": 2
},
+ {
+ "code": "DKK",
+ "local": "Denmark",
+ "symbol": "kr",
+ "name": "Danish krone",
+ "decimals": 2
+ },
+ {
+ "code": "DKK",
+ "local": "Denmark",
+ "symbol": "kr",
+ "name": "Danish krone",
+ "decimals": 2
+ },
{
"code": "DJF",
"local": "Djibouti",
@@ -545,13 +559,6 @@
"name": "Falkland Islands pound",
"decimals": 2
},
- {
- "code": "DKK",
- "local": "Faroe Islands",
- "symbol": "kr",
- "name": "Danish krone",
- "decimals": 2
- },
{
"code": "FOK",
"local": "Faroe Islands",
@@ -650,13 +657,6 @@
"name": "Euro",
"decimals": 2
},
- {
- "code": "DKK",
- "local": "Greenland",
- "symbol": "kr.",
- "name": "Krone",
- "decimals": 2
- },
{
"code": "XCD",
"local": "Grenada",
@@ -1252,6 +1252,13 @@
"name": "Norwegian krone",
"decimals": 2
},
+ {
+ "code": "NOK",
+ "local": "Norway",
+ "symbol": "kr",
+ "name": "Norwegian krone",
+ "decimals": 2
+ },
{
"code": "OMR",
"local": "Oman",
@@ -1616,13 +1623,6 @@
"name": "Surinamese dollar",
"decimals": 2
},
- {
- "code": "NOK",
- "local": "Svalbard and Jan Mayen",
- "symbol": "kr",
- "name": "Krone",
- "decimals": 2
- },
{
"code": "SEK",
"local": "Sweden",
@@ -1903,4 +1903,4 @@
"name": "Euro",
"decimals": 2
}
-]
\ No newline at end of file
+]