From 905e30d87b6d8b48a0bc9532fd0eb3be0d3f014e Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 9 Jun 2017 05:37:42 -0400 Subject: [PATCH] Move RemoteId from transactions to splits This is the more sensible location for it, since we import things on a per-account basis - so there can be more than one remote ID associated with a transaction, and the splits are the per-account portion of transactions anyway. --- ofx.go | 7 +++++-- transactions.go | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ofx.go b/ofx.go index e06e657..59f1ee6 100644 --- a/ofx.go +++ b/ofx.go @@ -44,8 +44,7 @@ func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *Account) er var t Transaction t.Date = tran.DtPosted.UTC() - t.RemoteId = tran.FiTID.String() - // TODO CorrectFiTID/CorrectAction? + // Construct the description from whichever of the descriptive OFX fields are present if len(tran.Name) > 0 { t.Description = string(tran.Name) @@ -80,6 +79,10 @@ func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *Account) er if account.SecurityId < 1 || account.SecurityId > int64(len(i.Securities)) { return errors.New("Internal error: security index not found in OFX import\n") } + + s1.RemoteId = tran.FiTID.String() + // TODO CorrectFiTID/CorrectAction? + security := i.Securities[account.SecurityId-1] s1.Amount = amt.FloatString(security.Precision) s2.Amount = amt.Neg(amt).FloatString(security.Precision) diff --git a/transactions.go b/transactions.go index c7e68f8..af4a19b 100644 --- a/transactions.go +++ b/transactions.go @@ -34,9 +34,10 @@ type Split struct { AccountId int64 SecurityId int64 - Number string // Check or reference number - Memo string - Amount string // String representation of decimal, suitable for passing to big.Rat.SetString() + RemoteId string // unique ID from server, for detecting duplicates + Number string // Check or reference number + Memo string + Amount string // String representation of decimal, suitable for passing to big.Rat.SetString() } func GetBigAmount(amt string) (*big.Rat, error) { @@ -63,7 +64,6 @@ func (s *Split) Valid() bool { type Transaction struct { TransactionId int64 UserId int64 - RemoteId string // unique ID from server, for detecting duplicates Description string Date time.Time Splits []*Split `db:"-"`