Skip to content

Commit 23d1e08

Browse files
committed
Fix import account matching
1 parent bc98784 commit 23d1e08

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

ledger/cmd/import.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,27 @@ var importCmd = &cobra.Command{
112112
csvDate, _ := time.Parse(csvDateFormat, record[dateColumn])
113113
if allowMatching || !existingTransaction(generalLedger, csvDate, inputPayeeWords[0]) {
114114
// Classify into expense account
115-
_, likely, _ := classifier.LogScores(inputPayeeWords)
115+
scores, likely, _ := classifier.LogScores(inputPayeeWords)
116116
if likely >= 0 {
117-
expenseAccount.Name = string(classifier.Classes[likely])
117+
matchScore := 0.0
118+
matchIdx := -1
119+
for j, score := range scores {
120+
if j == 0 {
121+
matchScore = score
122+
}
123+
if string(classifier.Classes[j]) == csvAccount.Name {
124+
continue
125+
}
126+
if score > matchScore {
127+
matchScore = score
128+
matchIdx = j
129+
}
130+
}
131+
if matchIdx >= 0 {
132+
expenseAccount.Name = string(classifier.Classes[matchIdx])
133+
} else {
134+
expenseAccount.Name = string(classifier.Classes[likely])
135+
}
118136
}
119137

120138
// Parse error, set to zero

0 commit comments

Comments
 (0)