898 lines
34 KiB
Python
898 lines
34 KiB
Python
import datetime
|
|
from unittest import mock
|
|
|
|
import pytest
|
|
|
|
from lingo.invoicing.models import Campaign, DraftInvoice, DraftInvoiceLine, InvoiceLine, Pool, Regie
|
|
from tests.utils import login
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_campaign_home(app, admin_user):
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaigns/')
|
|
h2 = resp.pyquery('div#appbar h2')
|
|
assert h2.text() == 'Campaigns'
|
|
|
|
|
|
def test_add_campaign(app, admin_user):
|
|
app = login(app)
|
|
resp = app.get('/manage/')
|
|
resp = resp.click('Invoicing')
|
|
resp = resp.click(href='/manage/invoicing/campaigns/')
|
|
resp = resp.click('New campaign')
|
|
resp.form['date_start'] = '2022-09-01'
|
|
resp.form['date_end'] = '2022-10-01'
|
|
resp.form['date_issue'] = '2022-10-31'
|
|
resp = resp.form.submit()
|
|
campaign = Campaign.objects.latest('pk')
|
|
assert resp.location.endswith('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert campaign.date_start == datetime.date(2022, 9, 1)
|
|
assert campaign.date_end == datetime.date(2022, 10, 1)
|
|
assert campaign.date_issue == datetime.date(2022, 10, 31)
|
|
|
|
resp = app.get('/manage/invoicing/campaign/add/')
|
|
resp.form['date_start'] = '2022-08-31'
|
|
resp.form['date_end'] = '2022-09-02'
|
|
resp.form['date_issue'] = '2022-10-31'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['__all__'] == [
|
|
'Another campaign overlapping this period already exists.'
|
|
]
|
|
resp.form['date_end'] = '2022-09-01'
|
|
resp = resp.form.submit()
|
|
campaign = Campaign.objects.latest('pk')
|
|
assert campaign.date_start == datetime.date(2022, 8, 31)
|
|
assert campaign.date_end == datetime.date(2022, 9, 1)
|
|
assert campaign.date_issue == datetime.date(2022, 10, 31)
|
|
|
|
resp = app.get('/manage/invoicing/campaign/add/')
|
|
resp.form['date_start'] = '2022-09-30'
|
|
resp.form['date_end'] = '2022-10-02'
|
|
resp.form['date_issue'] = '2022-10-31'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['__all__'] == [
|
|
'Another campaign overlapping this period already exists.'
|
|
]
|
|
resp.form['date_start'] = '2022-10-01'
|
|
resp = resp.form.submit()
|
|
campaign = Campaign.objects.latest('pk')
|
|
assert campaign.date_start == datetime.date(2022, 10, 1)
|
|
assert campaign.date_end == datetime.date(2022, 10, 2)
|
|
assert campaign.date_issue == datetime.date(2022, 10, 31)
|
|
|
|
|
|
def test_detail_campaign(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),
|
|
)
|
|
pool1 = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='completed',
|
|
)
|
|
pool2 = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='registered',
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaigns/')
|
|
resp = resp.click(href='/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert '/manage/invoicing/campaign/%s/edit/' % campaign.pk not in resp
|
|
assert '/manage/invoicing/campaign/%s/delete/' % campaign.pk not in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool1.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool2.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/add/' % (campaign.pk) not in resp
|
|
|
|
pool2.status = 'running'
|
|
pool2.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert '/manage/invoicing/campaign/%s/edit/' % campaign.pk not in resp
|
|
assert '/manage/invoicing/campaign/%s/delete/' % campaign.pk not in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool1.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool2.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/add/' % (campaign.pk) not in resp
|
|
|
|
pool2.status = 'failed'
|
|
pool2.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert '/manage/invoicing/campaign/%s/edit/' % campaign.pk in resp
|
|
assert '/manage/invoicing/campaign/%s/delete/' % campaign.pk in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool1.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool2.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/add/' % (campaign.pk) in resp
|
|
|
|
pool3 = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=False,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert '/manage/invoicing/campaign/%s/edit/' % campaign.pk not in resp
|
|
assert '/manage/invoicing/campaign/%s/delete/' % campaign.pk not in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool1.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool2.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool3.pk) in resp
|
|
assert '/manage/invoicing/campaign/%s/pool/add/' % (campaign.pk) not in resp
|
|
|
|
line = DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool1,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert '<span class="tag tag-success">1</span>' in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
line.status = 'error'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert '<span class="tag tag-error">1</span>' in resp
|
|
line.status = 'warning'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert 'tag-success' not in resp
|
|
assert '<span class="tag tag-warning">1</span>' in resp
|
|
assert 'tag-error' not in resp
|
|
line.delete()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
|
|
line = InvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool1,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert '<span class="tag tag-success">1</span>' in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
line.status = 'error'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert '<span class="tag tag-error">1</span>' in resp
|
|
line.status = 'warning'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
assert 'tag-success' not in resp
|
|
assert '<span class="tag tag-warning">1</span>' in resp
|
|
assert 'tag-error' not in resp
|
|
|
|
|
|
def test_edit_campaign(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),
|
|
)
|
|
Campaign.objects.create(
|
|
date_start=datetime.date(2022, 10, 1),
|
|
date_end=datetime.date(2022, 11, 1),
|
|
date_issue=datetime.date(2022, 11, 30),
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk)
|
|
resp.form['date_start'] = '2022-09-30'
|
|
resp.form['date_end'] = '2022-10-02'
|
|
resp.form['date_issue'] = '2022-12-31'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['__all__'] == [
|
|
'Another campaign overlapping this period already exists.'
|
|
]
|
|
resp.form['date_end'] = '2022-10-01'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/invoicing/campaign/%s/' % campaign.pk)
|
|
campaign.refresh_from_db()
|
|
assert campaign.date_start == datetime.date(2022, 9, 30)
|
|
assert campaign.date_end == datetime.date(2022, 10, 1)
|
|
assert campaign.date_issue == datetime.date(2022, 12, 31)
|
|
|
|
resp = app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk)
|
|
resp.form['date_start'] = '2022-10-31'
|
|
resp.form['date_end'] = '2022-11-02'
|
|
resp.form['date_issue'] = '2022-12-31'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['__all__'] == [
|
|
'Another campaign overlapping this period already exists.'
|
|
]
|
|
resp.form['date_start'] = '2022-11-01'
|
|
resp = resp.form.submit()
|
|
campaign.refresh_from_db()
|
|
assert campaign.date_start == datetime.date(2022, 11, 1)
|
|
assert campaign.date_end == datetime.date(2022, 11, 2)
|
|
assert campaign.date_issue == datetime.date(2022, 12, 31)
|
|
|
|
pool = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='completed',
|
|
)
|
|
app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk)
|
|
|
|
pool.status = 'failed'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk)
|
|
|
|
pool.status = 'registered'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk, status=404)
|
|
|
|
pool.status = 'running'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk, status=404)
|
|
|
|
pool.status = 'completed'
|
|
pool.draft = False
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/edit/' % campaign.pk, status=404)
|
|
|
|
|
|
def test_delete_campaign(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),
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/delete/' % campaign.pk)
|
|
resp = resp.form.submit()
|
|
assert Campaign.objects.count() == 0
|
|
assert resp.location.endswith('/manage/invoicing/campaigns/')
|
|
|
|
campaign.save()
|
|
pool = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='completed',
|
|
)
|
|
regie = Regie.objects.create(label='Foo')
|
|
invoice = DraftInvoice.objects.create(date_issue=datetime.date.today(), regie=regie, pool=pool)
|
|
DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
invoice=invoice,
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/delete/' % campaign.pk)
|
|
resp = resp.form.submit()
|
|
assert Campaign.objects.count() == 0
|
|
|
|
campaign.save()
|
|
pool.status = 'failed'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/delete/' % campaign.pk)
|
|
|
|
pool.status = 'registered'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/delete/' % campaign.pk, status=404)
|
|
|
|
pool.status = 'running'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/delete/' % campaign.pk, status=404)
|
|
|
|
pool.status = 'completed'
|
|
pool.draft = False
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/delete/' % campaign.pk, status=404)
|
|
|
|
|
|
def test_add_pool(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),
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/add/' % campaign.pk)
|
|
assert resp.form['draft'].value == 'on'
|
|
with mock.patch.object(Campaign, 'generate', autospec=True) as mock_generate:
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/invoicing/campaign/%s/#open:pools' % campaign.pk)
|
|
assert mock_generate.call_args_list == [mock.call(campaign, draft=True)]
|
|
|
|
pool = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='failed',
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/add/' % campaign.pk)
|
|
resp.form['draft'] = False
|
|
with mock.patch.object(Campaign, 'generate', autospec=True) as mock_generate:
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/invoicing/campaign/%s/#open:pools' % campaign.pk)
|
|
assert mock_generate.call_args_list == [mock.call(campaign, draft=False)]
|
|
|
|
pool.status = 'completed'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/add/' % campaign.pk)
|
|
|
|
pool.status = 'registered'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/add/' % campaign.pk, status=404)
|
|
|
|
pool.status = 'running'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/add/' % campaign.pk, status=404)
|
|
|
|
pool.status = 'completed'
|
|
pool.draft = False
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/add/' % campaign.pk, status=404)
|
|
|
|
|
|
def test_detail_pool(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),
|
|
)
|
|
campaign2 = Campaign.objects.create(
|
|
date_start=datetime.date(2022, 10, 1),
|
|
date_end=datetime.date(2022, 11, 1),
|
|
date_issue=datetime.date(2022, 11, 30),
|
|
)
|
|
pool = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='completed',
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) in resp
|
|
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/' % (0, pool.pk), status=404)
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign2.pk, pool.pk), status=404)
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, 0), status=404)
|
|
|
|
pool.draft = False
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) not in resp
|
|
|
|
pool.draft = True
|
|
pool.status = 'registered'
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) not in resp
|
|
|
|
pool.status = 'running'
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) not in resp
|
|
|
|
pool.status = 'failed'
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) in resp
|
|
|
|
line = DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '<span class="tag tag-success">1</span>' in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
line.status = 'error'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert '<span class="tag tag-error">1</span>' in resp
|
|
line.status = 'warning'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert '<span class="tag tag-warning">1</span>' in resp
|
|
assert 'tag-error' not in resp
|
|
line.delete()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
|
|
pool.draft = False
|
|
pool.save()
|
|
line = InvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert '<span class="tag tag-success">1</span>' in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
line.status = 'error'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert '<span class="tag tag-error">1</span>' in resp
|
|
line.status = 'warning'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert '<span class="tag tag-warning">1</span>' in resp
|
|
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(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
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(
|
|
event_date=datetime.date(2022, 9, 2),
|
|
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(
|
|
event_date=datetime.date(2022, 9, 3),
|
|
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(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
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(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
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 - 01/09/2022 - Label 11 (1.00)' % line11.pk
|
|
)
|
|
assert (
|
|
resp.pyquery('ul[data-invoice-id="%s"] li:nth-child(2)' % invoice1.pk).text()
|
|
== '#%s User1 Name1 - 03/09/2022 - Label 13 (3.00)' % line13.pk
|
|
)
|
|
assert (
|
|
resp.pyquery('ul[data-invoice-id="%s"] li:nth-child(3)' % invoice1.pk).text()
|
|
== '#%s User2 Name2 - 02/09/2022 - 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 - 01/09/2022 - Label 21 (1.00)' % line21.pk
|
|
)
|
|
|
|
|
|
def test_journal_pool(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),
|
|
)
|
|
campaign2 = Campaign.objects.create(
|
|
date_start=datetime.date(2022, 10, 1),
|
|
date_end=datetime.date(2022, 11, 1),
|
|
date_issue=datetime.date(2022, 11, 30),
|
|
)
|
|
pool = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='completed',
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) in resp
|
|
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (0, pool.pk), status=404)
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign2.pk, pool.pk), status=404)
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, 0), status=404)
|
|
|
|
pool.draft = False
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) not in resp
|
|
|
|
pool.draft = True
|
|
pool.status = 'registered'
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) not in resp
|
|
|
|
pool.status = 'running'
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) not in resp
|
|
|
|
pool.status = 'failed'
|
|
pool.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk) in resp
|
|
|
|
line = DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '<span class="tag tag-success">1</span>' in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
line.status = 'error'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert '<span class="tag tag-error">1</span>' in resp
|
|
line.status = 'warning'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert '<span class="tag tag-warning">1</span>' in resp
|
|
assert 'tag-error' not in resp
|
|
line.delete()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
|
|
pool.draft = False
|
|
pool.save()
|
|
line = InvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert '<span class="tag tag-success">1</span>' in resp
|
|
assert 'tag-warning' not in resp
|
|
assert 'tag-error' not in resp
|
|
line.status = 'error'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert 'tag-warning' not in resp
|
|
assert '<span class="tag tag-error">1</span>' in resp
|
|
line.status = 'warning'
|
|
line.save()
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert 'tag-success' not in resp
|
|
assert '<span class="tag tag-warning">1</span>' in resp
|
|
assert 'tag-error' not in resp
|
|
|
|
|
|
def test_journal_pool_lines(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')
|
|
invoice = DraftInvoice.objects.create(date_issue=datetime.date.today(), regie=regie, pool=pool)
|
|
|
|
lines = [
|
|
DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
invoice=invoice,
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
pricing_data={'foo': 'bar'},
|
|
event={'event': 'foobar'},
|
|
)
|
|
]
|
|
errors = [
|
|
('AgendaPricingNotFound', {}),
|
|
('CriteriaConditionNotFound', {'category': 'cat-foo'}),
|
|
('MultipleDefaultCriteriaCondition', {'category': 'cat-foo'}),
|
|
('PricingDataError', {'criterias': {'qf': 'qf-1', 'foo': 'bar'}}),
|
|
('PricingDataFormatError', {'pricing': 'foobar', 'wanted': 'decimal'}),
|
|
('PricingUnknownCheckStatusError', {'status': 'unknown'}),
|
|
('PricingEventNotCheckedError', {}),
|
|
('PricingBookingNotCheckedError', {}),
|
|
('PricingMultipleBookingError', {}),
|
|
('PricingBookingCheckTypeError', {'reason': 'not-found'}),
|
|
(
|
|
'PricingBookingCheckTypeError',
|
|
{
|
|
'check_type_group': 'foo-bar',
|
|
'check_type': 'foo-reason',
|
|
'reason': 'not-configured',
|
|
},
|
|
),
|
|
(
|
|
'PricingBookingCheckTypeError',
|
|
{'check_type_group': 'foo-bar', 'check_type': 'foo-reason', 'reason': 'wrong-kind'},
|
|
),
|
|
]
|
|
for error, error_details in errors:
|
|
lines.append(
|
|
DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
invoice=invoice,
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='warning' if error == 'AgendaPricingNotFound' else 'error',
|
|
pool=pool,
|
|
pricing_data={
|
|
'error': error,
|
|
'error_details': error_details,
|
|
},
|
|
event={'event': 'foobar'},
|
|
)
|
|
)
|
|
|
|
def format_status(value):
|
|
return (' '.join([v.strip() for v in value.split('\n')])).strip()
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/journal/' % (campaign.pk, pool.pk))
|
|
assert format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[0].pk).text()) == 'Success'
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[0].pk).text().strip()
|
|
== "{'foo': 'bar'} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[1].pk).text())
|
|
== 'Warning (Agenda pricing not found)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[1].pk).text().strip()
|
|
== "{'error': 'AgendaPricingNotFound', 'error_details': {}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[2].pk).text())
|
|
== 'Error (No matching criteria for category: cat-foo)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[2].pk).text().strip()
|
|
== "{'error': 'CriteriaConditionNotFound', 'error_details': {'category': 'cat-foo'}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[3].pk).text())
|
|
== 'Error (Multiple default criteria found for category: cat-foo)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[3].pk).text().strip()
|
|
== "{'error': 'MultipleDefaultCriteriaCondition', 'error_details': {'category': 'cat-foo'}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[4].pk).text())
|
|
== 'Error (Impossible to determine a pricing for criterias: qf-1 (category: qf), bar (category: foo))'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[4].pk).text().strip()
|
|
== "{'error': 'PricingDataError', 'error_details': {'criterias': {'foo': 'bar', 'qf': 'qf-1'}}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[5].pk).text())
|
|
== 'Error (Pricing is not a decimal: foobar)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[5].pk).text().strip()
|
|
== "{'error': 'PricingDataFormatError', 'error_details': {'pricing': 'foobar', 'wanted': 'decimal'}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[6].pk).text())
|
|
== 'Error (Unknown check status: unknown)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[6].pk).text().strip()
|
|
== "{'error': 'PricingUnknownCheckStatusError', 'error_details': {'status': 'unknown'}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[7].pk).text())
|
|
== 'Error (Event is not checked)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[7].pk).text().strip()
|
|
== "{'error': 'PricingEventNotCheckedError', 'error_details': {}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[8].pk).text())
|
|
== 'Error (Booking is not checked)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[8].pk).text().strip()
|
|
== "{'error': 'PricingBookingNotCheckedError', 'error_details': {}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[9].pk).text())
|
|
== 'Error (Multiple booking found)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[9].pk).text().strip()
|
|
== "{'error': 'PricingMultipleBookingError', 'error_details': {}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[10].pk).text())
|
|
== 'Error (Check type error: not found)'
|
|
)
|
|
assert (
|
|
resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[10].pk).text().strip()
|
|
== "{'error': 'PricingBookingCheckTypeError', 'error_details': {'reason': 'not-found'}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[11].pk).text())
|
|
== 'Error (Check type error: pricing not configured (group: foo-bar, check type: foo-reason))'
|
|
)
|
|
assert resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[11].pk).text().strip() == (
|
|
"{'error': 'PricingBookingCheckTypeError', 'error_details': {'check_type': 'foo-reason', "
|
|
"'check_type_group': 'foo-bar', 'reason': 'not-configured'}} {'event': 'foobar'}"
|
|
)
|
|
assert (
|
|
format_status(resp.pyquery('tr[data-line-id="%s"] td.status' % lines[12].pk).text())
|
|
== 'Error (Check type error: wrong kind (group: foo-bar, check type: foo-reason))'
|
|
)
|
|
assert resp.pyquery('tr[data-details-for-line-id="%s"] td pre' % lines[12].pk).text().strip() == (
|
|
"{'error': 'PricingBookingCheckTypeError', 'error_details': {'check_type': 'foo-reason', "
|
|
"'check_type_group': 'foo-bar', 'reason': 'wrong-kind'}} {'event': 'foobar'}"
|
|
)
|
|
|
|
|
|
def test_delete_pool(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),
|
|
)
|
|
campaign2 = Campaign.objects.create(
|
|
date_start=datetime.date(2022, 10, 1),
|
|
date_end=datetime.date(2022, 11, 1),
|
|
date_issue=datetime.date(2022, 11, 30),
|
|
)
|
|
pool = Pool.objects.create(
|
|
campaign=campaign,
|
|
draft=True,
|
|
status='completed',
|
|
)
|
|
regie = Regie.objects.create(label='Foo')
|
|
invoice = DraftInvoice.objects.create(date_issue=datetime.date.today(), regie=regie, pool=pool)
|
|
DraftInvoiceLine.objects.create(
|
|
event_date=datetime.date(2022, 9, 1),
|
|
invoice=invoice,
|
|
quantity=1,
|
|
unit_amount=1,
|
|
total_amount=1,
|
|
status='success',
|
|
pool=pool,
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk))
|
|
resp = resp.form.submit()
|
|
assert Pool.objects.count() == 0
|
|
assert resp.location.endswith('/manage/invoicing/campaign/%s/#open:pools' % campaign.pk)
|
|
|
|
pool.draft = True
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (0, pool.pk), status=404)
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign2.pk, pool.pk), status=404)
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, 0), status=404)
|
|
|
|
pool.status = 'registered'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk), status=404)
|
|
|
|
pool.status = 'running'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk), status=404)
|
|
|
|
pool.draft = False
|
|
pool.status = 'error'
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk), status=404)
|
|
|
|
pool.draft = True
|
|
pool.save()
|
|
app.get('/manage/invoicing/campaign/%s/pool/%s/delete/' % (campaign.pk, pool.pk))
|