mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
change transaction type of credit card payment to transfer transaction
This commit is contained in:
@@ -120,11 +120,13 @@ func TestOFXTransactionDataFileParseImportedData_MinimumValidData(t *testing.T)
|
|||||||
assert.Equal(t, "", allNewTransactions[3].OriginalCategoryName)
|
assert.Equal(t, "", allNewTransactions[3].OriginalCategoryName)
|
||||||
|
|
||||||
assert.Equal(t, int64(1234567890), allNewTransactions[4].Uid)
|
assert.Equal(t, int64(1234567890), allNewTransactions[4].Uid)
|
||||||
assert.Equal(t, models.TRANSACTION_DB_TYPE_INCOME, allNewTransactions[4].Type)
|
assert.Equal(t, models.TRANSACTION_DB_TYPE_TRANSFER_OUT, allNewTransactions[4].Type)
|
||||||
assert.Equal(t, int64(1725211425), utils.GetUnixTimeFromTransactionTime(allNewTransactions[4].TransactionTime))
|
assert.Equal(t, int64(1725211425), utils.GetUnixTimeFromTransactionTime(allNewTransactions[4].TransactionTime))
|
||||||
assert.Equal(t, int64(123), allNewTransactions[4].Amount)
|
assert.Equal(t, int64(123), allNewTransactions[4].Amount)
|
||||||
assert.Equal(t, "456", allNewTransactions[4].OriginalSourceAccountName)
|
assert.Equal(t, "", allNewTransactions[4].OriginalSourceAccountName)
|
||||||
assert.Equal(t, "USD", allNewTransactions[4].OriginalSourceAccountCurrency)
|
assert.Equal(t, "USD", allNewTransactions[4].OriginalSourceAccountCurrency)
|
||||||
|
assert.Equal(t, "456", allNewTransactions[4].OriginalDestinationAccountName)
|
||||||
|
assert.Equal(t, "USD", allNewTransactions[4].OriginalDestinationAccountCurrency)
|
||||||
assert.Equal(t, "", allNewTransactions[4].OriginalCategoryName)
|
assert.Equal(t, "", allNewTransactions[4].OriginalCategoryName)
|
||||||
|
|
||||||
assert.Equal(t, int64(1234567890), allNewTransactions[5].Uid)
|
assert.Equal(t, int64(1234567890), allNewTransactions[5].Uid)
|
||||||
|
|||||||
@@ -29,9 +29,10 @@ var ofxTransactionSupportedColumns = map[datatable.TransactionDataTableColumn]bo
|
|||||||
// ofxTransactionData defines the structure of open financial exchange (ofx) transaction data
|
// ofxTransactionData defines the structure of open financial exchange (ofx) transaction data
|
||||||
type ofxTransactionData struct {
|
type ofxTransactionData struct {
|
||||||
ofxBaseStatementTransaction
|
ofxBaseStatementTransaction
|
||||||
DefaultCurrency string
|
DefaultCurrency string
|
||||||
FromAccountId string
|
FromAccountId string
|
||||||
ToAccountId string
|
FromCreditAccount bool
|
||||||
|
ToAccountId string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ofxTransactionDataTable defines the structure of open financial exchange (ofx) transaction data table
|
// ofxTransactionDataTable defines the structure of open financial exchange (ofx) transaction data table
|
||||||
@@ -187,6 +188,22 @@ func (t *ofxTransactionDataRowIterator) parseTransaction(ctx core.Context, user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if data[datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TYPE] != ofxTransactionTypeNameMapping[models.TRANSACTION_TYPE_TRANSFER] {
|
||||||
|
if ofxTransaction.FromCreditAccount || ofxTransaction.TransactionType == ofxGenericCreditTransaction {
|
||||||
|
if amount >= 0 { // payment
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TYPE] = ofxTransactionTypeNameMapping[models.TRANSACTION_TYPE_TRANSFER]
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_AMOUNT] = utils.FormatAmount(amount)
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_RELATED_ACCOUNT_NAME] = data[datatable.TRANSACTION_DATA_TABLE_ACCOUNT_NAME]
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_RELATED_ACCOUNT_CURRENCY] = data[datatable.TRANSACTION_DATA_TABLE_ACCOUNT_CURRENCY]
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_RELATED_AMOUNT] = data[datatable.TRANSACTION_DATA_TABLE_AMOUNT]
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_ACCOUNT_NAME] = ""
|
||||||
|
} else { // purchase
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TYPE] = ofxTransactionTypeNameMapping[models.TRANSACTION_TYPE_EXPENSE]
|
||||||
|
data[datatable.TRANSACTION_DATA_TABLE_AMOUNT] = utils.FormatAmount(-amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ofxTransaction.Memo != "" {
|
if ofxTransaction.Memo != "" {
|
||||||
data[datatable.TRANSACTION_DATA_TABLE_DESCRIPTION] = ofxTransaction.Memo
|
data[datatable.TRANSACTION_DATA_TABLE_DESCRIPTION] = ofxTransaction.Memo
|
||||||
} else if ofxTransaction.Name != "" {
|
} else if ofxTransaction.Name != "" {
|
||||||
@@ -264,9 +281,14 @@ func createNewOFXTransactionDataTable(file *ofxFile) (*ofxTransactionDataTable,
|
|||||||
statement := file.BankMessageResponseV1.StatementTransactionResponse.StatementResponse
|
statement := file.BankMessageResponseV1.StatementTransactionResponse.StatementResponse
|
||||||
bankTransactions := statement.TransactionList.StatementTransactions
|
bankTransactions := statement.TransactionList.StatementTransactions
|
||||||
fromAccountId := ""
|
fromAccountId := ""
|
||||||
|
fromCreditAccount := false
|
||||||
|
|
||||||
if statement.AccountFrom != nil {
|
if statement.AccountFrom != nil {
|
||||||
fromAccountId = statement.AccountFrom.AccountId
|
fromAccountId = statement.AccountFrom.AccountId
|
||||||
|
|
||||||
|
if statement.AccountFrom.AccountType == ofxLineOfCreditAccount {
|
||||||
|
fromCreditAccount = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(bankTransactions); i++ {
|
for i := 0; i < len(bankTransactions); i++ {
|
||||||
@@ -280,6 +302,7 @@ func createNewOFXTransactionDataTable(file *ofxFile) (*ofxTransactionDataTable,
|
|||||||
ofxBaseStatementTransaction: bankTransactions[i].ofxBaseStatementTransaction,
|
ofxBaseStatementTransaction: bankTransactions[i].ofxBaseStatementTransaction,
|
||||||
DefaultCurrency: statement.DefaultCurrency,
|
DefaultCurrency: statement.DefaultCurrency,
|
||||||
FromAccountId: fromAccountId,
|
FromAccountId: fromAccountId,
|
||||||
|
FromCreditAccount: fromCreditAccount,
|
||||||
ToAccountId: toAccountId,
|
ToAccountId: toAccountId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -308,6 +331,7 @@ func createNewOFXTransactionDataTable(file *ofxFile) (*ofxTransactionDataTable,
|
|||||||
ofxBaseStatementTransaction: bankTransactions[i].ofxBaseStatementTransaction,
|
ofxBaseStatementTransaction: bankTransactions[i].ofxBaseStatementTransaction,
|
||||||
DefaultCurrency: statement.DefaultCurrency,
|
DefaultCurrency: statement.DefaultCurrency,
|
||||||
FromAccountId: fromAccountId,
|
FromAccountId: fromAccountId,
|
||||||
|
FromCreditAccount: true,
|
||||||
ToAccountId: toAccountId,
|
ToAccountId: toAccountId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user