Skip to content

Commit

Permalink
finance: Move bank account import to action button
Browse files Browse the repository at this point in the history
  • Loading branch information
FestplattenSchnitzel committed Sep 27, 2024
1 parent 1846e57 commit 815fda7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
27 changes: 14 additions & 13 deletions web/blueprints/finance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,17 @@ def bank_accounts_list_json() -> ResponseReturnValue:
def actions(bank_account: BankAccount) -> list[BtnColResponse]:
return [
BtnColResponse(
href=url_for('.accounts_show', account_id=bank_account.account_id),
href=url_for(".accounts_show", account_id=bank_account.account_id),
title="",
btn_class="btn-primary",
btn_class="btn-primary btn-sm",
icon="fa-eye",
)
),
BtnColResponse(
href=url_for(".bank_accounts_import", bank_account_id=bank_account.id),
title="",
btn_class="btn-primary btn-sm",
icon="fa-file-import",
),
]

return TableResponse[BankAccountRow](
Expand All @@ -182,7 +188,6 @@ def actions(bank_account: BankAccount) -> list[BtnColResponse]:
name=bank_account.name,
bank=bank_account.bank,
iban=bank_account.iban,
bic=bank_account.bic,
balance=money_filter(bank_account.balance),
last_imported_at=(
str(datetime.date(i))
Expand Down Expand Up @@ -270,14 +275,11 @@ def flash_fints_errors() -> t.Iterator[None]:
nicht erreicht werden.', 'error')
raise PycroftException from e

@bp.route('/bank-accounts/import', methods=['GET', 'POST'])
@access.require('finance_change')
@nav.navigate("Bankkontobewegungen importieren", icon='fa-file-import')
def bank_accounts_import() -> ResponseReturnValue:

@bp.route("/bank-accounts/<int:bank_account_id>/import", methods=["GET", "POST"])
@access.require("finance_change")
def bank_accounts_import(bank_account_id: int) -> ResponseReturnValue:
form = BankAccountActivitiesImportForm()
form.account.choices = [
(acc.id, acc.name) for acc in get_all_bank_accounts(session) if not acc.account.legacy
]
imported = ImportedTransactions([], [], [])

def display_form_response(
Expand All @@ -293,14 +295,13 @@ def display_form_response(
if not form.is_submitted():
del (form.start_date)
form.end_date.data = date.today() - timedelta(days=1)
form.account.data = config.membership_fee_bank_account_id

return display_form_response(imported)

if not form.validate():
return display_form_response(imported)

bank_account = session.get(BankAccount, form.account.data)
bank_account = session.get(BankAccount, bank_account_id)

# set start_date, end_date
if form.start_date.data is None:
Expand Down
1 change: 0 additions & 1 deletion web/blueprints/finance/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class BankAccountActivityEditForm(BankAccountActivityReadForm):


class BankAccountActivitiesImportForm(Form):
account = SelectField("Bankkonto", coerce=int)
user = StringField("Loginname", validators=[DataRequired()])
secret_pin = PasswordField("PIN", validators=[DataRequired()])
start_date = DateField("Startdatum")
Expand Down
2 changes: 0 additions & 2 deletions web/blueprints/finance/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class BankAccountTable(BootstrapTable):
name = Column("Name")
bank = Column("Bank")
iban = IbanColumn("IBAN")
bic = Column("SWIFT-BIC")
balance = Column("Saldo")
last_imported_at = Column("Zuletzt importiert")
actions = MultiBtnColumn("Aktionen")
Expand Down Expand Up @@ -219,7 +218,6 @@ class BankAccountRow(BaseModel):
name: str
bank: str
iban: str
bic: str
balance: str
last_imported_at: str # TODO perhaps date
actions: list[BtnColResponse]
Expand Down

0 comments on commit 815fda7

Please sign in to comment.