From 3468b10e942edf5aee857943c3b6fceed99e26cb Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Tue, 10 Nov 2026 21:57:39 -0300 Subject: [PATCH] feat(dca): limit create-transaction accounts to the strategy currencies --- app/apps/dca/forms.py | 2 ++ app/apps/dca/tests/test_transfer_linking.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/apps/dca/forms.py b/app/apps/dca/forms.py index 60fe5d45..0e638d68 100644 --- a/app/apps/dca/forms.py +++ b/app/apps/dca/forms.py @@ -250,6 +250,7 @@ class DCAEntryForm(forms.ModelForm): self.fields["from_account"].queryset = Account.objects.filter( is_archived=False, + currency=self.strategy.payment_currency, ) self.fields["from_category"].queryset = TransactionCategory.objects.filter( @@ -259,6 +260,7 @@ class DCAEntryForm(forms.ModelForm): self.fields["to_account"].queryset = Account.objects.filter( is_archived=False, + currency=self.strategy.target_currency, ) self.fields["to_category"].queryset = TransactionCategory.objects.filter( diff --git a/app/apps/dca/tests/test_transfer_linking.py b/app/apps/dca/tests/test_transfer_linking.py index 7dd0541f..ef4cce48 100644 --- a/app/apps/dca/tests/test_transfer_linking.py +++ b/app/apps/dca/tests/test_transfer_linking.py @@ -150,3 +150,17 @@ class DCATransferLinkingTests(TestCase): entry = form.save() self.assertEqual(list(entry.expense_transaction.entities.all()), [broker]) self.assertEqual(list(entry.income_transaction.entities.all()), [broker]) + + def test_create_accounts_must_hold_strategy_currency(self): + # Swapped: paying from the BTC wallet into the BRL cash account + form = DCAEntryForm( + data=self.entry_data( + create_transaction="on", + from_account=self.wallet.id, + to_account=self.cash.id, + ), + strategy=self.strategy, + ) + self.assertFalse(form.is_valid()) + self.assertIn("from_account", form.errors) + self.assertIn("to_account", form.errors)