-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable export of non-attributable transfers
- Loading branch information
1 parent
f07a07c
commit 9eb88cf
Showing
5 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from collections.abc import Sequence | ||
from datetime import datetime, timedelta | ||
|
||
from sepaxml import SepaTransfer | ||
from sqlalchemy import select | ||
from sqlalchemy.orm import joinedload | ||
|
||
from pycroft.helpers.utc import ensure_tz | ||
from pycroft.model import session | ||
from pycroft.model.finance import BankAccountActivity | ||
|
||
|
||
def get_activities_to_return() -> Sequence[BankAccountActivity]: | ||
statement = ( | ||
select(BankAccountActivity) | ||
.options(joinedload(BankAccountActivity.bank_account)) | ||
.filter(BankAccountActivity.transaction_id.is_(None)) | ||
.filter(BankAccountActivity.amount > 0) | ||
.filter( | ||
BankAccountActivity.imported_at | ||
< ensure_tz(datetime.utcnow() - timedelta(days=14)) | ||
) | ||
) | ||
|
||
return session.session.scalars(statement).all() | ||
|
||
|
||
def generate_activities_return_sepaxml(activities: list[BankAccountActivity]) -> bytes: | ||
config = { | ||
"name": "Studierendenrat der TU Dresden", | ||
"IBAN": "DE61850503003120219540", | ||
"BIC": "OSDDDE81", | ||
"batch": False, | ||
"currency": "EUR", | ||
} | ||
sepa = SepaTransfer(config, clean=False) | ||
|
||
for activity in activities: | ||
payment = { | ||
"name": activity.other_name, | ||
"IBAN": activity.other_account_number, | ||
"BIC": activity.other_routing_number, | ||
"amount": int(activity.amount * 100), | ||
"execution_date": datetime.now().date(), | ||
"description": f"Rücküberweisung nicht zuordenbarer Überweisung vom {activity.posted_on} mit Referenz {activity.reference}", | ||
} | ||
sepa.add_payment(payment) | ||
|
||
return sepa.export() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{# | ||
SPDX-FileCopyrightText: 2024 Gregor Düster <git@gdstr.eu> | ||
|
||
SPDX-License-Identifier: Apache-2.0 | ||
#} | ||
{% extends "layout.html" %} | ||
|
||
{% set page_title = "Unzuordenbare Überweisungen zurücküberweisen" %} | ||
|
||
{% block content %} | ||
<form action="{{ url_for('.bank_account_activities_return_do') }}" method="POST"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
{{ form.csrf_token }} | ||
<table class="table table-striped table-responsive activities"> | ||
<thead> | ||
<th></th> | ||
<th>Bankkonto</th> | ||
<th>Name</th> | ||
<th>Gültig am</th> | ||
<th>Verwendungszweck</th> | ||
<th>Betrag</th> | ||
</thead> | ||
<tbody> | ||
{% for field in form %}{% if field.type != 'CSRFTokenField' %} | ||
<tr> | ||
<td>{{ field }}</td> | ||
<td>{{ activities[field.id]["bank_account"] }}</td> | ||
<td>{{ activities[field.id]["name"] }}</td> | ||
<td>{{ activities[field.id]["valid_on"] }}</td> | ||
<td>{{ activities[field.id]["reference"] }}</td> | ||
<td>{{ activities[field.id]["amount"] }} €</td> | ||
</tr> | ||
{% endif %}{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-md-12"> | ||
<button type="submit" class="btn btn-primary">SEPA-XML generieren</button> | ||
</div> | ||
</div> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters