From a5182f63d7eb8a91283f45db30b988dc78a7a08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Mon, 10 Jun 2024 11:35:57 -0600 Subject: [PATCH] fix duplicate doc no handling --- projects/update-ynab/Makefile | 2 ++ projects/update-ynab/banks/banks.go | 3 ++- projects/update-ynab/ynab/parse_ynab_tx_memo.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/update-ynab/Makefile b/projects/update-ynab/Makefile index 99e3273..80ed8dd 100644 --- a/projects/update-ynab/Makefile +++ b/projects/update-ynab/Makefile @@ -1,4 +1,6 @@ test: go test ./... +dev: + go run ./main.go build: # https://docs.aws.amazon.com/lambda/latest/dg/golang-package.html GOOS=linux GOARCH=arm64 go build -tags lambda.norpc -o bootstrap main.go diff --git a/projects/update-ynab/banks/banks.go b/projects/update-ynab/banks/banks.go index 35e054b..7b467c2 100644 --- a/projects/update-ynab/banks/banks.go +++ b/projects/update-ynab/banks/banks.go @@ -50,12 +50,13 @@ func LoadBankTxs(db *sqlx.DB) ([]types.BankAccountWithTransactions, error) { sameRefCount := 0 for _, iterTx := range bankAccount.Transactions { iterRef := fmt.Sprintf("%s_%s", iterTx.Date.Format("20060102"), iterTx.DocNo) - if bankTx != iterTx.BankTx && ref == iterRef { + if bankTx.Id != iterTx.BankTx.Id && ref == iterRef { sameRefCount += 1 } } if sameRefCount > 0 { ref = fmt.Sprintf("%s(%d)", ref, sameRefCount+1) + slog.Info("found duplicate doc no", "docno", bankTx.DocNo, "new ref", ref) } bankAccount.Transactions = append(bankAccount.Transactions, types.PreparedBankTx{ BankTx: bankTx, diff --git a/projects/update-ynab/ynab/parse_ynab_tx_memo.go b/projects/update-ynab/ynab/parse_ynab_tx_memo.go index 2254c2a..6df6373 100644 --- a/projects/update-ynab/ynab/parse_ynab_tx_memo.go +++ b/projects/update-ynab/ynab/parse_ynab_tx_memo.go @@ -24,7 +24,7 @@ func ParseYnabTransactionMemo(memo *string) (ParsedYnabTransactionMemo, error) { } } - rgx := regexp.MustCompile(`ref: ([\d_]+);`) + rgx := regexp.MustCompile(`ref: ([\d_\(\)]+);`) if matches := rgx.FindStringSubmatch(*memo); matches != nil { parsed.Ref = matches[1] }