lingo: update new invoices email's context with template vars (#23138)

This commit is contained in:
Serghei Mihai 2018-04-06 08:02:01 +02:00
parent b493ae7406
commit 21c21969f2
5 changed files with 22 additions and 15 deletions

View File

@ -292,8 +292,10 @@ class Regie(models.Model):
payment_url = reverse('view-item', kwargs={'regie_id': self.id,
'item_crypto_id': invoice.crypto_id})
ctx = {'item': invoice}
ctx.update({'payment_url': urlparse.urljoin(settings.SITE_BASE_URL, payment_url)})
ctx = settings.TEMPLATE_VARS.copy()
ctx['invoice'] = invoice
ctx['payment_url'] = urlparse.urljoin(settings.SITE_BASE_URL, payment_url)
ctx['portal_url'] = settings.SITE_BASE_URL
subject = render_to_string([subject_template], ctx).strip()
text_body = render_to_string([text_body_template], ctx)
html_body = render_to_string([html_body_template], ctx)

View File

@ -2,15 +2,15 @@
<html>
<body style="max-width: 60em">
<p>{% blocktrans with id=item.id creation_date=item.creation_date|date:"DATE_FORMAT" amount=item.amount %}
We inform you that your invoice nr. {{ id }} issued on {{ creation_date }} of amount of {{ amount }}€ is available on {{ site_title }}.
<p>{% blocktrans with id=invoice.id creation_date=invoice.creation_date|date:"DATE_FORMAT" amount=invoice.amount %}
We inform you that your invoice nr. {{ id }} issued on {{ creation_date }} of amount of {{ amount }}€ is available on Combo.
{% endblocktrans %}</p>
{% if item.online_payment %}
{% if invoice.online_payment %}
<p>{% blocktrans %}You can <a href="{{ payment_url }}">view and pay it online</a>.{% endblocktrans %}</p>
{% else %}
<p>{% blocktrans %}You can view it by going on your <a href="{{ portal_url }}">{{ site_title }}</a>.{% endblocktrans %}</p>
{% if item.no_online_payment_reason == 'autobilling' %}
<p>{% blocktrans with debit_date=item.payment_limit_date|date:"DATE_FORMAT" %}
<p>{% blocktrans %}You can view it by going on your <a href="{{ portal_url }}">Combo</a>.{% endblocktrans %}</p>
{% if invoice.no_online_payment_reason == 'autobilling' %}
<p>{% blocktrans with debit_date=invoice.payment_limit_date|date:"DATE_FORMAT" %}
The amount of this invoice will be debited from your account at {{ debit_date }}.
{% endblocktrans %}
</p>

View File

@ -1,13 +1,13 @@
{% load i18n %}
{% blocktrans with id=item.id creation_date=item.creation_date|date:"DATE_FORMAT" amount=item.amount %}
{% blocktrans with id=invoice.id creation_date=invoice.creation_date|date:"DATE_FORMAT" amount=invoice.amount %}
We inform you that your invoice nr. {{ id }} issued on {{ creation_date }} of amount
of {{ amount }}€ is available on {{ site_title }}.{% endblocktrans %}
of {{ amount }}€ is available on Combo.{% endblocktrans %}
{% if item.online_payment %}{% blocktrans %}You can view and pay it online on {{ payment_url }}.{% endblocktrans %}
{% if invoice.online_payment %}{% blocktrans %}You can view and pay it online on {{ payment_url }}.{% endblocktrans %}
{% else %}{% blocktrans %}You can view it by going on {{ portal_url }}.{% endblocktrans %}
{% if item.no_online_payment_reason == 'autobilling' %}
{% blocktrans with debit_date=item.payment_limit_date|date:"DATE_FORMAT" %}The amount of this invoice will be debited from your account at {{ debit_date }}.{% endblocktrans %}
{% if invoice.no_online_payment_reason == 'autobilling' %}
{% blocktrans with debit_date=invoice.payment_limit_date|date:"DATE_FORMAT" %}The amount of this invoice will be debited from your account at {{ debit_date }}.{% endblocktrans %}
{% endif %}
{% endif %}

View File

@ -1,4 +1,4 @@
{% load i18n %}
{% blocktrans with invoice_id=item.id %}
{% blocktrans with invoice_id=invoice.id %}
New invoice nr. {{ invoice_id }} is available
{% endblocktrans %}

View File

@ -395,7 +395,7 @@ def test_send_new_remote_invoices_by_email(mock_get, user_saml, admin, app, remo
pay_limit_date = (invoice_now + timedelta(days=30)).date().isoformat()
FAKE_PENDING_INVOICES = {
'data' : {'foo': {'invoices': [{'id': '01', 'label': '010101', 'paid': False,
'amount': '37.26', 'total_amount': '37.26', 'online_payment': True,
'amount': '37.26', 'total_amount': '37.26', 'online_payment': False,
'has_pdf': True, 'created': creation_date,
'pay_limit_date': pay_limit_date}]},
}
@ -408,5 +408,10 @@ def test_send_new_remote_invoices_by_email(mock_get, user_saml, admin, app, remo
assert mailoutbox[0].recipients() == ['foo@example.net']
assert mailoutbox[0].from_email == settings.DEFAULT_FROM_EMAIL
assert mailoutbox[0].subject == 'New invoice nr. 01 is available'
html_message = mailoutbox[0].alternatives[0][0]
assert 'Combo' in mailoutbox[0].body
assert 'Combo' in html_message
assert 'http://localhost' in mailoutbox[0].body
assert 'http://localhost' in html_message
assert mailoutbox[0].attachments[0][0] == '01.pdf'
assert mailoutbox[0].attachments[0][2] == 'application/pdf'