Commit 9b054dac authored by Łukasz Wojniłowicz's avatar Łukasz Wojniłowicz
Browse files

Add fee for buy and sell operation in the right way

Fee should be added to buy and substracted from sell
operations. Difference between balance for banking and investment
account should include fees.

BUG: 361021
REVIEW: 127711
parent 1f71ae2a
......@@ -830,29 +830,29 @@ void MyMoneyStatementReader::processTransactionEntry(const MyMoneyStatement::Tra
transfervalue = statementTransactionUnderImport.m_amount;
} else if ((statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaBuy) ||
(statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaSell)) {
if (!statementTransactionUnderImport.m_price.isZero()) {
} else if (statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaBuy) {
s1.setAction(MyMoneySplit::ActionBuyShares);
if (!statementTransactionUnderImport.m_price.isZero()) {
s1.setPrice(statementTransactionUnderImport.m_price.abs());
} else {
if (!statementTransactionUnderImport.m_shares.isZero()) {
MyMoneyMoney total = -statementTransactionUnderImport.m_amount - statementTransactionUnderImport.m_fees;
s1.setPrice((total / statementTransactionUnderImport.m_shares).abs().convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())));
}
} else if (!statementTransactionUnderImport.m_shares.isZero()) {
MyMoneyMoney total = statementTransactionUnderImport.m_amount.abs() - statementTransactionUnderImport.m_fees.abs();
s1.setPrice((total / statementTransactionUnderImport.m_shares).abs().convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())));
}
s1.setShares(statementTransactionUnderImport.m_shares.abs());
s1.setValue(statementTransactionUnderImport.m_amount.abs() - statementTransactionUnderImport.m_fees.abs());
transfervalue = -(statementTransactionUnderImport.m_amount.abs());
} else if (statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaSell) {
s1.setAction(MyMoneySplit::ActionBuyShares);
// Make sure to setup the sign correctly
if (statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaBuy) {
s1.setShares(statementTransactionUnderImport.m_shares.abs());
s1.setValue(s1.value().abs());
transfervalue = -(statementTransactionUnderImport.m_amount.abs());
} else {
s1.setShares(-(statementTransactionUnderImport.m_shares.abs()));
s1.setValue(-(s1.value().abs()));
transfervalue = statementTransactionUnderImport.m_amount.abs();
if (!statementTransactionUnderImport.m_price.isZero()) {
s1.setPrice(statementTransactionUnderImport.m_price.abs());
} else if (!statementTransactionUnderImport.m_shares.isZero()) {
MyMoneyMoney total = statementTransactionUnderImport.m_amount.abs() + statementTransactionUnderImport.m_fees.abs();
s1.setPrice((total / statementTransactionUnderImport.m_shares).abs().convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())));
}
s1.setShares(-(statementTransactionUnderImport.m_shares.abs()));
s1.setValue(-(statementTransactionUnderImport.m_amount.abs() + statementTransactionUnderImport.m_fees.abs()));
transfervalue = statementTransactionUnderImport.m_amount.abs();
} else if ((statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaShrsin) ||
(statementTransactionUnderImport.m_eAction == MyMoneyStatement::Transaction::eaShrsout)) {
......
......@@ -1699,19 +1699,21 @@ void InvestProcessing::investCsvImport(MyMoneyStatement& st)
tr.m_strSymbol = m_trInvestData.symbol;
s2.m_accountId = m_csvUtil->checkCategory(m_csvSplit.m_strCategoryName, s1.m_amount, s2.m_amount);
tr.m_strBrokerageAccount = m_trInvestData.brokerageAccnt;
if ((tr.m_eAction == (MyMoneyStatement::Transaction::eaCashDividend)) ||
(tr.m_eAction == (MyMoneyStatement::Transaction::eaBuy)) ||
(tr.m_eAction == (MyMoneyStatement::Transaction::eaSell)) ||
(tr.m_eAction == (MyMoneyStatement::Transaction::eaInterest))) {
tr.m_strBrokerageAccount = m_trInvestData.brokerageAccnt;
/*
* need to deduct fees here
*/
tr.m_amount -= m_trInvestData.fee;
tr.m_amount = tr.m_amount.abs() - m_trInvestData.fee.abs();
}
else if (tr.m_eAction == (MyMoneyStatement::Transaction::eaBuy)) {
tr.m_amount = tr.m_amount.abs() + m_trInvestData.fee.abs();
}
else if (tr.m_eAction == (MyMoneyStatement::Transaction::eaNone)) {
tr.m_strBrokerageAccount = m_trInvestData.brokerageAccnt;
tr.m_listSplits += s2;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment