change the type of balance modification transaction to income or expense for imported feidee mymoney transaction data

This commit is contained in:
MaysWind
2024-09-18 23:04:00 +08:00
parent 8b92051900
commit fceb92eb6f
7 changed files with 117 additions and 67 deletions
@@ -49,8 +49,12 @@ type DataTableTransactionDataImporter struct {
transactionTypeMapping map[models.TransactionType]string
geoLocationSeparator string
transactionTagSeparator string
postProcessFunc DataTableTransactionDataImporterPostProcessFunc
}
// DataTableTransactionDataImporterPostProcessFunc represents item post process function of DataTableTransactionDataImporter
type DataTableTransactionDataImporterPostProcessFunc func(core.Context, *models.ImportTransaction) error
func (c *DataTableTransactionDataExporter) buildExportedContent(ctx core.Context, dataTableBuilder DataTableBuilder, uid int64, transactions []*models.Transaction, accountMap map[int64]*models.Account, categoryMap map[int64]*models.TransactionCategory, tagMap map[int64]*models.TransactionTag, allTagIndexes map[int64][]int64) error {
for i := 0; i < len(transactions); i++ {
transaction := transactions[i]
@@ -492,6 +496,15 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
OriginalTagNames: tagNames,
}
if c.postProcessFunc != nil {
err = c.postProcessFunc(ctx, transaction)
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot post process data row \"index:%d\" for user \"uid:%d\", because %s", dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
}
}
allNewTransactions = append(allNewTransactions, transaction)
}