mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 09:44:26 +08:00
not allow to add / modify / delete transaction with account whose parent account is hidden
This commit is contained in:
@@ -24,6 +24,7 @@ var (
|
|||||||
ErrCannotCreateTransactionWithThisTransactionTime = NewNormalError(NormalSubcategoryTransaction, 17, http.StatusBadRequest, "cannot add transaction with this transaction time")
|
ErrCannotCreateTransactionWithThisTransactionTime = NewNormalError(NormalSubcategoryTransaction, 17, http.StatusBadRequest, "cannot add transaction with this transaction time")
|
||||||
ErrCannotModifyTransactionWithThisTransactionTime = NewNormalError(NormalSubcategoryTransaction, 18, http.StatusBadRequest, "cannot modify transaction with this transaction time")
|
ErrCannotModifyTransactionWithThisTransactionTime = NewNormalError(NormalSubcategoryTransaction, 18, http.StatusBadRequest, "cannot modify transaction with this transaction time")
|
||||||
ErrCannotDeleteTransactionWithThisTransactionTime = NewNormalError(NormalSubcategoryTransaction, 19, http.StatusBadRequest, "cannot delete transaction with this transaction time")
|
ErrCannotDeleteTransactionWithThisTransactionTime = NewNormalError(NormalSubcategoryTransaction, 19, http.StatusBadRequest, "cannot delete transaction with this transaction time")
|
||||||
ErrCannotUseHiddenTransactionCategory = NewNormalError(NormalSubcategoryTransaction, 20, http.StatusBadRequest, "cannot use hidden transaction category")
|
ErrCannotUseHiddenAccount = NewNormalError(NormalSubcategoryTransaction, 20, http.StatusBadRequest, "cannot use hidden account")
|
||||||
ErrCannotUseHiddenTransactionTag = NewNormalError(NormalSubcategoryTransaction, 21, http.StatusBadRequest, "cannot use hidden transaction tag")
|
ErrCannotUseHiddenTransactionCategory = NewNormalError(NormalSubcategoryTransaction, 21, http.StatusBadRequest, "cannot use hidden transaction category")
|
||||||
|
ErrCannotUseHiddenTransactionTag = NewNormalError(NormalSubcategoryTransaction, 22, http.StatusBadRequest, "cannot use hidden transaction tag")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1579,6 +1579,54 @@ func (s *TransactionService) getAccountModels(sess *xorm.Session, transaction *m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check whether the parent accounts are valid
|
||||||
|
if sourceAccount.ParentAccountId > 0 && destinationAccount != nil && sourceAccount.ParentAccountId != destinationAccount.ParentAccountId && destinationAccount.ParentAccountId > 0 {
|
||||||
|
var accounts []*models.Account
|
||||||
|
err := sess.Where("uid=? AND deleted=? and (account_id=? or account_id=?)", transaction.Uid, false, sourceAccount.ParentAccountId, destinationAccount.ParentAccountId).Find(&accounts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(accounts) < 2 {
|
||||||
|
return nil, nil, errs.ErrAccountNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(accounts); i++ {
|
||||||
|
account := accounts[i]
|
||||||
|
|
||||||
|
if account.Hidden {
|
||||||
|
return nil, nil, errs.ErrCannotUseHiddenAccount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if sourceAccount.ParentAccountId > 0 && (destinationAccount == nil || sourceAccount.ParentAccountId == destinationAccount.ParentAccountId || destinationAccount.ParentAccountId == 0) {
|
||||||
|
sourceParentAccount := &models.Account{}
|
||||||
|
has, err = sess.ID(sourceAccount.ParentAccountId).Where("uid=? AND deleted=?", transaction.Uid, false).Get(sourceParentAccount)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
} else if !has {
|
||||||
|
return nil, nil, errs.ErrSourceAccountNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceParentAccount.Hidden {
|
||||||
|
return nil, nil, errs.ErrCannotUseHiddenAccount
|
||||||
|
}
|
||||||
|
} else if sourceAccount.ParentAccountId == 0 && destinationAccount != nil && destinationAccount.ParentAccountId > 0 {
|
||||||
|
destinationParentAccount := &models.Account{}
|
||||||
|
has, err = sess.ID(destinationAccount.ParentAccountId).Where("uid=? AND deleted=?", transaction.Uid, false).Get(destinationParentAccount)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
} else if !has {
|
||||||
|
return nil, nil, errs.ErrDestinationAccountNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
if destinationParentAccount.Hidden {
|
||||||
|
return nil, nil, errs.ErrCannotUseHiddenAccount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sourceAccount, destinationAccount, nil
|
return sourceAccount, destinationAccount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -677,6 +677,7 @@ export default {
|
|||||||
'cannot add transaction with this transaction time': 'You cannot add transaction with this transaction time',
|
'cannot add transaction with this transaction time': 'You cannot add transaction with this transaction time',
|
||||||
'cannot modify transaction with this transaction time': 'You cannot modify this transaction with this transaction time',
|
'cannot modify transaction with this transaction time': 'You cannot modify this transaction with this transaction time',
|
||||||
'cannot delete transaction with this transaction time': 'You cannot delete this transaction with this transaction time',
|
'cannot delete transaction with this transaction time': 'You cannot delete this transaction with this transaction time',
|
||||||
|
'cannot use hidden account': 'You cannot use hidden account',
|
||||||
'cannot use hidden transaction category': 'You cannot use hidden transaction category',
|
'cannot use hidden transaction category': 'You cannot use hidden transaction category',
|
||||||
'cannot use hidden transaction tag': 'You cannot use hidden transaction tag',
|
'cannot use hidden transaction tag': 'You cannot use hidden transaction tag',
|
||||||
'transaction category id is invalid': 'Transaction category ID is invalid',
|
'transaction category id is invalid': 'Transaction category ID is invalid',
|
||||||
|
|||||||
@@ -677,6 +677,7 @@ export default {
|
|||||||
'cannot add transaction with this transaction time': '您不能添加该交易时间的交易',
|
'cannot add transaction with this transaction time': '您不能添加该交易时间的交易',
|
||||||
'cannot modify transaction with this transaction time': '您不能修改该交易时间的交易',
|
'cannot modify transaction with this transaction time': '您不能修改该交易时间的交易',
|
||||||
'cannot delete transaction with this transaction time': '您不能删除该交易时间的交易',
|
'cannot delete transaction with this transaction time': '您不能删除该交易时间的交易',
|
||||||
|
'cannot use hidden account': '您不能使用隐藏的账户',
|
||||||
'cannot use hidden transaction category': '您不能使用隐藏的交易分类',
|
'cannot use hidden transaction category': '您不能使用隐藏的交易分类',
|
||||||
'cannot use hidden transaction tag': '您不能使用隐藏的交易标签',
|
'cannot use hidden transaction tag': '您不能使用隐藏的交易标签',
|
||||||
'transaction category id is invalid': '交易分类ID无效',
|
'transaction category id is invalid': '交易分类ID无效',
|
||||||
|
|||||||
Reference in New Issue
Block a user