Fix: allow updating transfer transactions
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
0b525f72ec
commit
ded3444391
2 changed files with 4 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue