Skip to content

Commit

Permalink
fix duplicate doc no handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyek committed Jun 10, 2024
1 parent 24b0146 commit a5182f6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions projects/update-ynab/Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion projects/update-ynab/banks/banks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion projects/update-ynab/ynab/parse_ynab_tx_memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down

0 comments on commit a5182f6

Please sign in to comment.