Fixed --stats functionality to properly handle case when no year is provided, ensuring it prints 'Jednotný kurz' for all years with available data rounded to 2 decimal places

This commit is contained in:
Kadu
2025-08-20 11:40:02 +02:00
parent bb3d4e8c7f
commit ee0f05f583

View File

@@ -242,36 +242,6 @@ def main():
if DEBUG:
print("Chyba: Pro použití --get-rate musí být zadána měna pomocí -c/--currency.")
sys.exit(1)
elif args.currency and not args.get_rate:
# Pokud je zadána měna, ale není zadán --get-rate, vytiskneme poslední dostupný kurz
currency_code = args.currency
debug_print(f"Vyhledávám poslední dostupný kurz pro {currency_code}...")
rate, date = database.get_last_rate_for_currency(currency_code)
if rate and date:
# Pro normální režim zobrazíme kurz ve formátu "11.11 # dated: dd.mm.yyyy"
if not DEBUG:
print(f"{rate} # dated: {date}")
else:
print(f"Poslední dostupný kurz {currency_code}: {rate} # dated: {date}")
else:
if not DEBUG:
print("Kurz nenalezen")
else:
print(f"Poslední dostupný kurz pro {currency_code} nebyl nalezen.")
elif args.report_year and args.currency:
if args.report_month:
# Generování měsíčního reportu
debug_print(f"Generuji měsíční report pro {args.currency} za {args.report_month}/{args.report_year}...")
rate_reporter.generate_monthly_report(args.report_year, args.report_month, args.currency, output_dir="data")
else:
# Generování ročního reportu
debug_print(f"Generuji roční report pro {args.currency} za rok {args.report_year}...")
rate_reporter.generate_yearly_report(args.report_year, args.currency, output_dir="data")
elif args.report_period and args.currency:
# Generování reportu za období
start_date, end_date = args.report_period
debug_print(f"Generuji report pro {args.currency} za období {start_date} - {end_date}...")
rate_reporter.generate_period_report(start_date, end_date, args.currency, output_dir="data")
elif args.stats is not None and args.currency:
currency_code = args.currency
if args.stats is True:
@@ -336,6 +306,22 @@ def main():
print("'Jednotný kurz' nenalezen")
else:
print(f"'Jednotný kurz' pro daňové účely podle metodiky ČNB pro {currency_code} za rok {year} nebyl nalezen.")
elif args.currency and not args.get_rate:
# Pokud je zadána měna, ale není zadán --get-rate, vytiskneme poslední dostupný kurz
currency_code = args.currency
debug_print(f"Vyhledávám poslední dostupný kurz pro {currency_code}...")
rate, date = database.get_last_rate_for_currency(currency_code)
if rate and date:
# Pro normální režim zobrazíme kurz ve formátu "11.11 # dated: dd.mm.yyyy"
if not DEBUG:
print(f"{rate} # dated: {date}")
else:
print(f"Poslední dostupný kurz {currency_code}: {rate} # dated: {date}")
else:
if not DEBUG:
print("Kurz nenalezen")
else:
print(f"Poslední dostupný kurz pro {currency_code} nebyl nalezen.")
else:
if DEBUG:
parser.print_help()