mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-10 17:46:30 +00:00
fix(payment): refine unpaid payment query to include status and expiration checks 🐛
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m59s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m59s
This commit is contained in:
@ -2,6 +2,7 @@ from rest_framework import serializers
|
|||||||
from .models import Device
|
from .models import Device
|
||||||
from api.serializers import CustomReadOnlyUserSerializer
|
from api.serializers import CustomReadOnlyUserSerializer
|
||||||
from billing.models import Payment # Import the Payment model
|
from billing.models import Payment # Import the Payment model
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
class CreateDeviceSerializer(serializers.ModelSerializer):
|
class CreateDeviceSerializer(serializers.ModelSerializer):
|
||||||
@ -48,7 +49,13 @@ class DeviceSerializer(serializers.ModelSerializer):
|
|||||||
def get_pending_payment_id(self, obj):
|
def get_pending_payment_id(self, obj):
|
||||||
# Query the last unpaid payment for the device
|
# Query the last unpaid payment for the device
|
||||||
unpaid_payment = (
|
unpaid_payment = (
|
||||||
Payment.objects.filter(devices=obj, paid=False)
|
Payment.objects.filter(
|
||||||
|
devices=obj,
|
||||||
|
paid=False,
|
||||||
|
status="PENDING",
|
||||||
|
expires_at__gt=timezone.now(),
|
||||||
|
expires_at__isnull=True,
|
||||||
|
)
|
||||||
.order_by("-created_at")
|
.order_by("-created_at")
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user