Commit ef953020 authored by Patrick's avatar Patrick

Send email cleanup

parent c19cf06c
......@@ -57,15 +57,15 @@ def send_invoice(permanence_id):
})
html_content = template.render(context)
if producer.email2:
to = [producer.email, producer.email2]
to_email_producer = [producer.email, producer.email2]
else:
to = [producer.email]
to_email_producer = [producer.email]
email = EmailMultiAlternatives(
"%s - %s - %s - %s" % (
_('Payment'), permanence, REPANIER_SETTINGS_GROUP_NAME, long_profile_name),
strip_tags(html_content),
sender_email,
to
from_email=sender_email,
to=to_email_producer
)
email.attach_alternative(html_content, "text/html")
send_email(email=email)
......@@ -88,9 +88,9 @@ def send_invoice(permanence_id):
if Purchase.objects.filter(
permanence_id=permanence.id, customer_who_pays_id=customer.id
).order_by('?').exists():
email_customer = [customer.user.email, ]
to_email_customer = [customer.user.email]
if customer.email2 is not None and len(customer.email2.strip()) > 0:
email_customer.append(customer.email2)
to_email_customer.append(customer.email2)
try:
invoice_customer_mail = config.invoice_customer_mail
except TranslationDoesNotExist:
......@@ -123,8 +123,8 @@ def send_invoice(permanence_id):
"%s - %s - %s - %s" % (_('Invoice'), permanence, REPANIER_SETTINGS_GROUP_NAME,
long_basket_name),
strip_tags(html_content),
sender_email,
email_customer
from_email=sender_email,
to=to_email_customer
)
email.attach_alternative(html_content, "text/html")
send_email(email=email)
......
......@@ -62,14 +62,14 @@ def send_pre_open_order(permanence_id):
})
html_content = template.render(context)
if producer.email2:
to = [producer.email, producer.email2]
to_email_producer = [producer.email, producer.email2]
else:
to = [producer.email]
to_email_producer = [producer.email]
email = EmailMultiAlternatives(
"%s - %s - %s" % (_("Pre-opening of orders"), permanence, REPANIER_SETTINGS_GROUP_NAME),
strip_tags(html_content),
sender_email,
to,
from_email=sender_email,
to=to_email_producer,
cc=cc_email_staff
)
email.attach_alternative(html_content, "text/html")
......@@ -91,16 +91,17 @@ def send_open_order(permanence_id):
translation.activate(language_code)
permanence = Permanence.objects.get(id=permanence_id)
config = Configuration.objects.get(id=DECIMAL_ONE)
sender_email, sender_function, signature, cc_email_staff = get_signature(is_reply_to_order_email=True)
sender_email, sender_function, signature, to_email_staff = get_signature(is_reply_to_order_email=True)
to_email_customer = []
for customer in Customer.objects.filter(
is_active=True,
represent_this_buyinggroup=False,
may_order=True,
language=language_code
).order_by('?'):
cc_email_staff.append(customer.user.email)
to_email_customer.append(customer.user.email)
if customer.email2 is not None and len(customer.email2.strip()) > 0:
cc_email_staff.append(customer.email2)
to_email_customer.append(customer.email2)
try:
offer_description = permanence.offer_description
except TranslationDoesNotExist:
......@@ -138,8 +139,8 @@ def send_open_order(permanence_id):
email = EmailMultiAlternatives(
"%s - %s - %s" % (_("Opening of orders"), permanence, REPANIER_SETTINGS_GROUP_NAME),
strip_tags(html_content),
sender_email,
bcc=cc_email_staff
from_email=sender_email,
bcc=list(set(to_email_staff) | set(to_email_customer))
)
email.attach_alternative(html_content, "text/html")
send_email(email=email, track_customer_on_error=True)
......
......@@ -90,8 +90,8 @@ def email_order(permanence_id, all_producers=True, closed_deliveries_id=None, pr
"%s - %s - %s" % (
_('Permanence preparation list'), permanence, REPANIER_SETTINGS_GROUP_NAME),
strip_tags(html_content),
sender_email,
to_email_board,
from_email=sender_email,
to=to_email_board,
cc=cc_email_staff
)
if group_wb is not None:
......@@ -170,9 +170,9 @@ def email_order(permanence_id, all_producers=True, closed_deliveries_id=None, pr
email = EmailMultiAlternatives(
subject,
strip_tags(html_content),
sender_email,
to,
cc
from_email=sender_email,
to=to,
cc=cc
)
if REPANIER_SETTINGS_SEND_ORDER_MAIL_TO_PRODUCER and wb is not None:
if REPANIER_SETTINGS_SEND_ABSTRACT_ORDER_MAIL_TO_PRODUCER:
......@@ -241,19 +241,19 @@ def export_order_2_1_customer(customer, filename, permanence, sender_email, send
wb = xlsx_order.export_customer(permanence=permanence, customer=customer, xlsx_formula=False, wb=None)
if wb is not None:
email_customer = [customer.user.email, ]
to_email_customer = [customer.user.email]
if cancel_order or REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
email_customer.append(sender_email)
if customer.email2 is not None and len(customer.email2.strip()) > 0:
email_customer.append(customer.email2)
to_email_customer.append(sender_email)
if customer.email2:
to_email_customer.append(customer.email2)
if customer_invoice.delivery is not None:
delivery_point = customer_invoice.delivery
if delivery_point.delivery_point.customer_responsible is not None:
customer_responsible = delivery_point.delivery_point.customer_responsible
if customer_responsible.id != customer.id:
email_customer.append(customer_responsible.user.email)
if customer_responsible.email2 is not None and len(customer_responsible.email2.strip()) > 0:
email_customer.append(customer_responsible.email2)
to_email_customer.append(customer_responsible.user.email)
if customer_responsible.email2:
to_email_customer.append(customer_responsible.email2)
else:
delivery_point = EMPTY_STRING
customer_last_balance, customer_on_hold_movement, customer_payment_needed, customer_order_amount = payment_message(
......@@ -297,8 +297,8 @@ def export_order_2_1_customer(customer, filename, permanence, sender_email, send
email = EmailMultiAlternatives(
subject,
strip_tags(html_content),
sender_email,
email_customer
from_email=sender_email,
to=to_email_customer
)
if not cancel_order and REPANIER_SETTINGS_SEND_ABSTRACT_ORDER_MAIL_TO_CUSTOMER:
if abstract_ws is not None:
......
......@@ -45,9 +45,9 @@ def send_mail_to_all_members_view(request):
email = EmailMessage(
strip_tags(form.cleaned_data.get('subject')),
strip_tags(form.cleaned_data.get('message')),
settings.DEFAULT_FROM_EMAIL,
to,
cc=to_email_customer
from_email=settings.DEFAULT_FROM_EMAIL,
to=to,
bcc=to_email_customer
)
send_email(email=email)
return HttpResponseRedirect('/') # Redirect after POST
......
......@@ -32,12 +32,12 @@ def send_mail_to_coordinators_view(request):
if form.cleaned_data.get('staff_%d' % staff.id):
to_email_staff.append(staff.user.email)
if len(to_email_staff) > 0:
to = (request.user.email,)
to_email_customer = [request.user.email]
email = EmailMessage(
strip_tags(form.cleaned_data.get('subject')),
strip_tags(form.cleaned_data.get('message')),
settings.DEFAULT_FROM_EMAIL,
to,
from_email=settings.DEFAULT_FROM_EMAIL,
to=to_email_customer,
cc=to_email_staff
)
send_email(email=email)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment