)
@classmethod
- def send_receipt(cls, email, year, resend=False):
+ def generate_receipt(cls, email, year):
+ # TODO: abstract out
Contact = apps.get_model('messaging', 'Contact')
Funding = apps.get_model('funding', 'Funding')
BillingAgreement = apps.get_model('paypal', 'BillingAgreement')
ctx = {
"email": email,
"year": year,
- "next_year": year + 1,
"total": sum(x['amount'] for x in payments),
"payments": payments,
- "optout": optout,
- "resend": resend,
}
temp = tempfile.NamedTemporaryFile(prefix='receipt-', suffix='.pdf', delete=False)
temp.close()
"wl.eps": os.path.join(settings.STATIC_ROOT, "img/wl.eps"),
})
+ with open(temp.name, 'rb') as f:
+ content = f.read()
+ os.unlink(f.name)
+ return content, optout, payments
+
+ @classmethod
+ def send_receipt(cls, email, year, resend=False):
+ receipt = cls.generate_receipt(email, year)
+ if receipt:
+ content, optout, payments = receipt
+ ctx = {
+ "email": email,
+ "year": year,
+ "next_year": year + 1,
+ "total": sum(x['amount'] for x in payments),
+ "payments": payments,
+ "optout": optout,
+ "resend": resend,
+ }
message = EmailMessage(
'Odlicz darowiznę na Wolne Lektury od podatku',
template.loader.render_to_string('club/receipt_email.txt', ctx),
settings.CLUB_CONTACT_EMAIL, [email]
)
- with open(temp.name, 'rb') as f:
- message.attach('wolnelektury-darowizny.pdf', f.read(), 'application/pdf')
+ message.attach('wolnelektury-darowizny.pdf', content, 'application/pdf')
message.send()
- os.unlink(f.name)
class PayUCardToken(payu_models.CardToken):
{% load club %}
{% block content %}
+<div style="display: flex; gap:50px;">
<table class="table">
<tr>
<td>Aktywne miesięczne wpłaty cykliczne:</td>
<td>{% club_active_30day_sum %} zł.</td>
</tr>
</table>
+ <div>
+ <form method="post" action="{% url 'club_receipt' %}" style="display: flex; flex-direction: column;">
+ {% csrf_token %}
+ <span>Pobierz zestawienie roczne</span>
+ <input name="email" placeholder="email"></input>
+ <input name="year" type="number" min="2020" max="2024" placeholder="rok"></input>
+ <button>pobierz zestawienie</button>
+ </form>
+ </div>
+ </div>
{{ block.super }}
{% endblock content %}
path('notify/<int:pk>/', views.PayUNotifyView.as_view(), name='club_payu_notify'),
path('weryfikacja/', views.member_verify, name='club_member_verify'),
+
+ path('potwierdzenie/', views.receipt, name='club_receipt'),
]
from django.conf import settings
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import Sum
-from django.http import HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.utils.decorators import method_decorator
'result': rows
}
)
+
+
+@permission_required('club.schedule_view')
+def receipt(request):
+ email = request.POST.get('email')
+ year = int(request.POST.get('year'))
+
+ receipt = models.PayUOrder.generate_receipt(email, year)
+ if receipt:
+ content, optout, payments = receipt
+ if not content:
+ return HttpResponse('no content')
+ return HttpResponse(
+ content,
+ headers={
+ "Content-Type": "application/pdf",
+ "Content-Disposition": f'attachment; filename="wolnelektury-{year}-{email}.pdf"',
+ }
+ )
+