mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-13 12:23:44 +01:00
feat(dca): limit create-transaction accounts to the strategy currencies
This commit is contained in:
1 parent
750b86394e
commit
3468b10e94
2 files changed
+16
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user