-feat 修复部分bug

This commit is contained in:
2026-01-27 18:42:35 +08:00
parent a339a9adce
commit 6422f2c45f
10 changed files with 1001 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ type TransactionFilter struct {
// Entity filters
CategoryID *uint
AccountID *uint
LedgerID *uint // 账本过滤
TagIDs []uint
Type *models.TransactionType
Currency *models.Currency
@@ -277,6 +278,13 @@ func (r *TransactionRepository) applyFilters(query *gorm.DB, filter TransactionF
if filter.RecurringID != nil {
query = query.Where("recurring_id = ?", *filter.RecurringID)
}
// LedgerID filter - requires subquery to get accounts belonging to the ledger
if filter.LedgerID != nil {
query = query.Where("account_id IN (?)",
r.db.Model(&models.Account{}).
Select("id").
Where("ledger_id = ?", *filter.LedgerID))
}
// UserID provided in argument takes precedence, but if filter has it, we can redundant check or ignore.
// The caller `List` already applied `Where("user_id = ?", userID)`.