Refactor code for improved readability and consistency across multiple files
Gitea Actions CI / detect (push) Successful in 3s
Gitea Actions CI / Compose & nginx validation (push) Failing after 14s
Gitea Actions CI / Frontend (lint / type / test / build) (push) Successful in 45s
Gitea Actions CI / Backend (lint / type / test / build) (push) Successful in 1m31s
Gitea Actions CI / detect (push) Successful in 3s
Gitea Actions CI / Compose & nginx validation (push) Failing after 14s
Gitea Actions CI / Frontend (lint / type / test / build) (push) Successful in 45s
Gitea Actions CI / Backend (lint / type / test / build) (push) Successful in 1m31s
This commit is contained in:
@@ -39,10 +39,7 @@ def category_spend(
|
||||
.scalar()
|
||||
)
|
||||
totals[expense.category_id] += expense.amount_kopecks - int(refunded or 0)
|
||||
categories = {
|
||||
item.id: item
|
||||
for item in db.query(Category).filter_by(space_id=space_id).all()
|
||||
}
|
||||
categories = {item.id: item for item in db.query(Category).filter_by(space_id=space_id).all()}
|
||||
return [
|
||||
{
|
||||
"category_id": category_id,
|
||||
|
||||
@@ -28,9 +28,7 @@ class Account(Base, PkMixin, TimestampMixin):
|
||||
|
||||
__tablename__ = "accounts"
|
||||
__table_args__ = (
|
||||
CheckConstraint(
|
||||
"kind IN ('cash', 'debit', 'credit', 'savings')", name="kind_valid"
|
||||
),
|
||||
CheckConstraint("kind IN ('cash', 'debit', 'credit', 'savings')", name="kind_valid"),
|
||||
CheckConstraint("status IN ('active', 'archived')", name="status_valid"),
|
||||
CheckConstraint("currency = 'RUB'", name="currency_rub_only"),
|
||||
UniqueConstraint("space_id", "id", name="uq_accounts_space_id"),
|
||||
|
||||
@@ -346,9 +346,7 @@ def savings_transfer(operation_id: uuid.UUID, db: Db, context: Context, _csrf: C
|
||||
|
||||
|
||||
@router.post("/operations/{operation_id}/savings-transfer/revert")
|
||||
def savings_transfer_revert(
|
||||
operation_id: uuid.UUID, db: Db, context: Context, _csrf: Csrf
|
||||
) -> dict:
|
||||
def savings_transfer_revert(operation_id: uuid.UUID, db: Db, context: Context, _csrf: Csrf) -> dict:
|
||||
from app.ledger import savings
|
||||
|
||||
operation = savings.revert_savings_conversion(
|
||||
|
||||
@@ -22,17 +22,13 @@ SAVINGS_ACCOUNT_NAME = "Накопления"
|
||||
|
||||
def get_savings_account(db: Session, *, space_id: uuid.UUID) -> Account | None:
|
||||
return (
|
||||
db.query(Account)
|
||||
.filter_by(space_id=space_id, system_key=SAVINGS_SYSTEM_KEY)
|
||||
.one_or_none()
|
||||
db.query(Account).filter_by(space_id=space_id, system_key=SAVINGS_SYSTEM_KEY).one_or_none()
|
||||
)
|
||||
|
||||
|
||||
def _savings_category(db: Session, *, space_id: uuid.UUID) -> Category | None:
|
||||
return (
|
||||
db.query(Category)
|
||||
.filter_by(space_id=space_id, system_key=SAVINGS_SYSTEM_KEY)
|
||||
.one_or_none()
|
||||
db.query(Category).filter_by(space_id=space_id, system_key=SAVINGS_SYSTEM_KEY).one_or_none()
|
||||
)
|
||||
|
||||
|
||||
@@ -143,9 +139,7 @@ def adjust_balance(
|
||||
"Credit account balances cannot be adjusted with a non-negative target",
|
||||
)
|
||||
if target_balance_kopecks < 0:
|
||||
raise bad_request(
|
||||
"LEDGER_ADJUST_TARGET_NEGATIVE", "Target balance cannot be negative"
|
||||
)
|
||||
raise bad_request("LEDGER_ADJUST_TARGET_NEGATIVE", "Target balance cannot be negative")
|
||||
from app.ledger.service import account_balance, ensure_period_open_for_date
|
||||
|
||||
ensure_period_open_for_date(db, space_id=space_id, day=occurred_on)
|
||||
@@ -277,9 +271,7 @@ def convert_expense_to_savings(
|
||||
"operation_id": str(operation.id),
|
||||
"savings_account_id": str(savings_account.id),
|
||||
"amount_kopecks": operation.amount_kopecks,
|
||||
"previous_category_id": (
|
||||
str(previous_category_id) if previous_category_id else None
|
||||
),
|
||||
"previous_category_id": (str(previous_category_id) if previous_category_id else None),
|
||||
},
|
||||
)
|
||||
return operation
|
||||
|
||||
Reference in New Issue
Block a user