invoicing: display invoices and their lines on pool detail page (#73514)
This commit is contained in:
parent
9f85afd377
commit
49ebe18ee5
|
@ -22,4 +22,19 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div>
|
||||
{% for line in lines %}
|
||||
{% ifchanged line.invoice_id %}
|
||||
{% if not forloop.first %}</ul>{% endif %}
|
||||
<h3 data-invoice-id="{{ line.invoice_id }}">
|
||||
{% blocktrans with number=line.invoice_id payer=line.invoice.payer amount=line.invoice.total_amount %}Invoice #{{ number }} addressed to {{ payer }}, amount {{ amount }}€{% endblocktrans %}
|
||||
</h3>
|
||||
<ul class="objects-list" data-invoice-id="{{ line.invoice_id }}">
|
||||
{% endifchanged %}
|
||||
<li>
|
||||
#{{ line.pk }} {{ line.user_name }} - {{ line.label }} ({{ line.total_amount }})
|
||||
</li>
|
||||
{% if forloop.last %}</ul>{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -314,6 +314,11 @@ class PoolDetailView(DetailView):
|
|||
self.object.error_count = len([line for line in all_lines if line.status == 'error'])
|
||||
self.object.warning_count = len([line for line in all_lines if line.status == 'warning'])
|
||||
self.object.success_count = len([line for line in all_lines if line.status == 'success'])
|
||||
kwargs['lines'] = (
|
||||
all_lines.filter(invoice__isnull=False)
|
||||
.select_related('invoice')
|
||||
.order_by('invoice__pk', 'user_external_id', 'pk')
|
||||
)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -441,6 +441,113 @@ def test_detail_pool(app, admin_user):
|
|||
assert 'tag-error' not in resp
|
||||
|
||||
|
||||
def test_detail_pool_invoices(app, admin_user):
|
||||
campaign = Campaign.objects.create(
|
||||
date_start=datetime.date(2022, 9, 1),
|
||||
date_end=datetime.date(2022, 10, 1),
|
||||
date_issue=datetime.date(2022, 10, 31),
|
||||
)
|
||||
pool = Pool.objects.create(
|
||||
campaign=campaign,
|
||||
draft=True,
|
||||
status='completed',
|
||||
)
|
||||
regie = Regie.objects.create(label='Foo')
|
||||
invoice1 = DraftInvoice.objects.create(
|
||||
date_issue=datetime.date.today(), regie=regie, pool=pool, payer='payer:1'
|
||||
)
|
||||
invoice2 = DraftInvoice.objects.create(
|
||||
date_issue=datetime.date.today(), regie=regie, pool=pool, payer='payer:2'
|
||||
)
|
||||
|
||||
line11 = DraftInvoiceLine.objects.create(
|
||||
invoice=invoice1,
|
||||
quantity=1,
|
||||
unit_amount=1,
|
||||
total_amount=1,
|
||||
status='success',
|
||||
pool=pool,
|
||||
label='Label 11',
|
||||
user_external_id='user:1',
|
||||
user_name='User1 Name1',
|
||||
)
|
||||
line12 = DraftInvoiceLine.objects.create(
|
||||
invoice=invoice1,
|
||||
quantity=1,
|
||||
unit_amount=2,
|
||||
total_amount=2,
|
||||
status='success',
|
||||
pool=pool,
|
||||
label='Label 12',
|
||||
user_external_id='user:2',
|
||||
user_name='User2 Name2',
|
||||
)
|
||||
line13 = DraftInvoiceLine.objects.create(
|
||||
invoice=invoice1,
|
||||
quantity=1,
|
||||
unit_amount=3,
|
||||
total_amount=3,
|
||||
status='success',
|
||||
pool=pool,
|
||||
label='Label 13',
|
||||
user_external_id='user:1',
|
||||
user_name='User1 Name1',
|
||||
)
|
||||
|
||||
orphan_line = DraftInvoiceLine.objects.create(
|
||||
quantity=1,
|
||||
unit_amount=42,
|
||||
total_amount=42,
|
||||
status='failed',
|
||||
pool=pool,
|
||||
label='Label 14',
|
||||
user_external_id='user:1',
|
||||
user_name='User1 Name1',
|
||||
)
|
||||
|
||||
line21 = DraftInvoiceLine.objects.create(
|
||||
invoice=invoice2,
|
||||
quantity=1,
|
||||
unit_amount=1,
|
||||
total_amount=1,
|
||||
status='success',
|
||||
pool=pool,
|
||||
label='Label 21',
|
||||
user_external_id='user:1',
|
||||
user_name='User1 Name1',
|
||||
)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
||||
assert '#%s' % orphan_line.pk not in resp
|
||||
assert (
|
||||
resp.pyquery('h3[data-invoice-id="%s"]' % invoice1.pk).text()
|
||||
== 'Invoice #%s addressed to payer:1, amount 6.00€' % invoice1.pk
|
||||
)
|
||||
assert len(resp.pyquery('ul[data-invoice-id="%s"] li' % invoice1.pk)) == 3
|
||||
assert (
|
||||
resp.pyquery('ul[data-invoice-id="%s"] li:nth-child(1)' % invoice1.pk).text()
|
||||
== '#%s User1 Name1 - Label 11 (1.00)' % line11.pk
|
||||
)
|
||||
assert (
|
||||
resp.pyquery('ul[data-invoice-id="%s"] li:nth-child(2)' % invoice1.pk).text()
|
||||
== '#%s User1 Name1 - Label 13 (3.00)' % line13.pk
|
||||
)
|
||||
assert (
|
||||
resp.pyquery('ul[data-invoice-id="%s"] li:nth-child(3)' % invoice1.pk).text()
|
||||
== '#%s User2 Name2 - Label 12 (2.00)' % line12.pk
|
||||
)
|
||||
assert (
|
||||
resp.pyquery('h3[data-invoice-id="%s"]' % invoice2.pk).text()
|
||||
== 'Invoice #%s addressed to payer:2, amount 1.00€' % invoice2.pk
|
||||
)
|
||||
assert len(resp.pyquery('ul[data-invoice-id="%s"] li' % invoice2.pk)) == 1
|
||||
assert (
|
||||
resp.pyquery('ul[data-invoice-id="%s"] li:nth-child(1)' % invoice2.pk).text()
|
||||
== '#%s User1 Name1 - Label 21 (1.00)' % line21.pk
|
||||
)
|
||||
|
||||
|
||||
def test_journal_pool(app, admin_user):
|
||||
campaign = Campaign.objects.create(
|
||||
date_start=datetime.date(2022, 9, 1),
|
||||
|
|
Loading…
Reference in New Issue