From: Radek Czajka Date: Thu, 9 Feb 2023 13:19:08 +0000 (+0100) Subject: receipts X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/891c65c58eef499c1ffc3a5fe690e1b6bff0f0db?ds=sidebyside;hp=6fdea282117c9e066e714d714d3c14efadbca335 receipts --- diff --git a/src/club/management/commands/send_receipts.py b/src/club/management/commands/send_receipts.py index acf8bc417..c827cba8c 100644 --- a/src/club/management/commands/send_receipts.py +++ b/src/club/management/commands/send_receipts.py @@ -8,6 +8,7 @@ from django.utils.timezone import now from club.models import PayUOrder from funding.models import Funding from paypal.models import BillingAgreement +from pz.models import Payment class Command(BaseCommand): @@ -44,6 +45,15 @@ class Command(BaseCommand): 'email', flat=True ).distinct() ) + emails.update( + Payment.objects.exclude(debit__email='').filter( + realised=True, + is_dd=True, + booking_date__year=year, + ).order_by('debit__email').values_list( + 'debit__email', flat=True + ).distinct() + ) if options['emails']: emails = options['emails'].split(',') diff --git a/src/club/models.py b/src/club/models.py index 468622f91..35402686b 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -2,6 +2,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from datetime import datetime, timedelta +from decimal import Decimal import os import tempfile from django.apps import apps @@ -370,8 +371,12 @@ class PayUOrder(payu_models.Order): Contact = apps.get_model('messaging', 'Contact') Funding = apps.get_model('funding', 'Funding') BillingAgreement = apps.get_model('paypal', 'BillingAgreement') + DirectDebit = apps.get_model('pz', 'DirectDebit') + Payment = apps.get_model('pz', 'Payment') + payments = [] + optout = None try: contact = Contact.objects.get(email=email) except Contact.DoesNotExist: @@ -381,8 +386,10 @@ class PayUOrder(payu_models.Order): notifications=True).order_by('completed_at').first() if funding is None: print('no notifications') - return - optout = funding.wl_optout_url() + if not DirectDebit.objects.filter(email=email, optout=False).exists(): + return + else: + optout = funding.wl_optout_url() else: if contact.level == Level.OPT_OUT: print('opt-out') @@ -409,9 +416,22 @@ class PayUOrder(payu_models.Order): 'amount': funding.amount, }) + for pa in Payment.objects.filter( + debit__email=email, + realised=True, + is_dd=True, + booking_date__year=year + ): + payments.append({ + 'timestamp': datetime(pa.booking_date.year, pa.booking_date.month, pa.booking_date.day, tzinfo=utc), + 'amount': Decimal(str(pa.debit.amount) + '.00') + }) + + if not payments: return payments.sort(key=lambda x: x['timestamp']) + print(payments) ctx = { "email": email, @@ -425,7 +445,7 @@ class PayUOrder(payu_models.Order): temp = tempfile.NamedTemporaryFile(prefix='receipt-', suffix='.pdf', delete=False) temp.close() render_to_pdf(temp.name, 'club/receipt.texml', ctx, { - "fnp.eps": os.path.join(settings.STATIC_ROOT, "img/fnp.eps"), + "wl.eps": os.path.join(settings.STATIC_ROOT, "img/wl.eps"), }) message = EmailMessage( diff --git a/src/club/templates/club/receipt.texml b/src/club/templates/club/receipt.texml index 0e34af238..9ad037c5a 100644 --- a/src/club/templates/club/receipt.texml +++ b/src/club/templates/club/receipt.texml @@ -1,3 +1,4 @@ +