mirror of
https://github.com/pretix/pretix.git
synced 2026-08-28 13:34:40 +00:00
Fix and improve sendmail logic
This commit is contained in:
@@ -191,15 +191,13 @@ class ScheduledMail(models.Model):
|
|||||||
positions = [p for p in positions if p.subevent_id == self.subevent_id]
|
positions = [p for p in positions if p.subevent_id == self.subevent_id]
|
||||||
|
|
||||||
parent_op = None
|
parent_op = None
|
||||||
sent_to_parent_positions = set()
|
sent_to_positions = set()
|
||||||
for p in positions:
|
for p in positions:
|
||||||
|
|
||||||
if p.addon_to_id is None:
|
if p.addon_to_id is None:
|
||||||
parent_op = p
|
parent_op = p
|
||||||
if not self.rule.all_products and p.item_id not in position_ids:
|
if not self.rule.all_products and p.item_id not in position_ids:
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
sent_to_parent_positions.add(p.id)
|
|
||||||
|
|
||||||
if p.id in position_ids:
|
if p.id in position_ids:
|
||||||
mail_to_parent = False
|
mail_to_parent = False
|
||||||
@@ -208,13 +206,12 @@ class ScheduledMail(models.Model):
|
|||||||
if p.addon_to_id is not None:
|
if p.addon_to_id is not None:
|
||||||
# without attendee-email
|
# without attendee-email
|
||||||
if not p.attendee_email:
|
if not p.attendee_email:
|
||||||
if p.addon_to_id in sent_to_parent_positions:
|
if p.addon_to_id in sent_to_positions:
|
||||||
continue
|
continue
|
||||||
elif parent_op.attendee_email:
|
elif parent_op.attendee_email:
|
||||||
sent_to_parent_positions.add(parent_op.id)
|
|
||||||
mail_to_parent = True
|
mail_to_parent = True
|
||||||
# with attendee-email but same as parent's and sent to parent
|
# with attendee-email but same as parent's and sent to parent
|
||||||
elif parent_op.attendee_email and p.attendee_email == parent_op.attendee_email and parent_op in sent_to_parent_positions:
|
elif parent_op.attendee_email and p.attendee_email == parent_op.attendee_email and parent_op in sent_to_positions:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if p.attendee_email and (p.attendee_email != o.email or not o_sent):
|
if p.attendee_email and (p.attendee_email != o.email or not o_sent):
|
||||||
@@ -228,6 +225,7 @@ class ScheduledMail(models.Model):
|
|||||||
p.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
p.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
||||||
attach_ical=self.rule.attach_ical,
|
attach_ical=self.rule.attach_ical,
|
||||||
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
|
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
|
||||||
|
sent_to_positions.add(p.id)
|
||||||
elif mail_to_parent and (parent_op.attendee_email != o.email or not o_sent):
|
elif mail_to_parent and (parent_op.attendee_email != o.email or not o_sent):
|
||||||
email_ctx = get_email_context(
|
email_ctx = get_email_context(
|
||||||
event=e,
|
event=e,
|
||||||
@@ -239,6 +237,7 @@ class ScheduledMail(models.Model):
|
|||||||
parent_op.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
parent_op.send_mail(self.rule.subject, self.rule.template, email_ctx,
|
||||||
attach_ical=self.rule.attach_ical,
|
attach_ical=self.rule.attach_ical,
|
||||||
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
|
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
|
||||||
|
sent_to_positions.add(parent_op.id)
|
||||||
elif not o_sent and o.email:
|
elif not o_sent and o.email:
|
||||||
email_ctx = get_email_context(
|
email_ctx = get_email_context(
|
||||||
event=e,
|
event=e,
|
||||||
@@ -262,7 +261,7 @@ class Rule(models.Model, LoggingMixin):
|
|||||||
SEND_TO_CHOICES = [
|
SEND_TO_CHOICES = [
|
||||||
(CUSTOMERS, _("Everyone who created a ticket order")),
|
(CUSTOMERS, _("Everyone who created a ticket order")),
|
||||||
(ATTENDEES,
|
(ATTENDEES,
|
||||||
_("Every attendee (falling back to the order contact when no attendee email address is given or the ticket's contact in the case of add-ons)")),
|
_("Every attendee (falling back to the order contact when no attendee email address is given)")),
|
||||||
(BOTH, _('Both (all order contact addresses and all attendee email addresses)'))
|
(BOTH, _('Both (all order contact addresses and all attendee email addresses)'))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
|||||||
ia = InvoiceAddress(order=o)
|
ia = InvoiceAddress(order=o)
|
||||||
|
|
||||||
parent_op = None
|
parent_op = None
|
||||||
sent_to_parent_positions = set()
|
sent_to_positions = set()
|
||||||
if recipients in ('both', 'attendees'):
|
if recipients in ('both', 'attendees'):
|
||||||
for p in o.positions.annotate(
|
for p in o.positions.annotate(
|
||||||
any_checkins=Exists(
|
any_checkins=Exists(
|
||||||
@@ -105,27 +105,25 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
|||||||
if not allowed:
|
if not allowed:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
send_to_email = ''
|
send_to_parent = False
|
||||||
|
|
||||||
if not p.attendee_email:
|
if not p.attendee_email:
|
||||||
if recipients == 'attendees':
|
if recipients == 'attendees':
|
||||||
if is_addon:
|
if is_addon:
|
||||||
if p.addon_to_id in sent_to_parent_positions:
|
if p.addon_to_id in sent_to_positions:
|
||||||
continue
|
continue
|
||||||
elif parent_op and parent_op.id == p.addon_to_id and parent_op.attendee_email:
|
elif parent_op and parent_op.id == p.addon_to_id and parent_op.attendee_email:
|
||||||
send_to_email = parent_op.attendee_email
|
send_to_parent = True
|
||||||
else:
|
else:
|
||||||
send_to_order = True
|
send_to_order = True
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
send_to_order = True
|
send_to_order = True
|
||||||
continue
|
continue
|
||||||
elif is_addon and p.addon_to_id in sent_to_parent_positions and p.attendee_email == parent_op.attendee_email:
|
# add-on's attendee-email is the same as parent's and sent to parent
|
||||||
|
elif is_addon and p.addon_to_id in sent_to_positions and p.attendee_email == parent_op.attendee_email:
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
send_to_email = p.attendee_email
|
|
||||||
|
|
||||||
if send_to_email == o.email and send_to_order:
|
if p.attendee_email and p.attendee_email == o.email and send_to_order:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if subevent and p.subevent_id != subevent:
|
if subevent and p.subevent_id != subevent:
|
||||||
@@ -138,27 +136,50 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
with language(o.locale, event.settings.region):
|
with language(o.locale, event.settings.region):
|
||||||
email_context = get_email_context(event=event, order=o, invoice_address=ia, position=p)
|
if send_to_parent:
|
||||||
outgoing_mail = mail(
|
email_context = get_email_context(event=event, order=o, invoice_address=ia, position=parent_op)
|
||||||
send_to_email,
|
outgoing_mail = mail(
|
||||||
subject,
|
parent_op.attendee_email,
|
||||||
message,
|
subject,
|
||||||
email_context,
|
message,
|
||||||
event,
|
email_context,
|
||||||
locale=o.locale,
|
event,
|
||||||
order=o,
|
locale=o.locale,
|
||||||
position=p,
|
order=o,
|
||||||
attach_tickets=attach_tickets,
|
position=parent_op,
|
||||||
attach_ical=attach_ical,
|
attach_tickets=attach_tickets,
|
||||||
attach_cached_files=attachments
|
attach_ical=attach_ical,
|
||||||
)
|
attach_cached_files=attachments
|
||||||
if outgoing_mail:
|
|
||||||
o.log_action(
|
|
||||||
'pretix.plugins.sendmail.order.email.sent.attendee',
|
|
||||||
user=user,
|
|
||||||
data=outgoing_mail.log_data(),
|
|
||||||
)
|
)
|
||||||
sent_to_parent_positions.add(p.id)
|
if outgoing_mail:
|
||||||
|
o.log_action(
|
||||||
|
'pretix.plugins.sendmail.order.email.sent.attendee',
|
||||||
|
user=user,
|
||||||
|
data=outgoing_mail.log_data(),
|
||||||
|
)
|
||||||
|
sent_to_positions.add(parent_op.id)
|
||||||
|
else:
|
||||||
|
email_context = get_email_context(event=event, order=o, invoice_address=ia, position=p)
|
||||||
|
outgoing_mail = mail(
|
||||||
|
p.attendee_email,
|
||||||
|
subject,
|
||||||
|
message,
|
||||||
|
email_context,
|
||||||
|
event,
|
||||||
|
locale=o.locale,
|
||||||
|
order=o,
|
||||||
|
position=p,
|
||||||
|
attach_tickets=attach_tickets,
|
||||||
|
attach_ical=attach_ical,
|
||||||
|
attach_cached_files=attachments
|
||||||
|
)
|
||||||
|
if outgoing_mail:
|
||||||
|
o.log_action(
|
||||||
|
'pretix.plugins.sendmail.order.email.sent.attendee',
|
||||||
|
user=user,
|
||||||
|
data=outgoing_mail.log_data(),
|
||||||
|
)
|
||||||
|
sent_to_positions.add(p.id)
|
||||||
|
|
||||||
if send_to_order and o.email:
|
if send_to_order and o.email:
|
||||||
with language(o.locale, event.settings.region):
|
with language(o.locale, event.settings.region):
|
||||||
|
|||||||
Reference in New Issue
Block a user