Projet

Général

Profil

0002-lingo-do-not-display-pay-limit-date-column-if-not-pr.patch

Lauréline Guérin, 25 février 2020 14:48

Télécharger (3,57 ko)

Voir les différences:

Subject: [PATCH 2/2] lingo: do not display pay limit date column if not
 provided (#40170)

 combo/apps/lingo/models.py                        |  5 ++++-
 combo/apps/lingo/templates/lingo/combo/items.html |  4 ++--
 tests/test_lingo_remote_regie.py                  | 13 +++++++++++++
 3 files changed, 19 insertions(+), 3 deletions(-)
combo/apps/lingo/models.py
685 685
        items = self.get_invoices(user=context['user'])
686 686
        none_date = datetime.datetime(1900, 1, 1)  # to avoid None-None comparison errors
687 687
        items.sort(key=lambda i: i.creation_date or none_date, reverse=True)
688
        ctx.update({'items': items})
688
        ctx.update({
689
            'items': items,
690
            'with_payment_limit_date': any(i.payment_limit_date for i in items),
691
        })
689 692
        return ctx
690 693

  
691 694
    def render(self, context):
combo/apps/lingo/templates/lingo/combo/items.html
10 10
      <th class="invoice-id">{% trans "Number" %}</th>
11 11
      <th class="invoice-subject">{% trans "Label" %}</th>
12 12
      <th class="invoice-creation-date">{% trans "Issue date" %}</th>
13
      <th class="invoice-payment-limit-date">{% trans "Payment limit date" %}</th>
13
      {% if with_payment_limit_date %}<th class="invoice-payment-limit-date">{% trans "Payment limit date" %}</th>{% endif %}
14 14
      <th class="invoice-amount">{% trans "Amount" %}</th>
15 15
      <td></td>
16 16
    </tr>
......
21 21
    <td class="invoice-id">{{ item.display_id }}</td>
22 22
    <td class="invoice-subject">{{ item.subject }}</td>
23 23
    <td class="invoice-creation-date">{{ item.creation_date|date:"SHORT_DATE_FORMAT" }}</td>
24
    <td class="invoice-payment-limit-date">{{ item.payment_limit_date|date:"SHORT_DATE_FORMAT" }}</td>
24
    {% if with_payment_limit_date %}<td class="invoice-payment-limit-date">{{ item.payment_limit_date|date:"SHORT_DATE_FORMAT" }}</td>{% endif %}
25 25
    <td class="invoice-amount amount">{% blocktrans with amount=item.total_amount|floatformat:"2" %}
26 26
      {{ amount }}€
27 27
      {% endblocktrans %}
tests/test_lingo_remote_regie.py
153 153
    content = cell.render(context)
154 154
    assert 'F-2016-One' in content
155 155
    assert '123.45' in content
156
    assert 'class="invoice-payment-limit-date"' in content
157

  
158
    # invoice without limit date
159
    invoices = copy.deepcopy(INVOICES)
160
    invoices[0]['pay_limit_date'] = ''
161
    ws_invoices = {'err': 0, 'data': invoices}
162
    mock_response = mock.Mock(status_code=200, content=json.dumps(ws_invoices))
163
    mock_response.json.return_value = ws_invoices
164
    mock_send.return_value = mock_response
165
    content = cell.render(context)
166
    assert 'F-2016-One' in content
167
    assert '123.45' in content
168
    assert 'class="invoice-payment-limit-date"' not in content
156 169

  
157 170
    # check if regie webservice has been correctly called
158 171
    assert mock_send.call_args[0][0].method == 'GET'
159
-