mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-08 13:55:21 +02:00
feat: add exchange_currency to currency
This commit is contained in:
@@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from apps.common.widgets.crispy.submit import NoClassSubmit
|
from apps.common.widgets.crispy.submit import NoClassSubmit
|
||||||
from apps.common.widgets.decimal import ArbitraryDecimalDisplayNumberInput
|
from apps.common.widgets.decimal import ArbitraryDecimalDisplayNumberInput
|
||||||
from apps.currencies.models import Currency, ExchangeRate
|
from apps.currencies.models import Currency, ExchangeRate
|
||||||
|
from apps.common.widgets.tom_select import TomSelect
|
||||||
|
|
||||||
|
|
||||||
class CurrencyForm(forms.ModelForm):
|
class CurrencyForm(forms.ModelForm):
|
||||||
@@ -16,7 +17,17 @@ class CurrencyForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Currency
|
model = Currency
|
||||||
fields = ["name", "decimal_places", "prefix", "suffix", "code"]
|
fields = [
|
||||||
|
"name",
|
||||||
|
"decimal_places",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"code",
|
||||||
|
"exchange_currency",
|
||||||
|
]
|
||||||
|
widgets = {
|
||||||
|
"exchange_currency": TomSelect(),
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@@ -25,7 +36,12 @@ class CurrencyForm(forms.ModelForm):
|
|||||||
self.helper.form_tag = False
|
self.helper.form_tag = False
|
||||||
self.helper.form_method = "post"
|
self.helper.form_method = "post"
|
||||||
self.helper.layout = Layout(
|
self.helper.layout = Layout(
|
||||||
"code", "name", "decimal_places", "prefix", "suffix"
|
"code",
|
||||||
|
"name",
|
||||||
|
"decimal_places",
|
||||||
|
"prefix",
|
||||||
|
"suffix",
|
||||||
|
"exchange_currency",
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.instance and self.instance.pk:
|
if self.instance and self.instance.pk:
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.2 on 2024-11-09 05:03
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('currencies', '0005_alter_currency_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='currency',
|
||||||
|
name='exchange_currency',
|
||||||
|
field=models.ForeignKey(blank=True, help_text='Default currency for exchange calculations', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='exchange_currencies', to='currencies.currency', verbose_name='Exchange Currency'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -14,6 +14,16 @@ class Currency(models.Model):
|
|||||||
prefix = models.CharField(max_length=10, verbose_name=_("Prefix"), blank=True)
|
prefix = models.CharField(max_length=10, verbose_name=_("Prefix"), blank=True)
|
||||||
suffix = models.CharField(max_length=10, verbose_name=_("Suffix"), blank=True)
|
suffix = models.CharField(max_length=10, verbose_name=_("Suffix"), blank=True)
|
||||||
|
|
||||||
|
exchange_currency = models.ForeignKey(
|
||||||
|
"self",
|
||||||
|
verbose_name=_("Exchange Currency"),
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
related_name="exchange_currencies",
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
help_text=_("Default currency for exchange calculations"),
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user