Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle reversals for new imported transactions #701

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pycroft/lib/finance/transaction_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ def process_transactions(
):
purpose = purpose + " EREF+" + transaction.data["end_to_end_reference"]

amount = transaction.data["amount"].amount

# Reversal ("Storno")
if "R" in transaction.data.get("status", ""):
amount = -amount

Comment on lines +224 to +229
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing that inline, we should provide an intermediate function which turns a MT940Transaction into a BankAccountActivity. For that, it needs from transaction.data the following fields:

  • applicant_iban
  • applicant_bin
  • applicant_name
  • purpose
  • end_to_end_reference
  • amount
  • guessed_entry_date
  • date

This should be a pure function

def activiity_from_transaction_data(
    transaction_data: TDataTypedDict,
    bank_account_id: int
) -> BankAccountActivity: ...

where TDataTypedDict captures the aforementioned keys as a TypedDict.
We can then use a fixed mt940 dump of test data to check whether all the cases are handled properly without even having to touch the DB.

new_activity = BankAccountActivity(
bank_account_id=bank_account.id,
amount=transaction.data["amount"].amount,
amount=amount,
reference=purpose,
other_account_number=iban,
other_routing_number=bic,
Expand Down
Loading