lingo: display amount_paid if provided (#40170)

This commit is contained in:
Lauréline Guérin 2020-02-25 14:05:28 +01:00
parent 3662751240
commit 7e81814aa5
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 30 additions and 1 deletions

View File

@ -80,6 +80,7 @@ def build_remote_item(data, regie):
display_id=data.get('display_id'),
total_amount=data.get('total_amount'),
amount=data.get('amount'),
amount_paid=data.get('amount_paid'),
subject=data.get('label'),
has_pdf=data.get('has_pdf'),
online_payment=data.get('online_payment'),
@ -410,7 +411,7 @@ class RemoteItem(object):
payment_date = None
def __init__(self, id, regie, creation_date, payment_limit_date,
total_amount, amount, display_id, subject, has_pdf,
total_amount, amount, amount_paid, display_id, subject, has_pdf,
online_payment, paid, payment_date, no_online_payment_reason):
self.id = id
self.regie = regie
@ -418,6 +419,8 @@ class RemoteItem(object):
self.payment_limit_date = dateparse.parse_date(payment_limit_date)
self.total_amount = Decimal(total_amount)
self.amount = Decimal(amount)
if amount_paid:
self.amount_paid = Decimal(amount_paid)
self.display_id = display_id or self.id
self.subject = subject
self.has_pdf = has_pdf

View File

@ -27,6 +27,13 @@
{% endblocktrans %}
</div>
{% endif %}
{% if item.amount_paid %}
<div class="amount_paid">
{% blocktrans with amount=item.amount_paid|floatformat:"2" %}
Amount already paid: <span class="amount">{{ amount }}€</span>
{% endblocktrans %}
</div>
{% endif %}
<div class="issued">{% trans "Issue date:" %} <span class="timestamp">{{ item.creation_date|date:"SHORT_DATE_FORMAT" }}</span></div>
{% if item.payment_limit_date %}
<div class="invoice-payment-limit-date">{% trans "Payment due date:" %}

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import copy
import json
import pytest
import mock
@ -178,11 +179,29 @@ def test_remote_regie_past_invoices_cell(mock_send, remote_regie):
def test_anonymous_successful_item_payment(mock_get, mock_pay_invoice, app, remote_regie):
assert remote_regie.is_remote() == True
encrypt_id = aes_hex_encrypt(settings.SECRET_KEY, 'F201601')
# invoice with amount_paid
invoices = copy.deepcopy(INVOICES)
invoices[0]['amount'] = '100.00'
invoices[0]['amount_paid'] = '23.45'
mock_json = mock.Mock()
mock_json.json.return_value = {'err': 0, 'data': invoices[0]}
mock_get.return_value = mock_json
mock_pay_invoice.return_value = mock.Mock(status_code=200)
resp = app.get('/lingo/item/%s/%s/' % (remote_regie.id, encrypt_id))
assert 'Total amount: <span class="amount">123.45€</span>' in resp.text
assert 'Amount to pay: <span class="amount">100.00€</span>' in resp.text
assert 'Amount already paid: <span class="amount">23.45€</span>' in resp.text
# invoice without amount_paid
mock_json = mock.Mock()
mock_json.json.return_value = {'err': 0, 'data': INVOICES[0]}
mock_get.return_value = mock_json
mock_pay_invoice.return_value = mock.Mock(status_code=200)
resp = app.get('/lingo/item/%s/%s/' % (remote_regie.id, encrypt_id))
assert 'Total amount: <span class="amount">123.45€</span>' in resp.text
assert 'Amount to pay: <span class="amount">123.45€</span>' in resp.text
assert 'Amount already paid>' not in resp.text
form = resp.form
assert 'email' in form.fields