From 423d4607478dd7c31f49f71d81615d3f3a9f0f36 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Wed, 6 Mar 2019 05:58:46 -0500 Subject: [PATCH] Bank transactions: Allow transaction currencies to be empty The XML marahaller will attempt to marshal the top-level elements, not knowing that the lower-level elements are empty. Making them pointers solves this. --- bank.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bank.go b/bank.go index 05cab71..53a7015 100644 --- a/bank.go +++ b/bank.go @@ -126,8 +126,8 @@ type Transaction struct { ImageData []ImageData `xml:"IMAGEDATA,omitempty"` // Only one of Currency and OrigCurrency can ever be Valid() for the same transaction - Currency Currency `xml:"CURRENCY,omitempty"` // Represents the currency of TrnAmt (instead of CURDEF in STMTRS) if Valid - OrigCurrency Currency `xml:"ORIGCURRENCY,omitempty"` // Represents the currency TrnAmt was converted to STMTRS' CURDEF from if Valid + Currency *Currency `xml:"CURRENCY,omitempty"` // Represents the currency of TrnAmt (instead of CURDEF in STMTRS) if Valid + OrigCurrency *Currency `xml:"ORIGCURRENCY,omitempty"` // Represents the currency TrnAmt was converted to STMTRS' CURDEF from if Valid Inv401kSource inv401kSource `xml:"INV401KSOURCE,omitempty"` // One of PRETAX, AFTERTAX, MATCH, PROFITSHARING, ROLLOVER, OTHERVEST, OTHERNONVEST (Default if not present is OTHERNONVEST. The following cash source types are subject to vesting: MATCH, PROFITSHARING, and OTHERVEST.) } @@ -166,8 +166,13 @@ func (t Transaction) Valid(version ofxVersion) (bool, error) { } else if len(t.ImageData) > 2 { return false, errors.New("Only 2 of ImageData allowed in Transaction") } - ok1, _ := t.Currency.Valid() - ok2, _ := t.OrigCurrency.Valid() + var ok1, ok2 bool + if t.Currency != nil { + ok1, _ = t.Currency.Valid() + } + if t.OrigCurrency != nil { + ok2, _ = t.OrigCurrency.Valid() + } if ok1 && ok2 { return false, errors.New("Currency and OrigCurrency both supplied for Pending Transaction, only one allowed") }