feat: add exchange_currency to currency

This commit is contained in:
Herculino Trotta
2024-11-09 02:55:42 -03:00
parent 3ee2ab9117
commit ff30bcdf4c
3 changed files with 47 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _
from apps.common.widgets.crispy.submit import NoClassSubmit
from apps.common.widgets.decimal import ArbitraryDecimalDisplayNumberInput
from apps.currencies.models import Currency, ExchangeRate
from apps.common.widgets.tom_select import TomSelect
class CurrencyForm(forms.ModelForm):
@@ -16,7 +17,17 @@ class CurrencyForm(forms.ModelForm):
class Meta:
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):
super().__init__(*args, **kwargs)
@@ -25,7 +36,12 @@ class CurrencyForm(forms.ModelForm):
self.helper.form_tag = False
self.helper.form_method = "post"
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:

View File

@@ -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'),
),
]

View File

@@ -14,6 +14,16 @@ class Currency(models.Model):
prefix = models.CharField(max_length=10, verbose_name=_("Prefix"), 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):
return self.name