From eba314ee3e028b781444c9e85efd3dcee67db169 Mon Sep 17 00:00:00 2001 From: luto Date: Sat, 14 Oct 2017 18:07:13 +0200 Subject: [PATCH] [import] do not import inflow virtual transactions, which can't be matched --- .../management/commands/import_shackbureau.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/byro_shackspace/management/commands/import_shackbureau.py b/byro_shackspace/management/commands/import_shackbureau.py index 7a3dd42..2d160de 100644 --- a/byro_shackspace/management/commands/import_shackbureau.py +++ b/byro_shackspace/management/commands/import_shackbureau.py @@ -98,22 +98,22 @@ def _import_inflows(member, virtual_transactions, real_transactions): value_datetime=localize(parse_date(inflow['due_date'])), purpose=inflow['payment_reference'], ) - if not possible_real_transaction.exists(): - real_transaction = None - elif possible_real_transaction.count() == 1: - real_transaction = possible_real_transaction.first() - else: - real_transaction = possible_real_transaction.first() - print(f'Found more than one transactions matching our query: {possible_real_transaction.values_list("pk", flat=True)}') - VirtualTransaction.objects.create( - destination_account=account, - source_account=liability_account, - member=member, - amount=abs(Decimal(inflow['amount'])), - value_datetime=localize(parse_date(inflow['due_date'])), - real_transaction=real_transaction, - ) + if possible_real_transaction.count() == 1: + real_transaction = possible_real_transaction.first() + + VirtualTransaction.objects.create( + destination_account=account, + source_account=liability_account, + member=member, + amount=abs(Decimal(inflow['amount'])), + value_datetime=localize(parse_date(inflow['due_date'])), + real_transaction=real_transaction, + ) + elif possible_real_transaction.count() == 0: + print(f'Found no transaction matching our query: {inflow}') + elif possible_real_transaction.count() > 1: + print(f'Found more than one transactions matching our query: {possible_real_transaction.values_list("pk", flat=True)}') def _import_transactions(member_data, member):