feat: add exchange rate config page

This commit is contained in:
Herculino Trotta
2024-10-16 14:30:32 -03:00
parent 31ca384ced
commit fde5101011
10 changed files with 258 additions and 3 deletions
+41 -1
View File
@@ -6,7 +6,8 @@ from django.forms import CharField
from django.utils.translation import gettext_lazy as _
from apps.common.widgets.crispy.submit import NoClassSubmit
from apps.currencies.models import Currency
from apps.common.widgets.decimal import ArbitraryDecimalDisplayNumberInput
from apps.currencies.models import Currency, ExchangeRate
class CurrencyForm(forms.ModelForm):
@@ -43,3 +44,42 @@ class CurrencyForm(forms.ModelForm):
),
),
)
class ExchangeRateForm(forms.ModelForm):
date = forms.DateTimeField(
widget=forms.DateTimeInput(
attrs={"type": "datetime-local"}, format="%Y-%m-%dT%H:%M"
)
)
class Meta:
model = ExchangeRate
fields = ["from_currency", "to_currency", "rate", "date"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.form_method = "post"
self.helper.layout = Layout("date", "from_currency", "to_currency", "rate")
self.fields["rate"].widget = ArbitraryDecimalDisplayNumberInput()
if self.instance and self.instance.pk:
self.helper.layout.append(
FormActions(
NoClassSubmit(
"submit", _("Update"), css_class="btn btn-outline-primary w-100"
),
),
)
else:
self.helper.layout.append(
FormActions(
NoClassSubmit(
"submit", _("Add"), css_class="btn btn-outline-primary w-100"
),
),
)