mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Bank transfer: Enable organizer-level features with multiple currencies (#3177)
Co-authored-by: Martin Gross <gross@rami.io>
This commit is contained in:
@@ -96,6 +96,21 @@ def test_assign_order(env, client):
|
||||
assert env[2].status == Order.STATUS_PAID
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_assign_order_invalid_currency(env, client):
|
||||
job = BankImportJob.objects.create(event=env[0])
|
||||
trans = BankTransaction.objects.create(event=env[0], import_job=job, payer='Foo',
|
||||
state=BankTransaction.STATE_NOMATCH,
|
||||
amount=23, date='unknown', currency='HUF')
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
r = json.loads(client.post('/control/event/{}/{}/banktransfer/action/'.format(env[0].organizer.slug, env[0].slug), {
|
||||
'action_{}'.format(trans.pk): 'assign:FOO'
|
||||
}).content.decode('utf-8'))
|
||||
assert r['status'] == 'error'
|
||||
trans.refresh_from_db()
|
||||
assert trans.state == BankTransaction.STATE_NOMATCH
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_assign_order_unknown(env, client):
|
||||
job = BankImportJob.objects.create(event=env[0])
|
||||
|
||||
@@ -79,11 +79,13 @@ RES_JOB = {
|
||||
'amount': '0.00',
|
||||
'date': 'unknown',
|
||||
'state': 'error',
|
||||
'currency': 'EUR',
|
||||
'order': None
|
||||
}
|
||||
],
|
||||
'created': '2017-06-27T09:13:35.785251Z',
|
||||
'state': 'pending'
|
||||
'state': 'pending',
|
||||
'currency': 'EUR'
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +95,10 @@ def test_api_list(env, client):
|
||||
|
||||
with mock.patch('django.utils.timezone.now') as mock_now:
|
||||
mock_now.return_value = testtime
|
||||
job = BankImportJob.objects.create(event=env[0], organizer=env[0].organizer)
|
||||
job = BankImportJob.objects.create(event=env[0], organizer=env[0].organizer, currency='EUR')
|
||||
BankTransaction.objects.create(event=env[0], import_job=job, payer='Foo',
|
||||
state=BankTransaction.STATE_ERROR,
|
||||
amount=0, date='unknown')
|
||||
amount=0, date='unknown', currency='EUR')
|
||||
res = copy.copy(RES_JOB)
|
||||
res['id'] = job.pk
|
||||
res['created'] = testtime.isoformat().replace('+00:00', 'Z')
|
||||
@@ -113,10 +115,10 @@ def test_api_detail(env, client):
|
||||
|
||||
with mock.patch('django.utils.timezone.now') as mock_now:
|
||||
mock_now.return_value = testtime
|
||||
job = BankImportJob.objects.create(event=env[0], organizer=env[0].organizer)
|
||||
job = BankImportJob.objects.create(event=env[0], organizer=env[0].organizer, currency='EUR')
|
||||
BankTransaction.objects.create(event=env[0], import_job=job, payer='Foo',
|
||||
state=BankTransaction.STATE_ERROR,
|
||||
amount=0, date='unknown')
|
||||
amount=0, date='unknown', currency='EUR')
|
||||
res = copy.copy(RES_JOB)
|
||||
res['id'] = job.pk
|
||||
res['created'] = testtime.isoformat().replace('+00:00', 'Z')
|
||||
@@ -151,6 +153,7 @@ def test_api_create(env, client):
|
||||
assert rdata['state'] == 'completed'
|
||||
assert len(rdata['transactions']) == 1
|
||||
assert rdata['transactions'][0]['checksum']
|
||||
assert rdata['transactions'][0]['currency'] == 'EUR'
|
||||
env[2].refresh_from_db()
|
||||
assert env[2].status == Order.STATUS_PAID
|
||||
|
||||
@@ -179,7 +182,79 @@ def test_api_create_with_iban_bic(env, client):
|
||||
assert rdata['state'] == 'completed'
|
||||
assert len(rdata['transactions']) == 1
|
||||
assert rdata['transactions'][0]['checksum']
|
||||
assert rdata['transactions'][0]['currency'] == 'EUR'
|
||||
env[2].refresh_from_db()
|
||||
assert env[2].status == Order.STATUS_PAID
|
||||
with scopes_disabled():
|
||||
assert env[2].payments.first().info_data['iban'] == 'NL79RABO5373380466'
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_api_create_org_auto_currency(env, client):
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
r = client.post(
|
||||
'/api/v1/organizers/{}/bankimportjobs/'.format(env[0].organizer.slug), json.dumps({
|
||||
'transactions': [
|
||||
{
|
||||
'payer': 'Foo',
|
||||
'reference': 'DUMMY-1Z3AS',
|
||||
'amount': '23.00',
|
||||
'date': 'yesterday' # test bogus date format
|
||||
}
|
||||
]
|
||||
}), content_type="application/json"
|
||||
)
|
||||
assert r.status_code == 201
|
||||
rdata = json.loads(r.content.decode('utf-8'))
|
||||
# This is only because we don't run celery in tests, otherwise it wouldn't be completed yet.
|
||||
assert rdata['state'] == 'completed'
|
||||
assert len(rdata['transactions']) == 1
|
||||
assert rdata['transactions'][0]['checksum']
|
||||
assert rdata['transactions'][0]['currency'] == 'EUR'
|
||||
env[2].refresh_from_db()
|
||||
assert env[2].status == Order.STATUS_PAID
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_api_create_org_unclear_currency(env, client):
|
||||
Event.objects.create(
|
||||
organizer=env[0].organizer, name='Dummy', slug='dummy2', currency='HUF',
|
||||
date_from=now(), plugins='pretix.plugins.banktransfer'
|
||||
)
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
r = client.post(
|
||||
'/api/v1/organizers/{}/bankimportjobs/'.format(env[0].organizer.slug), json.dumps({
|
||||
'transactions': [
|
||||
{
|
||||
'payer': 'Foo',
|
||||
'reference': 'DUMMY-1Z3AS',
|
||||
'amount': '23.00',
|
||||
'date': 'yesterday' # test bogus date format
|
||||
}
|
||||
]
|
||||
}), content_type="application/json"
|
||||
)
|
||||
assert r.status_code == 400
|
||||
|
||||
r = client.post(
|
||||
'/api/v1/organizers/{}/bankimportjobs/'.format(env[0].organizer.slug), json.dumps({
|
||||
'currency': 'EUR',
|
||||
'transactions': [
|
||||
{
|
||||
'payer': 'Foo',
|
||||
'reference': 'DUMMY-1Z3AS',
|
||||
'amount': '23.00',
|
||||
'date': 'yesterday' # test bogus date format
|
||||
}
|
||||
]
|
||||
}), content_type="application/json"
|
||||
)
|
||||
assert r.status_code == 201
|
||||
rdata = json.loads(r.content.decode('utf-8'))
|
||||
# This is only because we don't run celery in tests, otherwise it wouldn't be completed yet.
|
||||
assert rdata['state'] == 'completed'
|
||||
assert len(rdata['transactions']) == 1
|
||||
assert rdata['transactions'][0]['checksum']
|
||||
assert rdata['transactions'][0]['currency'] == 'EUR'
|
||||
env[2].refresh_from_db()
|
||||
assert env[2].status == Order.STATUS_PAID
|
||||
|
||||
@@ -338,6 +338,19 @@ def test_mark_paid_organizer(env, orga_job):
|
||||
assert env[2].status == Order.STATUS_PAID
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_incorrect_currency(env, orga_job):
|
||||
BankImportJob.objects.filter(pk=orga_job).update(currency='HUF')
|
||||
process_banktransfers(orga_job, [{
|
||||
'payer': 'Karla Kundin',
|
||||
'reference': 'Bestellung DUMMY-1234S',
|
||||
'date': '2016-01-26',
|
||||
'amount': '23.00'
|
||||
}])
|
||||
env[2].refresh_from_db()
|
||||
assert env[2].status == Order.STATUS_PENDING
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_mark_paid_double_reference(env, orga_job):
|
||||
process_banktransfers(orga_job, [{
|
||||
|
||||
@@ -64,6 +64,32 @@ def env():
|
||||
return event, user, refund
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def refund_huf(env):
|
||||
event = Event.objects.create(
|
||||
organizer=env[0].organizer, name='Dummy', slug='dummy2', currency='HUF',
|
||||
date_from=now(), plugins='pretix.plugins.banktransfer,pretix.plugins.paypal'
|
||||
)
|
||||
order = Order.objects.create(
|
||||
code='1Z3AS', event=event, email='admin@localhost',
|
||||
status=Order.STATUS_PAID,
|
||||
datetime=now(), expires=now() + timedelta(days=10),
|
||||
total=42
|
||||
)
|
||||
refund = OrderRefund.objects.create(
|
||||
order=order,
|
||||
amount=Decimal("42"),
|
||||
provider='banktransfer',
|
||||
state=OrderRefund.REFUND_STATE_CREATED,
|
||||
info=json.dumps({
|
||||
'payer': "Abc Def",
|
||||
'iban': "DE27520521540534534466",
|
||||
'bic': "HELADEF1MEG",
|
||||
})
|
||||
)
|
||||
return refund
|
||||
|
||||
|
||||
url_prefixes = [
|
||||
"/control/event/dummy/dummy/",
|
||||
"/control/organizer/dummy/"
|
||||
@@ -106,6 +132,18 @@ def test_export_refunds(client, env, url_prefix):
|
||||
assert "HELADEF" in r
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_export_refunds_multi_currency(client, env, refund_huf):
|
||||
client.login(email='dummy@dummy.dummy', password='dummy')
|
||||
r = client.get('/control/organizer/dummy/banktransfer/refunds/')
|
||||
assert r.status_code == 200
|
||||
r = client.post('/control/organizer/dummy/banktransfer/refunds/', {"unite_transactions": True}, follow=True)
|
||||
assert r.status_code == 200
|
||||
assert RefundExport.objects.count() == 2
|
||||
assert RefundExport.objects.get(currency="EUR").sum == Decimal("23.00")
|
||||
assert RefundExport.objects.get(currency="HUF").sum == Decimal("42.00")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize("url_prefix", url_prefixes)
|
||||
def test_export_refunds_omit_invalid_bic(client, env, url_prefix):
|
||||
|
||||
Reference in New Issue
Block a user