diff --git a/src/pretix/plugins/banktransfer/tasks.py b/src/pretix/plugins/banktransfer/tasks.py index 9a10d3ef54..15c084d57f 100644 --- a/src/pretix/plugins/banktransfer/tasks.py +++ b/src/pretix/plugins/banktransfer/tasks.py @@ -162,6 +162,21 @@ def _handle_transaction(trans: BankTransaction, matches: tuple, event: Event = N else: trans.order = orders[0] + if len(orders) > 1: + # Multi-match! Can we split this automatically? + order_pending_sum = sum(o.pending_sum for o in orders) + if order_pending_sum != trans.amount: + # we can't :( this needs to be dealt with by a human + trans.state = BankTransaction.STATE_NOMATCH + trans.message = gettext_noop('Automatic split to multiple orders not possible.') + trans.save() + return + + # we can! + splits = [(o, o.pending_sum) for o in orders] + else: + splits = [(orders[0], trans.amount)] + for o in orders: if o.status == Order.STATUS_PAID and o.pending_sum <= Decimal('0.00'): trans.state = BankTransaction.STATE_DUPLICATE @@ -179,21 +194,6 @@ def _handle_transaction(trans: BankTransaction, matches: tuple, event: Event = N trans.save() return - if len(orders) > 1: - # Multi-match! Can we split this automatically? - order_pending_sum = sum(o.pending_sum for o in orders) - if order_pending_sum != trans.amount: - # we can't :( this needs to be dealt with by a human - trans.state = BankTransaction.STATE_NOMATCH - trans.message = gettext_noop('Automatic split to multiple orders not possible.') - trans.save() - return - - # we can! - splits = [(o, o.pending_sum) for o in orders] - else: - splits = [(orders[0], trans.amount)] - trans.state = BankTransaction.STATE_VALID for order, amount in splits: info_data = { diff --git a/src/tests/plugins/banktransfer/test_import.py b/src/tests/plugins/banktransfer/test_import.py index 31a502e274..05e2a76b87 100644 --- a/src/tests/plugins/banktransfer/test_import.py +++ b/src/tests/plugins/banktransfer/test_import.py @@ -471,6 +471,33 @@ def test_split_payment_success(env, orga_job): assert o4.payments.get().amount == Decimal('12.00') +@pytest.mark.django_db +def test_valid_plus_invalid_match(env, orga_job): + with scopes_disabled(): + o4 = Order.objects.create( + code='99999', event=env[0], + status=Order.STATUS_PAID, + datetime=now(), expires=now() + timedelta(days=10), + total=12, + sales_channel=env[0].organizer.sales_channels.get(identifier="web"), + ) + o4.payments.create( + provider='paypal', + state=OrderPayment.PAYMENT_STATE_CONFIRMED, + amount=o4.total + ) + process_banktransfers(orga_job, [{ + 'payer': 'Karla Kundin', + 'reference': 'Bestellungen DUMMY-1Z3AS DUMMY-99999', + 'date': '2016-01-26', + 'amount': '.00' + }]) + with scopes_disabled(): + job = BankImportJob.objects.last() + t = job.transactions.last() + assert t.state == BankTransaction.STATE_NOMATCH + + @pytest.mark.django_db def test_split_payment_mismatch(env, orga_job): with scopes_disabled():