lingo: display amount_paid in invoice listing (#40364)

This commit is contained in:
Lauréline Guérin 2020-03-03 10:25:03 +01:00
parent 89ebef5aba
commit 72fe08ea5e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 40 additions and 2 deletions

View File

@ -688,6 +688,7 @@ class Items(CellBase):
ctx.update({
'items': items,
'with_payment_limit_date': any(i.payment_limit_date for i in items),
'with_amount_paid': any(getattr(i, 'amount_paid', None) for i in items),
})
return ctx

View File

@ -12,6 +12,9 @@
<th class="invoice-creation-date">{% trans "Issue date" %}</th>
{% if with_payment_limit_date %}<th class="invoice-payment-limit-date">{% trans "Payment limit date" %}</th>{% endif %}
<th class="invoice-amount">{% trans "Amount" %}</th>
{% if with_amount_paid %}
<th class="invoice-amount-paid">{% trans "Amount already paid" %}</th>
{% endif %}
<td></td>
</tr>
</thead>
@ -22,10 +25,21 @@
<td class="invoice-subject">{{ item.subject }}</td>
<td class="invoice-creation-date">{{ item.creation_date|date:"SHORT_DATE_FORMAT" }}</td>
{% if with_payment_limit_date %}<td class="invoice-payment-limit-date">{{ item.payment_limit_date|date:"SHORT_DATE_FORMAT" }}</td>{% endif %}
{% if with_amount_paid %}
<td class="invoice-amount amount">{% if item.amount %}{% blocktrans with amount=item.amount|floatformat:"2" %}
{{ amount }}€
{% endblocktrans %}{% endif %}
</td>
<td class="invoice-amount-paid amount">{% if item.amount_paid %}{% blocktrans with amount=item.amount_paid|floatformat:"2" %}
{{ amount }}€
{% endblocktrans %}{% endif %}
</td>
{% else %}
<td class="invoice-amount amount">{% blocktrans with amount=item.total_amount|floatformat:"2" %}
{{ amount }}€
{% endblocktrans %}
</td>
{% endif %}
{% if item.regie.is_remote %}
<td>
<a href="{% url 'view-item' regie_id=item.regie.pk item_crypto_id=item.crypto_id %}?page={{ cell.page.pk }}" rel="popup" class="icon-view">{% trans "View" %}

View File

@ -163,10 +163,33 @@ def test_remote_regie_past_invoices_cell(mock_send, remote_regie):
mock_response.json.return_value = ws_invoices
mock_send.return_value = mock_response
content = cell.render(context)
assert 'F-2016-One' in content
assert '123.45' in content
assert 'class="invoice-payment-limit-date"' not in content
# invoice with amount_paid
invoices = copy.deepcopy(INVOICES)
invoices[0]['amount'] = '100.00'
invoices[0]['amount_paid'] = '23.45'
ws_invoices = {'err': 0, 'data': invoices}
mock_response = mock.Mock(status_code=200, content=json.dumps(ws_invoices))
mock_response.json.return_value = ws_invoices
mock_send.return_value = mock_response
content = cell.render(context)
assert '100.00' in content
assert '23.45' in content
assert 'class="invoice-amount-paid"' in content
# invoice with zero amount_paid
invoices = copy.deepcopy(INVOICES)
invoices[0]['amount'] = '123.45'
invoices[0]['amount_paid'] = '0.00'
ws_invoices = {'err': 0, 'data': invoices}
mock_response = mock.Mock(status_code=200, content=json.dumps(ws_invoices))
mock_response.json.return_value = ws_invoices
mock_send.return_value = mock_response
content = cell.render(context)
assert '123.45' in content
assert 'class="invoice-amount-paid"' not in content
# check if regie webservice has been correctly called
assert mock_send.call_args[0][0].method == 'GET'
url = mock_send.call_args[0][0].url