Skip to content

Commit 6e9f109

Browse files
authored
feat: allow transactions to be created without an Envelope (#273)
This removes the requirement for Incoming and Outgoing transactions to have an Envelope. With this, “Income” transactions that make money available for budgeting are possible. At the same time, if a tracking error occurs, reconciling transactions are now possible. Those either remove money from the budget that does not exist or add money that was not tracked before (same as an income transaction). Neither of those two types logically requires an Envelope.
1 parent db1e124 commit 6e9f109

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

pkg/controllers/transaction.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,20 @@ func CreateTransaction(c *gin.Context) {
102102
}
103103

104104
// Check the source account
105-
sourceAccount, err := getAccountResource(c, transaction.SourceAccountID)
105+
_, err = getAccountResource(c, transaction.SourceAccountID)
106106
if err != nil {
107107
return
108108
}
109109

110110
// Check the destination account
111-
destinationAccount, err := getAccountResource(c, transaction.DestinationAccountID)
111+
_, err = getAccountResource(c, transaction.DestinationAccountID)
112112
if err != nil {
113113
return
114114
}
115115

116-
// Check if the transaction is a transfer. If yes, the envelope can be empty.
117-
//
118-
// Check that the Envelope ID is set for incoming and outgoing transactions
119-
if sourceAccount.External || destinationAccount.External && transaction.EnvelopeID == nil {
120-
httputil.NewError(c, http.StatusBadRequest, errors.New("For incoming and outgoing transactions, an envelope is required"))
121-
return
122-
123-
// Check the envelope ID only if it is set. (This will always evaluate to true for incoming and outgoing transactions,
124-
// but for transfers, can evaluate to false
125-
} else if transaction.EnvelopeID != nil {
116+
// Check the envelope ID only if it is set. (This will always evaluate to true for incoming and outgoing transactions,
117+
// but for transfers, can evaluate to false
118+
if transaction.EnvelopeID != nil {
126119
_, err = getEnvelopeResource(c, *transaction.EnvelopeID)
127120
if err != nil {
128121
return

pkg/controllers/transaction_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ func (suite *TestSuiteEnv) TestCreateNoEnvelopeTransactionOutgoing() {
228228
}
229229

230230
recorder := test.Request(suite.T(), http.MethodPost, "http://example.com/v1/transactions", c)
231-
test.AssertHTTPStatus(suite.T(), http.StatusBadRequest, &recorder)
232-
233-
err := test.DecodeError(suite.T(), recorder.Body.Bytes())
234-
assert.Equal(suite.T(), "For incoming and outgoing transactions, an envelope is required", err)
231+
test.AssertHTTPStatus(suite.T(), http.StatusCreated, &recorder)
235232
}
236233

237234
func (suite *TestSuiteEnv) TestCreateNonExistingEnvelopeTransactionTransfer() {

0 commit comments

Comments
 (0)