feat(currencies): allow archiving

This commit is contained in:
Herculino Trotta
2025-08-29 22:47:00 -03:00
parent 4565dc770b
commit 1abe9e9f62
7 changed files with 50 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field, Column, Row
from django import forms
from django.db.models import Q
from django.utils.translation import gettext_lazy as _
from apps.accounts.models import Account
@@ -15,6 +16,7 @@ from apps.common.widgets.crispy.submit import NoClassSubmit
from apps.common.widgets.tom_select import TomSelect
from apps.transactions.models import TransactionCategory, TransactionTag
from apps.common.widgets.decimal import ArbitraryDecimalDisplayNumberInput
from apps.currencies.models import Currency
class AccountGroupForm(forms.ModelForm):
@@ -79,6 +81,24 @@ class AccountForm(forms.ModelForm):
self.fields["group"].queryset = AccountGroup.objects.all()
if self.instance.id:
self.fields["currency"].queryset = Currency.objects.filter(
Q(is_archived=False) | Q(accounts=self.instance.id),
)
self.fields["exchange_currency"].queryset = Currency.objects.filter(
Q(is_archived=False) | Q(accounts=self.instance.id)
)
else:
self.fields["currency"].queryset = Currency.objects.filter(
Q(is_archived=False),
)
self.fields["exchange_currency"].queryset = Currency.objects.filter(
Q(is_archived=False)
)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.form_method = "post"

View File

@@ -26,6 +26,7 @@ class CurrencyForm(forms.ModelForm):
"suffix",
"code",
"exchange_currency",
"is_archived",
]
widgets = {
"exchange_currency": TomSelect(),
@@ -40,6 +41,7 @@ class CurrencyForm(forms.ModelForm):
self.helper.layout = Layout(
"code",
"name",
Switch("is_archived"),
"decimal_places",
"prefix",
"suffix",

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.5 on 2025-08-30 00:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('currencies', '0021_alter_exchangerateservice_service_type'),
]
operations = [
migrations.AddField(
model_name='currency',
name='is_archived',
field=models.BooleanField(default=False, verbose_name='Archived'),
),
]

View File

@@ -32,6 +32,11 @@ class Currency(models.Model):
help_text=_("Default currency for exchange calculations"),
)
is_archived = models.BooleanField(
default=False,
verbose_name=_("Archived"),
)
def __str__(self):
return self.name

View File

@@ -102,4 +102,6 @@ def get_transactions(
account__in=request.user.untracked_accounts.all()
)
transactions = transactions.exclude(account__currency__is_archived=True)
return transactions

View File

@@ -30,6 +30,7 @@ def calculate_historical_currency_net_worth(queryset):
| Q(accounts__visibility="private", accounts__owner=None),
accounts__is_archived=False,
accounts__isnull=False,
is_archived=False,
)
.values_list("name", flat=True)
.distinct()

View File

@@ -24,6 +24,7 @@
<th scope="col" class="col-auto"></th>
<th scope="col" class="col-auto">{% translate 'Code' %}</th>
<th scope="col" class="col">{% translate 'Name' %}</th>
<th scope="col" class="col">{% translate 'Archived' %}</th>
</tr>
</thead>
<tbody>
@@ -53,6 +54,7 @@
</td>
<td class="col-auto">{{ currency.code }}</td>
<td class="col">{{ currency.name }}</td>
<td class="col">{% if currency.is_archived %}<i class="fa-solid fa-solid fa-check text-success"></i>{% endif %}</td>
</tr>
{% endfor %}
</tbody>