From ded34443910c895460cf8b231b0b9f67026ce588 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 1 Feb 2024 12:00:00 +0100 Subject: [PATCH] Fix: allow updating transfer transactions Signed-off-by: Knut Ahlers --- pkg/database/database.go | 1 + pkg/database/schema.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/database/database.go b/pkg/database/database.go index 5499bbc..34d256b 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -457,6 +457,7 @@ func (c *Client) UpdateTransaction(txID uuid.UUID, tx Transaction) (err error) { tx.ID = txID tx.Account = oldTX.Account // Changing that would create chaos + tx.PairKey = oldTX.PairKey // Updating a paired tx should not decouple it if err = tx.Validate(c); err != nil { return fmt.Errorf("validating transaction: %w", err) diff --git a/pkg/database/schema.go b/pkg/database/schema.go index 0470253..ed46bdb 100644 --- a/pkg/database/schema.go +++ b/pkg/database/schema.go @@ -82,6 +82,8 @@ func (b *BaseModel) BeforeCreate(*gorm.DB) (err error) { } // Validate executes some basic checks on the transaction +// +//nolint:gocyclo func (t Transaction) Validate(c *Client) (err error) { var errs []error @@ -110,7 +112,7 @@ func (t Transaction) Validate(c *Client) (err error) { } } - if acc.Type == AccountTypeBudget && !t.Category.Valid { + if acc.Type == AccountTypeBudget && !t.Category.Valid && !t.PairKey.Valid { errs = append(errs, fmt.Errorf("budget account transactions need a category")) }