lingo: do not display pay limit date column if not provided (#40170)

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

View File

@ -685,7 +685,10 @@ class Items(CellBase):
items = self.get_invoices(user=context['user'])
none_date = datetime.datetime(1900, 1, 1) # to avoid None-None comparison errors
items.sort(key=lambda i: i.creation_date or none_date, reverse=True)
ctx.update({'items': items})
ctx.update({
'items': items,
'with_payment_limit_date': any(i.payment_limit_date for i in items),
})
return ctx
def render(self, context):

View File

@ -10,7 +10,7 @@
<th class="invoice-id">{% trans "Number" %}</th>
<th class="invoice-subject">{% trans "Label" %}</th>
<th class="invoice-creation-date">{% trans "Issue date" %}</th>
<th class="invoice-payment-limit-date">{% trans "Payment limit 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>
<td></td>
</tr>
@ -21,7 +21,7 @@
<td class="invoice-id">{{ item.display_id }}</td>
<td class="invoice-subject">{{ item.subject }}</td>
<td class="invoice-creation-date">{{ item.creation_date|date:"SHORT_DATE_FORMAT" }}</td>
<td class="invoice-payment-limit-date">{{ item.payment_limit_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 %}
<td class="invoice-amount amount">{% blocktrans with amount=item.total_amount|floatformat:"2" %}
{{ amount }}€
{% endblocktrans %}

View File

@ -153,6 +153,19 @@ def test_remote_regie_past_invoices_cell(mock_send, remote_regie):
content = cell.render(context)
assert 'F-2016-One' in content
assert '123.45' in content
assert 'class="invoice-payment-limit-date"' in content
# invoice without limit date
invoices = copy.deepcopy(INVOICES)
invoices[0]['pay_limit_date'] = ''
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 'F-2016-One' in content
assert '123.45' in content
assert 'class="invoice-payment-limit-date"' not in content
# check if regie webservice has been correctly called
assert mock_send.call_args[0][0].method == 'GET'