feat(api): read and write sub-transactions

Transactions, installment plans and recurring transactions take a nested
sub_transactions list; their amount becomes the parts' sum. Changing only
the amount of a split transaction, or adding parts to a transfer, is a
validation error.
This commit is contained in:
Herculino Trotta committed 2026-11-14 02:13:21 -03:00
1 parent ae245fb1d1
commit 5459865366
3 files changed
+206 -29

No files matched your search

+3 -3
View File
@@ -52,7 +52,7 @@ class TransactionViewSet(viewsets.ModelViewSet):
ordering = ["-id"]
def get_queryset(self):
return Transaction.objects.all()
return Transaction.objects.prefetch_related("sub_transactions")
def perform_create(self, serializer):
instance = serializer.save()
@@ -145,7 +145,7 @@ class InstallmentPlanViewSet(viewsets.ModelViewSet):
ordering = ["-id"]
def get_queryset(self):
return InstallmentPlan.objects.all()
return InstallmentPlan.objects.prefetch_related("sub_transactions")
class RecurringTransactionViewSet(viewsets.ModelViewSet):
@@ -175,4 +175,4 @@ class RecurringTransactionViewSet(viewsets.ModelViewSet):
ordering = ["-id"]
def get_queryset(self):
return RecurringTransaction.objects.all()
return RecurringTransaction.objects.prefetch_related("sub_transactions")