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)