mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-17 14:21:32 +01:00
Off unless MCP_ENABLED=true. Runs inside the web app (stateless Streamable HTTP, JSON responses), so no extra container or supervisord program. - Tools run the REST views in-process as the caller, so permissions, sharing, validation and transaction rules stay the API's. - 11 curated tools with compact output, plus search_api/call_api to reach every other API endpoint from the OpenAPI schema. - OAuth protected-resource metadata (RFC 9728) and a WWW-Authenticate hint on 401s, so MCP clients find the existing OAuth server and DCR. - GET /api/transactions/summary/: totals per currency and type, optionally grouped by category, tag, entity, account or month. API changes found while testing it: - Writes no longer need Django model permissions, which nothing granted; access now matches the web UI (signed-in user, scoped querysets, owner-only edits of shared objects). API tokens and OAuth apps can now write for regular users. - Account group owner is read-only; it could be set to another user. - Reject negative installment, recurring, DCA and exchange-rate amounts, a zero recurrence interval, and performance on non-investment accounts. - Accounts can be archived; group_id/exchange_currency_id are optional; category accepts null; currency prefix/suffix keep their spaces. - Transactions filter by tags and entities. - OpenAPI: separate request schemas (COMPONENT_SPLIT_REQUEST) and real descriptions for the viewsets and DCA chart actions.
90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
from rest_framework import serializers
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from apps.dca.models import DCAEntry, DCAStrategy
|
|
|
|
|
|
class DCAEntrySerializer(serializers.ModelSerializer):
|
|
profit_loss = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
profit_loss_percentage = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
current_value = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
entry_price = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
class Meta:
|
|
model = DCAEntry
|
|
fields = [
|
|
"id",
|
|
"strategy",
|
|
"date",
|
|
"amount_paid",
|
|
"amount_received",
|
|
"notes",
|
|
"created_at",
|
|
"updated_at",
|
|
"profit_loss",
|
|
"profit_loss_percentage",
|
|
"current_value",
|
|
"entry_price",
|
|
]
|
|
read_only_fields = ["created_at", "updated_at"]
|
|
extra_kwargs = {
|
|
"amount_paid": {"min_value": 0},
|
|
"amount_received": {"min_value": 0},
|
|
}
|
|
|
|
|
|
class DCAStrategySerializer(serializers.ModelSerializer):
|
|
entries = DCAEntrySerializer(many=True, read_only=True)
|
|
total_invested = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
total_received = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
average_entry_price = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
total_entries = serializers.IntegerField(read_only=True)
|
|
current_total_value = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
total_profit_loss = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
total_profit_loss_percentage = serializers.DecimalField(
|
|
max_digits=42, decimal_places=30, read_only=True
|
|
)
|
|
|
|
permission_classes = [IsAuthenticated]
|
|
|
|
class Meta:
|
|
model = DCAStrategy
|
|
fields = [
|
|
"id",
|
|
"name",
|
|
"target_currency",
|
|
"payment_currency",
|
|
"notes",
|
|
"created_at",
|
|
"updated_at",
|
|
"entries",
|
|
"total_invested",
|
|
"total_received",
|
|
"average_entry_price",
|
|
"total_entries",
|
|
"current_total_value",
|
|
"total_profit_loss",
|
|
"total_profit_loss_percentage",
|
|
]
|
|
read_only_fields = ["created_at", "updated_at"]
|