forked from CGM_Public/pretix_original
Send automatic payment reminder emails, redesign mail settings
This commit is contained in:
33
src/pretix/base/migrations/0036_auto_20160902_0755.py
Normal file
33
src/pretix/base/migrations/0036_auto_20160902_0755.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-09-02 07:55
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def preserve_event_settings(apps, schema_editor):
|
||||
Event = apps.get_model('pretixbase', 'Event')
|
||||
EventSetting = apps.get_model('pretixbase', 'EventSetting')
|
||||
for e in Event.objects.all():
|
||||
EventSetting.objects.create(object=e, key='mail_days_order_expire_warning', value='0')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pretixbase', '0035_merge'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='expiry_reminder_sent',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='item',
|
||||
name='allow_cancel',
|
||||
field=models.BooleanField(default=True, help_text='If you deactivate this, an order including this product might not be cancelled by the user. It may still be cancelled by you.', verbose_name='Allow product to be cancelled'),
|
||||
),
|
||||
migrations.RunPython(preserve_event_settings)
|
||||
]
|
||||
@@ -160,6 +160,9 @@ class Order(LoggedModel):
|
||||
help_text=_("The text entered in this field will not be visible to the user and is available for your "
|
||||
"convenience.")
|
||||
)
|
||||
expiry_reminder_sent = models.BooleanField(
|
||||
default=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Order")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from collections import Counter, namedtuple
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
@@ -6,6 +7,7 @@ from typing import List, Optional
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.dispatch import receiver
|
||||
from django.utils.formats import date_format
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
@@ -21,7 +23,7 @@ from pretix.base.payment import BasePaymentProvider
|
||||
from pretix.base.services.invoices import (
|
||||
generate_cancellation, generate_invoice, invoice_qualified,
|
||||
)
|
||||
from pretix.base.services.mail import mail
|
||||
from pretix.base.services.mail import SendMailException, mail
|
||||
from pretix.base.signals import (
|
||||
order_paid, order_placed, periodic_task, register_payment_providers,
|
||||
)
|
||||
@@ -48,6 +50,8 @@ error_messages = {
|
||||
'voucher_required': _('You need a valid voucher code to order one of the products in your cart.'),
|
||||
}
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def mark_order_paid(order: Order, provider: str=None, info: str=None, date: datetime=None, manual: bool=None,
|
||||
force: bool=False, send_mail: bool=True, user: User=None) -> Order:
|
||||
@@ -368,6 +372,41 @@ def expire_orders(sender, **kwargs):
|
||||
o.save()
|
||||
|
||||
|
||||
@receiver(signal=periodic_task)
|
||||
def send_expiry_warnings(sender, **kwargs):
|
||||
eventcache = {}
|
||||
today = now().date()
|
||||
|
||||
for o in Order.objects.filter(expires__gte=today, expiry_reminder_sent=False, status=Order.STATUS_PENDING).select_related('event'):
|
||||
settings = eventcache.get(o.event.pk, None)
|
||||
if settings is None:
|
||||
settings = o.event.settings
|
||||
eventcache[o.event.pk] = settings
|
||||
|
||||
days = settings.get('mail_days_order_expire_warning', as_type=int)
|
||||
if days and (o.expires.date() - today).days <= days:
|
||||
o.expiry_reminder_sent = True
|
||||
o.save()
|
||||
try:
|
||||
mail(
|
||||
o.email, _('Your is about to expire: %(code)s') % {'code': o.code},
|
||||
settings.mail_text_order_expire_warning,
|
||||
{
|
||||
'event': o.event.name,
|
||||
'url': build_absolute_uri(o.event, 'presale:event.order', kwargs={
|
||||
'order': o.code,
|
||||
'secret': o.secret
|
||||
}),
|
||||
'expire_date': date_format(o.expires, 'SHORT_DATE_FORMAT')
|
||||
},
|
||||
o.event, locale=o.locale
|
||||
)
|
||||
except SendMailException:
|
||||
logger.exception('Reminder email could not be sent')
|
||||
else:
|
||||
o.log_action('pretix.event.order.expire_warning_sent')
|
||||
|
||||
|
||||
class OrderChangeManager:
|
||||
error_messages = {
|
||||
'free_to_paid': _('You cannot change a free order to a paid order.'),
|
||||
|
||||
@@ -227,6 +227,24 @@ we successfully received your payment for {event}. Thank you!
|
||||
You can change your order details and view the status of your order at
|
||||
{url}
|
||||
|
||||
Best regards,
|
||||
Your {event} team"""))
|
||||
},
|
||||
'mail_days_order_expire_warning': {
|
||||
'type': int,
|
||||
'default': '3'
|
||||
},
|
||||
'mail_text_order_expire_warning': {
|
||||
'type': LazyI18nString,
|
||||
'default': LazyI18nString.from_gettext(ugettext_noop("""Hello,
|
||||
|
||||
we did not yet receive a payment for your order for {event}.
|
||||
Please keep in mind that if we only guarantee your order if we receive
|
||||
your payment before {expire_date}.
|
||||
|
||||
You can view the payment information and the status of your order at
|
||||
{url}
|
||||
|
||||
Best regards,
|
||||
Your {event} team"""))
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user