Fix: allow updating transfer transactions

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-02-01 12:00:00 +01:00
parent 0b525f72ec
commit ded3444391
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E
2 changed files with 4 additions and 1 deletions

View file

@ -457,6 +457,7 @@ func (c *Client) UpdateTransaction(txID uuid.UUID, tx Transaction) (err error) {
tx.ID = txID tx.ID = txID
tx.Account = oldTX.Account // Changing that would create chaos 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 { if err = tx.Validate(c); err != nil {
return fmt.Errorf("validating transaction: %w", err) return fmt.Errorf("validating transaction: %w", err)

View file

@ -82,6 +82,8 @@ func (b *BaseModel) BeforeCreate(*gorm.DB) (err error) {
} }
// Validate executes some basic checks on the transaction // Validate executes some basic checks on the transaction
//
//nolint:gocyclo
func (t Transaction) Validate(c *Client) (err error) { func (t Transaction) Validate(c *Client) (err error) {
var errs []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")) errs = append(errs, fmt.Errorf("budget account transactions need a category"))
} }