You've already forked monobank-firefly3-bot
Add duplicate transaction check from log and transaction description LIKE match
This commit is contained in:
@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -28,6 +29,15 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// check if transaction hs been logged
|
||||
isTransactionAlreadyLogged, err := LogContainsTransactionID(monobankTransaction.Data.StatementItem.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isTransactionAlreadyLogged {
|
||||
return nil
|
||||
}
|
||||
|
||||
// find accounts
|
||||
destAccount := App().Config.GetAccountByMonobankId(monobankTransaction.Data.Account)
|
||||
|
||||
@ -92,8 +102,21 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
}
|
||||
break
|
||||
} else {
|
||||
// check name match
|
||||
isDescriptionMatch := false
|
||||
if row.NamesLooseMatch {
|
||||
for _, name := range row.Names {
|
||||
if strings.HasPrefix(monobankTransaction.Data.StatementItem.Description, name) {
|
||||
isDescriptionMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isDescriptionMatch = slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description)
|
||||
}
|
||||
|
||||
// check name & mcc
|
||||
if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, int(monobankTransaction.Data.StatementItem.Mcc))) {
|
||||
if !(isDescriptionMatch || slices.Contains(row.MccCodes, int(monobankTransaction.Data.StatementItem.Mcc))) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user