mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-13 12:23:44 +01:00
Hyperscript-driven page to simulate one-time, recurring and installment expenses or incomes over the projected balance.
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
from django.contrib.auth.decorators import login_required
|
|
from django.shortcuts import render
|
|
from django.utils import timezone
|
|
|
|
from apps.common.widgets.datepicker import AirMonthYearPickerInput
|
|
from apps.common.widgets.decimal import convert_to_decimal
|
|
from apps.currencies.models import Currency
|
|
from apps.currencies.utils.convert import convert
|
|
from apps.mini_tools.forms import CurrencyConverterForm
|
|
from apps.mini_tools.utils.exchange_rate_map import get_currency_exchange_map
|
|
from apps.mini_tools.utils.simulator import get_simulator_baseline
|
|
|
|
|
|
@login_required
|
|
def unit_price_calculator(request):
|
|
return render(request, "mini_tools/unit_price_calculator.html")
|
|
|
|
|
|
@login_required
|
|
def simulator(request):
|
|
start_month_input = AirMonthYearPickerInput(
|
|
clear_button=False, attrs={"class": "w-full sim-start"}
|
|
).render("start_month", timezone.localdate(timezone.now()).replace(day=1))
|
|
|
|
return render(
|
|
request,
|
|
"mini_tools/simulator.html",
|
|
context={
|
|
"baseline": get_simulator_baseline(request.user),
|
|
"start_month_input": start_month_input,
|
|
},
|
|
)
|
|
|
|
|
|
@login_required
|
|
def currency_converter(request):
|
|
rate_map = get_currency_exchange_map()
|
|
|
|
form = CurrencyConverterForm()
|
|
return render(
|
|
request,
|
|
"mini_tools/currency_converter/currency_converter.html",
|
|
context={"form": form, "rate_map": rate_map},
|
|
)
|
|
|
|
|
|
@login_required
|
|
def currency_converter_convert(request):
|
|
from_value = request.GET.get("from_value")
|
|
from_currency = request.GET.get("from_currency")
|
|
to_currency = request.GET.get("to_currency")
|
|
|
|
if from_currency:
|
|
from_currency = Currency.objects.filter(id=from_currency).first()
|
|
if to_currency:
|
|
to_currency = Currency.objects.filter(id=to_currency).first()
|
|
if from_value:
|
|
from_value = convert_to_decimal(from_value)
|
|
|
|
if from_currency and to_currency and from_value:
|
|
converted_amount, prefix, suffix, decimal_places = convert(
|
|
amount=from_value,
|
|
from_currency=from_currency,
|
|
to_currency=to_currency,
|
|
)
|
|
else:
|
|
converted_amount = None
|
|
prefix = ""
|
|
suffix = ""
|
|
decimal_places = 0
|
|
|
|
return render(
|
|
request,
|
|
"mini_tools/currency_converter/converted_value.html",
|
|
context={
|
|
"converted_amount": converted_amount,
|
|
"prefix": prefix,
|
|
"suffix": suffix,
|
|
"decimal_places": decimal_places,
|
|
},
|
|
)
|