From 872fd374ed1b2eb07959064925538f00ba8c7b02 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Wed, 4 Jun 2025 15:45:19 +0200 Subject: [PATCH] New transferwise APIs no longer allow downloading statements So remove the scheduled job that handles them, as well as the database table that stores them. --- .../commands/transferwise_fetch_statements.py | 75 ------------------- ...006_delete_transferwisemonthlystatement.py | 16 ++++ postgresqleu/transferwise/models.py | 12 --- 3 files changed, 16 insertions(+), 87 deletions(-) delete mode 100644 postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py create mode 100644 postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py diff --git a/postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py b/postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py deleted file mode 100644 index e23d7936..00000000 --- a/postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py +++ /dev/null @@ -1,75 +0,0 @@ -# -# This script fetches monthly statements in PDF format from transferwise -# and passes them on to the notification address. -# -# Copyright (C) 2019, PostgreSQL Europe -# - - -from django.core.management.base import BaseCommand -from django.db import transaction -from django.conf import settings - -import datetime - -from postgresqleu.invoices.models import InvoicePaymentMethod -from postgresqleu.mailqueue.util import send_simple_mail -from postgresqleu.transferwise.models import TransferwiseMonthlyStatement - - -class Command(BaseCommand): - help = 'Fetch TransferWise monthly statements' - - class ScheduledJob: - scheduled_times = [datetime.time(2, 2), ] - - @classmethod - def should_run(self): - return InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.transferwise.Transferwise').exists() - - def handle(self, *args, **options): - for method in InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.transferwise.Transferwise'): - self.fetch_one_statement(method) - - @transaction.atomic - def fetch_one_statement(self, method): - pm = method.get_implementation() - if not pm.config('send_statements'): - return - - # We fetch for the *previous* month. Take todays day, truncate it to the month, - # subtract one day to get the last day of the previous month, and then truncate - # again to the first of that month. - d = (datetime.date.today().replace(day=1) - datetime.timedelta(days=1)).replace(day=1) - - if TransferwiseMonthlyStatement.objects.filter(paymentmethod=method, month=d).exists(): - return - - # Else we don't have it, so download it - api = pm.get_api() - r = api.get_binary( - 'profiles/{}/borderless-accounts/{}/statement.pdf'.format(api.get_profile(), api.get_account()['id']), { - 'currency': settings.CURRENCY_ABBREV, - 'intervalStart': api.format_date(d), - 'intervalEnd': api.format_date(datetime.date.today().replace(day=1)), - }, - version='v3', - ) - statement = TransferwiseMonthlyStatement( - paymentmethod=method, - month=d, - contents=r.read(), - ) - statement.save() - - send_simple_mail(settings.INVOICE_SENDER_EMAIL, - pm.config('notification_receiver'), - 'TransferWise monthly statement for {}'.format(statement.month.strftime("%B %Y")), - "The TransferWise monthly statement for {0} for the month of {1} is attached.".format( - method.internaldescription, - statement.month.strftime("%B %Y"), - ), - attachments=[ - ('TransferWise_{}.pdf'.format(statement.month.strftime("%b_%Y")), 'application/pdf', statement.contents), - ] - ) diff --git a/postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py b/postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py new file mode 100644 index 00000000..36a6ce41 --- /dev/null +++ b/postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.11 on 2025-06-04 13:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('transferwise', '0005_transferwise_monthly_statements'), + ] + + operations = [ + migrations.DeleteModel( + name='TransferwiseMonthlyStatement', + ), + ] diff --git a/postgresqleu/transferwise/models.py b/postgresqleu/transferwise/models.py index 0659149b..58bdab52 100644 --- a/postgresqleu/transferwise/models.py +++ b/postgresqleu/transferwise/models.py @@ -52,15 +52,3 @@ class TransferwisePayout(models.Model): sentat = models.DateTimeField(null=True, blank=True) completedat = models.DateTimeField(null=True, blank=True) completedtrans = models.ForeignKey(TransferwiseTransaction, blank=True, null=True, on_delete=models.CASCADE) - - -class TransferwiseMonthlyStatement(models.Model): - paymentmethod = models.ForeignKey(InvoicePaymentMethod, blank=False, null=False, on_delete=models.CASCADE) - month = models.DateField(null=False, blank=False) - downloaded = models.DateTimeField(null=False, blank=False, auto_now_add=True) - contents = models.BinaryField(null=False) - - class Meta: - unique_together = ( - ('month', 'paymentmethod'), - ) -- 2.39.5