diff --git a/validation.py b/validation.py index 0c9a590..e913449 100644 --- a/validation.py +++ b/validation.py @@ -377,11 +377,23 @@ def validate_settings(payload): settings[key] = str(flag) if "wealth_tax_threshold_ore" in data: - ore, error = validate_ore(data["wealth_tax_threshold_ore"], optional=True) - if error: - errors["wealth_tax_threshold_ore"] = error + text = str(data["wealth_tax_threshold_ore"] or "").strip() + if not text: + settings["wealth_tax_threshold_ore"] = "0" else: - settings["wealth_tax_threshold_ore"] = str(ore or 0) + try: + ore = rates.nok_to_ore(text) + except ValueError as error: + errors["wealth_tax_threshold_ore"] = ( + "Beløp kan ha høgst 2 desimalar." + if "2 decimals" in str(error) + else "Beløp må vere eit tal, t.d. 1 000 000." + ) + else: + if ore < 0: + errors["wealth_tax_threshold_ore"] = "Botnen kan ikkje vere negativ." + else: + settings["wealth_tax_threshold_ore"] = str(ore) if "year_end_price_source" in data: settings["year_end_price_source"] = str(data["year_end_price_source"]).strip()