Allow to disable some e-mails depending on sales channel (#1726)

Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
Raphael Michel
2020-07-28 09:26:18 +02:00
committed by GitHub
12 changed files with 137 additions and 11 deletions

View File

@@ -0,0 +1,39 @@
# Generated by Django 3.0.8 on 2020-07-24 09:05
from django.db import migrations
from pretix.base.channels import get_all_sales_channels
def set_sales_channels(apps, schema_editor):
# We now allow restricting some mails to certain sales channels
# The default is changing from all channels to "web" only
# Therefore, for existing events, we enable all sales channels
Event_SettingsStore = apps.get_model('pretixbase', 'Event_SettingsStore')
Event = apps.get_model('pretixbase', 'Event')
all_sales_channels = "[" + ", ".join('"' + sc + '"' for sc in get_all_sales_channels()) + "]"
batch_size = 1000
Event_SettingsStore.objects.bulk_create([
Event_SettingsStore(
object=event,
key="mail_sales_channel_placed_paid",
value=all_sales_channels)
for event in Event.objects.all()
], batch_size=batch_size)
Event_SettingsStore.objects.bulk_create([
Event_SettingsStore(
object=event,
key="mail_sales_channel_download_reminder",
value=all_sales_channels)
for event in Event.objects.all()
], batch_size=batch_size)
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0158_auto_20200724_0754'),
]
operations = [
migrations.RunPython(set_sales_channels, migrations.RunPython.noop),
]

View File

@@ -1491,7 +1491,7 @@ class OrderPayment(models.Model):
trigger_pdf=not send_mail or not self.order.event.settings.invoice_email_attachment
)
if send_mail:
if send_mail and self.order.sales_channel in self.order.event.settings.mail_sales_channel_placed_paid:
self._send_paid_mail(invoice, user, mail_text)
if self.order.event.settings.mail_send_order_paid_attendee:
for p in self.order.positions.all():

View File

@@ -960,11 +960,12 @@ def _perform_order(event: Event, payment_provider: str, position_ids: List[str],
email_attendees = event.settings.mail_send_order_placed_attendee
email_attendees_template = event.settings.mail_text_order_placed_attendee
_order_placed_email(event, order, pprov, email_template, log_entry, invoice, payment)
if email_attendees:
for p in order.positions.all():
if p.addon_to_id is None and p.attendee_email and p.attendee_email != order.email:
_order_placed_email_attendee(event, order, p, email_attendees_template, log_entry)
if sales_channel in event.settings.mail_sales_channel_placed_paid:
_order_placed_email(event, order, pprov, email_template, log_entry, invoice, payment)
if email_attendees:
for p in order.positions.all():
if p.addon_to_id is None and p.attendee_email and p.attendee_email != order.email:
_order_placed_email_attendee(event, order, p, email_attendees_template, log_entry)
return order.id
@@ -1056,6 +1057,9 @@ def send_download_reminders(sender, **kwargs):
if days is None:
continue
if o.sales_channel not in event.settings.mail_sales_channel_download_reminder:
continue
reminder_date = (o.first_date - timedelta(days=days)).replace(hour=0, minute=0, second=0, microsecond=0)
if now() < reminder_date or o.datetime > reminder_date:
continue

View File

@@ -1190,6 +1190,14 @@ DEFAULTS = {
"Defaults to your event name."),
)
},
'mail_sales_channel_placed_paid': {
'default': ['web'],
'type': list,
},
'mail_sales_channel_download_reminder': {
'default': ['web'],
'type': list,
},
'mail_text_signature': {
'type': LazyI18nString,
'default': ""