place the account at the end of the account category after changing account category

This commit is contained in:
MaysWind
2026-01-17 23:32:13 +08:00
parent 8db69f64c8
commit 46ff0ecd3b
2 changed files with 22 additions and 11 deletions
+21 -10
View File
@@ -437,6 +437,17 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount, false) toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount, false)
if toUpdateAccount != nil { if toUpdateAccount != nil {
if toUpdateAccount.Category != mainAccount.Category {
maxOrderId, err := a.accounts.GetMaxDisplayOrder(c, uid, toUpdateAccount.Category)
if err != nil {
log.Errorf(c, "[accounts.AccountModifyHandler] failed to get max display order for user \"uid:%d\", because %s", uid, err.Error())
return nil, errs.Or(err, errs.ErrOperationFailed)
}
toUpdateAccount.DisplayOrder = maxOrderId + 1
}
anythingUpdate = true anythingUpdate = true
toUpdateAccounts = append(toUpdateAccounts, toUpdateAccount) toUpdateAccounts = append(toUpdateAccounts, toUpdateAccount)
} }
@@ -542,7 +553,6 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
account.Type = oldAccount.Type account.Type = oldAccount.Type
account.ParentAccountId = oldAccount.ParentAccountId account.ParentAccountId = oldAccount.ParentAccountId
account.DisplayOrder = oldAccount.DisplayOrder
account.Currency = oldAccount.Currency account.Currency = oldAccount.Currency
account.Balance = oldAccount.Balance account.Balance = oldAccount.Balance
@@ -762,15 +772,16 @@ func (a *AccountsApi) getToUpdateAccount(uid int64, accountModifyReq *models.Acc
} }
newAccount := &models.Account{ newAccount := &models.Account{
AccountId: oldAccount.AccountId, AccountId: oldAccount.AccountId,
Uid: uid, Uid: uid,
Name: accountModifyReq.Name, Name: accountModifyReq.Name,
Category: accountModifyReq.Category, DisplayOrder: oldAccount.DisplayOrder,
Icon: accountModifyReq.Icon, Category: accountModifyReq.Category,
Color: accountModifyReq.Color, Icon: accountModifyReq.Icon,
Comment: accountModifyReq.Comment, Color: accountModifyReq.Color,
Extend: newAccountExtend, Comment: accountModifyReq.Comment,
Hidden: accountModifyReq.Hidden, Extend: newAccountExtend,
Hidden: accountModifyReq.Hidden,
} }
if newAccount.Name != oldAccount.Name || if newAccount.Name != oldAccount.Name ||
+1 -1
View File
@@ -445,7 +445,7 @@ func (s *AccountService) ModifyAccounts(c core.Context, mainAccount *models.Acco
// update accounts // update accounts
for i := 0; i < len(updateAccounts); i++ { for i := 0; i < len(updateAccounts); i++ {
account := updateAccounts[i] account := updateAccounts[i]
updatedRows, err := sess.ID(account.AccountId).Cols("name", "category", "icon", "color", "comment", "extend", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", account.Uid, false).Update(account) updatedRows, err := sess.ID(account.AccountId).Cols("name", "display_order", "category", "icon", "color", "comment", "extend", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", account.Uid, false).Update(account)
if err != nil { if err != nil {
return err return err