not map to parent accounts, hidden accounts, and hidden categories when importing transactions
This commit is contained in:
@@ -1287,7 +1287,7 @@ func (a *TransactionsApi) TransactionParseImportFileHandler(c *core.WebContext)
|
||||
return nil, errs.Or(err, errs.ErrOperationFailed)
|
||||
}
|
||||
|
||||
accountMap := a.accounts.GetAccountNameMapByList(accounts)
|
||||
accountMap := a.accounts.GetVisibleAccountNameMapByList(accounts)
|
||||
|
||||
categories, err := a.transactionCategories.GetAllCategoriesByUid(c, user.Uid, 0, -1)
|
||||
|
||||
@@ -1296,7 +1296,7 @@ func (a *TransactionsApi) TransactionParseImportFileHandler(c *core.WebContext)
|
||||
return nil, errs.Or(err, errs.ErrOperationFailed)
|
||||
}
|
||||
|
||||
expenseCategoryMap, incomeCategoryMap, transferCategoryMap := a.transactionCategories.GetSubCategoryNameMapByList(categories)
|
||||
expenseCategoryMap, incomeCategoryMap, transferCategoryMap := a.transactionCategories.GetVisibleSubCategoryNameMapByList(categories)
|
||||
|
||||
tags, err := a.transactionTags.GetAllTagsByUid(c, user.Uid)
|
||||
|
||||
|
||||
@@ -889,7 +889,7 @@ func (l *UserDataCli) getUserEssentialDataForImport(c *core.CliContext, uid int6
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
accountMap = l.accounts.GetAccountNameMapByList(accounts)
|
||||
accountMap = l.accounts.GetVisibleAccountNameMapByList(accounts)
|
||||
|
||||
categories, err := l.categories.GetAllCategoriesByUid(c, uid, 0, -1)
|
||||
|
||||
@@ -898,7 +898,7 @@ func (l *UserDataCli) getUserEssentialDataForImport(c *core.CliContext, uid int6
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
|
||||
expenseCategoryMap, incomeCategoryMap, transferCategoryMap = l.categories.GetSubCategoryNameMapByList(categories)
|
||||
expenseCategoryMap, incomeCategoryMap, transferCategoryMap = l.categories.GetVisibleSubCategoryNameMapByList(categories)
|
||||
|
||||
tags, err := l.tags.GetAllTagsByUid(c, uid)
|
||||
|
||||
|
||||
@@ -774,12 +774,21 @@ func (s *AccountService) GetAccountMapByList(accounts []*models.Account) map[int
|
||||
return accountMap
|
||||
}
|
||||
|
||||
// GetAccountNameMapByList returns an account map by a list
|
||||
func (s *AccountService) GetAccountNameMapByList(accounts []*models.Account) map[string]*models.Account {
|
||||
// GetVisibleAccountNameMapByList returns visible account map by a list
|
||||
func (s *AccountService) GetVisibleAccountNameMapByList(accounts []*models.Account) map[string]*models.Account {
|
||||
accountMap := make(map[string]*models.Account)
|
||||
|
||||
for i := 0; i < len(accounts); i++ {
|
||||
account := accounts[i]
|
||||
|
||||
if account.Hidden {
|
||||
continue
|
||||
}
|
||||
|
||||
if account.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
|
||||
continue
|
||||
}
|
||||
|
||||
accountMap[account.Name] = account
|
||||
}
|
||||
return accountMap
|
||||
|
||||
@@ -451,8 +451,8 @@ func (s *TransactionCategoryService) GetCategoryMapByList(categories []*models.T
|
||||
return categoryMap
|
||||
}
|
||||
|
||||
// GetSubCategoryNameMapByList returns a sub transaction category map by a list
|
||||
func (s *TransactionCategoryService) GetSubCategoryNameMapByList(categories []*models.TransactionCategory) (expenseCategoryMap map[string]map[string]*models.TransactionCategory, incomeCategoryMap map[string]map[string]*models.TransactionCategory, transferCategoryMap map[string]map[string]*models.TransactionCategory) {
|
||||
// GetVisibleSubCategoryNameMapByList returns visible sub transaction category map by a list
|
||||
func (s *TransactionCategoryService) GetVisibleSubCategoryNameMapByList(categories []*models.TransactionCategory) (expenseCategoryMap map[string]map[string]*models.TransactionCategory, incomeCategoryMap map[string]map[string]*models.TransactionCategory, transferCategoryMap map[string]map[string]*models.TransactionCategory) {
|
||||
categoryMap := make(map[int64]*models.TransactionCategory, len(categories))
|
||||
expenseCategoryMap = make(map[string]map[string]*models.TransactionCategory)
|
||||
incomeCategoryMap = make(map[string]map[string]*models.TransactionCategory)
|
||||
@@ -466,6 +466,10 @@ func (s *TransactionCategoryService) GetSubCategoryNameMapByList(categories []*m
|
||||
for i := 0; i < len(categories); i++ {
|
||||
category := categories[i]
|
||||
|
||||
if category.Hidden {
|
||||
continue
|
||||
}
|
||||
|
||||
if category.ParentCategoryId == models.LevelOneTransactionCategoryParentId {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user