Add init options to skip data initialization and remove manual cleanup in test cases.

This commit is contained in:
2026-01-11 11:51:49 +08:00
parent 693c5890ca
commit 9efbbc38ab
12 changed files with 40 additions and 51 deletions

View File

@@ -24,7 +24,7 @@ from flask_sqlalchemy import SQLAlchemy
from accounting.utils.user import UserUtilityInterface
VERSION: str = "1.6.1"
VERSION: str = "1.6.1.2"
"""The package version."""
db: SQLAlchemy = SQLAlchemy()
"""The database instance."""

View File

@@ -54,13 +54,20 @@ def __validate_username(ctx: click.core.Context, param: click.core.Option,
@click.option("-u", "--username", metavar="USERNAME", prompt=True,
help="The username.", callback=__validate_username,
default=lambda: os.getlogin())
@click.option("--skip-accounts", is_flag=True, default=False,
help="Skip initializing accounts.")
@click.option("--skip-currencies", is_flag=True, default=False,
help="Skip initializing currencies.")
@with_appcontext
def init_db_command(username: str) -> None:
def init_db_command(username: str, skip_accounts: bool,
skip_currencies: bool) -> None:
"""Initializes the accounting database."""
db.create_all()
init_base_accounts_command()
init_accounts_command(username)
init_currencies_command(username)
if not skip_accounts:
init_accounts_command(username)
if not skip_currencies:
init_currencies_command(username)
db.session.commit()
click.echo("Accounting database initialized.")