summaryrefslogtreecommitdiff
path: root/postgresqleu/trustlypayment
diff options
context:
space:
mode:
authorMagnus Hagander2019-01-26 18:11:27 +0000
committerMagnus Hagander2019-01-28 20:36:04 +0000
commitdef070ead25bf3f1f80490dd8c1fdd34680979b3 (patch)
treeb3dcbef3671a39a965ba9405e2e161fe19726ce3 /postgresqleu/trustlypayment
parentd2d3824645b9005fed338e71266ec88ea15b3cd5 (diff)
Schedule existing django management commands
This adds the scheduling metadata to all the existing management commands. In passing, also makes the description nicer on a couple of them, since it is now shown in the admin web.
Diffstat (limited to 'postgresqleu/trustlypayment')
-rwxr-xr-xpostgresqleu/trustlypayment/management/commands/send_trustly_logreport.py10
-rw-r--r--postgresqleu/trustlypayment/management/commands/trustly_extend_invoices.py8
-rw-r--r--postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py13
-rw-r--r--postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py9
4 files changed, 38 insertions, 2 deletions
diff --git a/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py b/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py
index a36d03de..01b7c7db 100755
--- a/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py
+++ b/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py
@@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand
from django.db import transaction
from django.conf import settings
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, time
from io import StringIO
from postgresqleu.invoices.models import InvoicePaymentMethod
@@ -18,6 +18,14 @@ from postgresqleu.mailqueue.util import send_simple_mail
class Command(BaseCommand):
help = 'Send log information about Trustly events'
+ class ScheduledJob:
+ scheduled_times = [time(23, 15), ]
+ internal = True
+
+ @classmethod
+ def should_run(self):
+ return InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.trustly.TrustlyPayment').exists()
+
def handle(self, *args, **options):
for method in InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.trustly.TrustlyPayment'):
pm = method.get_implementation()
diff --git a/postgresqleu/trustlypayment/management/commands/trustly_extend_invoices.py b/postgresqleu/trustlypayment/management/commands/trustly_extend_invoices.py
index 5dda3eb0..dfc20909 100644
--- a/postgresqleu/trustlypayment/management/commands/trustly_extend_invoices.py
+++ b/postgresqleu/trustlypayment/management/commands/trustly_extend_invoices.py
@@ -11,6 +11,14 @@ from datetime import timedelta
class Command(BaseCommand):
help = 'Extend trustly invoices if they are in pending state'
+ class ScheduledJob:
+ scheduled_interval = timedelta(hours=1)
+ internal = True
+
+ @classmethod
+ def should_run(self):
+ return TrustlyTransaction.objects.filter(pendingat__isnull=False, completedat__isnull=True).exists()
+
def handle(self, *args, **options):
manager = InvoiceManager()
with transaction.atomic():
diff --git a/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py b/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py
index df7735cb..cbd40cdd 100644
--- a/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py
+++ b/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py
@@ -17,11 +17,22 @@ from postgresqleu.invoices.models import InvoiceRefund, InvoicePaymentMethod
from postgresqleu.invoices.util import InvoiceManager
from decimal import Decimal
+from datetime import timedelta
import dateutil
class Command(BaseCommand):
- help = 'Verify that a Trustly refund has completed, and flag it as such'
+ help = 'Flag completed Trustly refunds'
+
+ class ScheduledJob:
+ scheduled_interval = timedelta(hours=4)
+
+ @classmethod
+ def should_run(self):
+ if not InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.trustly.TrustlyPayment').exists():
+ return False
+
+ return InvoiceRefund.objects.filter(completed__isnull=True, invoice__paidusing__classname='postgresqleu.util.payment.trustly.TrustlyPayment').exists()
@transaction.atomic
def handle(self, *args, **options):
diff --git a/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py b/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py
index 48f4eb95..f0d76b9d 100644
--- a/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py
+++ b/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py
@@ -11,6 +11,8 @@ from django.core.management.base import BaseCommand
from django.db import transaction
from django.conf import settings
+from datetime import time
+
from postgresqleu.invoices.models import InvoicePaymentMethod
from postgresqleu.trustlypayment.util import Trustly
from postgresqleu.accounting.util import get_latest_account_balance
@@ -20,6 +22,13 @@ from postgresqleu.mailqueue.util import send_simple_mail
class Command(BaseCommand):
help = 'Compare trustly balance to the accounting system'
+ class ScheduledJob:
+ scheduled_times = [time(3, 7), ]
+
+ @classmethod
+ def should_run(self):
+ return InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.trustly.TrustlyPayment').exists()
+
@transaction.atomic
def handle(self, *args, **options):
for method in InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.trustly.TrustlyPayment'):