- Refactored monetary fields across models to use `DecimalField` for improved precision. - Implemented two-factor authentication (2FA) for admin logins with OTP codes. - Added ability to generate admin OTP via management commands. - Updated Docker Compose override for dev-specific port bindings. - Included template for 2FA OTP verification to enhance security. Additional changes: - Upgraded and downgraded various dependencies (e.g., django-celery-beat and yarl). - Replaced float-based calculations with decimal for consistent rounding behavior. - Improved admin user management commands for activation and OTP generation.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from decimal import Decimal
|
|
|
|
from rest_framework.fields import DecimalField, JSONField, SerializerMethodField
|
|
from rest_framework.serializers import ModelSerializer, Serializer
|
|
|
|
from engine.payments.models import Transaction
|
|
|
|
|
|
class DepositSerializer(Serializer):
|
|
amount = DecimalField(
|
|
max_digits=12,
|
|
decimal_places=2,
|
|
required=True,
|
|
min_value=Decimal("0.01"),
|
|
max_value=Decimal("999999.99"),
|
|
)
|
|
|
|
|
|
class TransactionSerializer(ModelSerializer):
|
|
class Meta:
|
|
model = Transaction
|
|
fields = "__all__"
|
|
|
|
|
|
class TransactionProcessSerializer(ModelSerializer):
|
|
process = JSONField(required=True)
|
|
order_hr_id = SerializerMethodField(read_only=True, required=False)
|
|
order_uuid = SerializerMethodField(read_only=True, required=False)
|
|
|
|
def get_order_hr_id(self, obj: Transaction) -> str | None:
|
|
return obj.order.human_readable_id if obj.order else None
|
|
|
|
def get_order_uuid(self, obj: Transaction) -> str | None:
|
|
return str(obj.order.uuid) if obj.order else None
|
|
|
|
class Meta:
|
|
model = Transaction
|
|
fields = ("process", "order_hr_id", "order_uuid")
|
|
read_only_fields = ("process", "order_hr_id", "order_uuid")
|
|
|
|
|
|
class LimitsSerializer(Serializer):
|
|
min_amount = DecimalField(max_digits=12, decimal_places=2, read_only=True)
|
|
max_amount = DecimalField(max_digits=12, decimal_places=2, read_only=True)
|