From 6dc14c73d6484ca180b1bc85ef015a619a53ab8b Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 11 May 2025 12:41:26 -0300 Subject: [PATCH 1/2] fix(api:accounts): unable to create an account with an account group Fixes #253 --- app/apps/api/serializers/accounts.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/apps/api/serializers/accounts.py b/app/apps/api/serializers/accounts.py index afd59b1..c7f5e45 100644 --- a/app/apps/api/serializers/accounts.py +++ b/app/apps/api/serializers/accounts.py @@ -1,3 +1,4 @@ +from django.db.models import Q from rest_framework import serializers from rest_framework.permissions import IsAuthenticated @@ -22,6 +23,7 @@ class AccountSerializer(serializers.ModelSerializer): write_only=True, allow_null=True, ) + currency = CurrencySerializer(read_only=True) currency_id = serializers.PrimaryKeyRelatedField( queryset=Currency.objects.all(), source="currency", write_only=True @@ -50,6 +52,13 @@ class AccountSerializer(serializers.ModelSerializer): "is_asset", ] + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + request = self.context.get("request") + if request and request.user.is_authenticated: + # Reload the queryset to get an updated version with the requesting user + self.fields["group_id"].queryset = AccountGroup.objects.all() + def create(self, validated_data): return Account.objects.create(**validated_data) From 46eb471a3478d70b727622b24f4285283eef1831 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 11 May 2025 12:46:30 -0300 Subject: [PATCH 2/2] fix(api:transactions): wrong schema definition for TransactionCategory --- app/apps/api/fields/transactions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/apps/api/fields/transactions.py b/app/apps/api/fields/transactions.py index 8723c76..e4ab075 100644 --- a/app/apps/api/fields/transactions.py +++ b/app/apps/api/fields/transactions.py @@ -41,7 +41,10 @@ class TransactionCategoryField(serializers.Field): def get_schema(): return { "type": "array", - "items": {"type": "string", "description": "TransactionTag ID or name"}, + "items": { + "type": "string", + "description": "TransactionCategory ID or name", + }, }