mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-12 09:15:49 +00:00
Merge pull request #12 from i701/feat/task-queues
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m55s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m55s
refactor(devices): update device payment status in background task and remove unused serializer field 🔨
This commit is contained in:
@ -72,6 +72,9 @@ def update_expired_payments(timestamp: int):
|
||||
logger.info(f"Found {count} payments to expire.")
|
||||
|
||||
for payment in expired_payments_qs:
|
||||
for device in payment.devices.all():
|
||||
device.has_a_pending_payment = False
|
||||
device.save()
|
||||
if (
|
||||
payment.user
|
||||
and payment.user.mobile
|
||||
|
@ -32,7 +32,6 @@ class BlockDeviceSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class DeviceSerializer(serializers.ModelSerializer):
|
||||
pending_payment_id = serializers.SerializerMethodField()
|
||||
user = serializers.SerializerMethodField()
|
||||
|
||||
def get_user(self, obj):
|
||||
@ -46,21 +45,6 @@ class DeviceSerializer(serializers.ModelSerializer):
|
||||
}
|
||||
return None
|
||||
|
||||
def get_pending_payment_id(self, obj):
|
||||
# Query the last unpaid payment for the device
|
||||
unpaid_payment = (
|
||||
Payment.objects.filter(
|
||||
devices=obj,
|
||||
paid=False,
|
||||
status="PENDING",
|
||||
expires_at__gt=timezone.now(),
|
||||
expires_at__isnull=True,
|
||||
)
|
||||
.order_by("-created_at")
|
||||
.first()
|
||||
)
|
||||
return unpaid_payment.id if unpaid_payment else None
|
||||
|
||||
class Meta: # type: ignore
|
||||
model = Device
|
||||
fields = "__all__"
|
||||
|
Reference in New Issue
Block a user