1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-01 12:08:37 -04:00

Add ability to delete accounts to UI

This commit is contained in:
2015-07-04 21:11:00 -04:00
parent 81bdc03b10
commit 0377b5f42b
2 changed files with 188 additions and 43 deletions

View File

@ -131,11 +131,20 @@ func DeleteAccount(a *Account) error {
return err
}
// Re-parent splits to this account's parent account
_, err = transaction.Exec("UPDATE splits SET AccountId=? WHERE AccountId=?", a.ParentAccountId, a.AccountId)
if err != nil {
transaction.Rollback()
return err
if a.ParentAccountId != -1 {
// Re-parent splits to this account's parent account if this account isn't a root account
_, err = transaction.Exec("UPDATE splits SET AccountId=? WHERE AccountId=?", a.ParentAccountId, a.AccountId)
if err != nil {
transaction.Rollback()
return err
}
} else {
// Delete splits if this account is a root account
_, err = transaction.Exec("DELETE FROM splits WHERE AccountId=?", a.AccountId)
if err != nil {
transaction.Rollback()
return err
}
}
// Re-parent child accounts to this account's parent account