From 21c21969f20f9692c4a765cdf3d249760e378aff Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Fri, 6 Apr 2018 08:02:01 +0200 Subject: [PATCH] lingo: update new invoices email's context with template vars (#23138) --- combo/apps/lingo/models.py | 6 ++++-- .../lingo/combo/invoice_email_notification_body.html | 12 ++++++------ .../lingo/combo/invoice_email_notification_body.txt | 10 +++++----- .../combo/invoice_email_notification_subject.txt | 2 +- tests/test_lingo_remote_regie.py | 7 ++++++- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py index 3bcb565a..eae30841 100644 --- a/combo/apps/lingo/models.py +++ b/combo/apps/lingo/models.py @@ -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) diff --git a/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.html b/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.html index 16bb059c..a126cb79 100644 --- a/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.html +++ b/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.html @@ -2,15 +2,15 @@ -

{% 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 }}. +

{% 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 %}

- {% if item.online_payment %} + {% if invoice.online_payment %}

{% blocktrans %}You can view and pay it online.{% endblocktrans %}

{% else %} -

{% blocktrans %}You can view it by going on your {{ site_title }}.{% endblocktrans %}

- {% if item.no_online_payment_reason == 'autobilling' %} -

{% blocktrans with debit_date=item.payment_limit_date|date:"DATE_FORMAT" %} +

{% blocktrans %}You can view it by going on your Combo.{% 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 %}

diff --git a/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.txt b/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.txt index 7b562fb7..24fc84f5 100644 --- a/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.txt +++ b/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_body.txt @@ -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 %} diff --git a/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_subject.txt b/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_subject.txt index 83c802e7..47726134 100644 --- a/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_subject.txt +++ b/combo/apps/lingo/templates/lingo/combo/invoice_email_notification_subject.txt @@ -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 %} diff --git a/tests/test_lingo_remote_regie.py b/tests/test_lingo_remote_regie.py index 8d3fee8a..98381b7a 100644 --- a/tests/test_lingo_remote_regie.py +++ b/tests/test_lingo_remote_regie.py @@ -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'