From 122449f8fc9a1b4dc1e7f0f3ee44c39180ef6a26 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Wed, 15 Jan 2020 11:21:23 -0500 Subject: [PATCH] fix issue #13 --- core/model/account.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/model/account.go b/core/model/account.go index 0bff9c1..a2dd94d 100644 --- a/core/model/account.go +++ b/core/model/account.go @@ -43,6 +43,17 @@ func (model *Model) CreateAccount(account *types.Account, userId string) (err er return errors.New("currency required") } + // don't allow setting parent that has transactions + count, err := model.db.GetSplitCountByAccountId(account.Parent) + + if err != nil { + return + } + + if count != 0 { + return errors.New("cannot set parent to account with transactions") + } + userAccounts, err := model.GetAccounts(account.OrgId, userId, "") if err != nil {