[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kmymoney] kmymoney/reports: Don't overweight investment performance report
From: Łukasz_Wojniłowicz <null () kde ! org>
Date: 2017-04-01 6:19:03
Message-ID: E1cuCNL-0003Wy-Fu () code ! kde ! org
[Download RAW message or body]
Git commit b337c849c061b232dc666379d7f21eaa55722607 by Łukasz Wojniłowicz.
Committed on 01/04/2017 at 06:17.
Pushed by wojnilowicz into branch 'master'.
Don't overweight investment performance report
Price, value, shares, institution, type aren't used by Investment
Performance and Capital Gains reports, so don't append them.
Signed-off-by: Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
M +53 -63 kmymoney/reports/querytable.cpp
M +0 -6 kmymoney/reports/tests/querytable-test.cpp
https://commits.kde.org/kmymoney/b337c849c061b232dc666379d7f21eaa55722607
diff --git a/kmymoney/reports/querytable.cpp b/kmymoney/reports/querytable.cpp
index e5fe6bd6..764ec9df 100644
--- a/kmymoney/reports/querytable.cpp
+++ b/kmymoney/reports/querytable.cpp
@@ -1398,7 +1398,6 @@ void QueryTable::constructAccountTable()
//make sure we have all subaccounts of investment accounts
includeInvestmentSubAccounts();
-
QMap<QString, CashFlowList> topAccounts; // for total calculation
QList<MyMoneyAccount> accounts;
file->accountList(accounts);
@@ -1417,73 +1416,65 @@ void QueryTable::constructAccountTable()
ReportAccount account(*it_account);
TableRow qaccountrow;
CashFlowList accountCashflow; // for total calculation
- if (m_config.queryColumns() == MyMoneyReport::eQCperformance) {
- constructPerformanceRow(account, qaccountrow, accountCashflow);
- } else if (m_config.queryColumns() == MyMoneyReport::eQCcapitalgain) {
- constructCapitalGainRow(account, qaccountrow);
- } else
- qaccountrow["equitytype"].clear();
+ switch(m_config.queryColumns()) {
+ case MyMoneyReport::eQCperformance:
+ {
+ constructPerformanceRow(account, qaccountrow, accountCashflow);
+ if (!qaccountrow.isEmpty()) {
+ // assuming that that report is grouped by topaccount
+ qaccountrow["topaccount"] = account.topParentName();
+ if (!topAccounts.contains(qaccountrow["topaccount"]))
+ topAccounts.insert(qaccountrow["topaccount"], accountCashflow); // \
create cashflow for unknown account... + else
+ topAccounts[qaccountrow["topaccount"]] += accountCashflow; // \
...or add cashflow for known account + }
+ break;
+ }
+ case MyMoneyReport::eQCcapitalgain:
+ constructCapitalGainRow(account, qaccountrow);
+ break;
+ default:
+ {
+ //get fraction for account
+ int fraction = account.currency().smallestAccountFraction() != -1 ?
+ account.currency().smallestAccountFraction() : \
file->baseCurrency().smallestAccountFraction(); +
+ MyMoneyMoney netprice = account.deepCurrencyPrice(m_config.toDate());
+ if (m_config.isConvertCurrency() && account.isForeignCurrency())
+ netprice *= account.baseCurrencyPrice(m_config.toDate()); // display \
currency is base currency, so set the price +
+ netprice = netprice.reduce();
+ shares = shares.reduce();
+
+ qaccountrow["price"] = \
netprice.convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())).toString();
+ qaccountrow["value"] = (netprice * shares).convert(fraction).toString();
+ qaccountrow["shares"] = shares.toString();
+
+ QString iid = account.institutionId();
+
+ // If an account does not have an institution, get it from the top-parent.
+ if (iid.isEmpty() && !account.isTopLevel())
+ iid = account.topParent().institutionId();
+
+ if (iid.isEmpty())
+ qaccountrow["institution"] = i18nc("No institution", "None");
+ else
+ qaccountrow["institution"] = file->institution(iid).name();
+
+ qaccountrow["type"] = \
KMyMoneyUtils::accountTypeToString(account.accountType()); + }
+ }
if (qaccountrow.isEmpty()) // don't add the account if there are no calculated \
values continue;
- // help for sort and render functions
qaccountrow["rank"] = '1';
- //
- // Handle currency conversion
- //
-
- MyMoneyMoney displayprice(1, 1);
- if (m_config.isConvertCurrency()) {
- // display currency is base currency, so set the price
- if (account.isForeignCurrency())
- displayprice = account.baseCurrencyPrice(m_config.toDate()).reduce();
- } else {
- // display currency is the account's deep currency. display this fact in \
the report
- qaccountrow["currency"] = account.currency().id();
- }
-
qaccountrow["account"] = account.name();
qaccountrow["accountid"] = account.id();
qaccountrow["topaccount"] = account.topParentName();
-
- qaccountrow["shares"] = shares.toString();
-
- //get fraction for account
- int fraction = account.currency().smallestAccountFraction();
-
- //use base currency fraction if not initialized
- if (fraction == -1)
- fraction = file->baseCurrency().smallestAccountFraction();
-
- MyMoneyMoney netprice = account.deepCurrencyPrice(m_config.toDate()).reduce() \
* displayprice;
- qaccountrow["price"] = \
(netprice.reduce()).convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())).toString();
- qaccountrow["value"] = (netprice.reduce() * \
shares.reduce()).convert(fraction).toString();
-
- QString iid = (*it_account).institutionId();
-
- // If an account does not have an institution, get it from the top-parent.
- if (iid.isEmpty() && ! account.isTopLevel()) {
- ReportAccount topaccount = account.topParent();
- iid = topaccount.institutionId();
- }
-
- if (iid.isEmpty())
- qaccountrow["institution"] = i18nc("No institution", "None");
- else
- qaccountrow["institution"] = file->institution(iid).name();
-
- qaccountrow["type"] = \
KMyMoneyUtils::accountTypeToString((*it_account).accountType());
-
- // assuming that that report is grouped by topaccount
- if (m_config.queryColumns() == MyMoneyReport::eQCperformance) {
- if (!topAccounts.contains(qaccountrow["topaccount"]))
- topAccounts.insert(qaccountrow["topaccount"], accountCashflow); // \
create cashflow for unknown account...
- else
- topAccounts[qaccountrow["topaccount"]] += accountCashflow; // ...or \
add cashflow for known account
- }
-
- m_rows += qaccountrow;
+ if (!m_config.isConvertCurrency())
+ qaccountrow["currency"] = account.currency().id();
+ m_rows.append(qaccountrow);
}
}
@@ -1497,13 +1488,12 @@ void QueryTable::constructAccountTable()
qtotalsrow["topaccount"] = topAccount.key();
qtotalsrow["return"] = helperIRR(topAccount.value()).toString();
grandCashflow += topAccount.value(); // cumulative sum of cashflows of each \
topaccount
- m_rows += qtotalsrow; // rows aren't sorted yet, so no problem \
with adding them randomly at the end + m_rows.append(qtotalsrow); // \
rows aren't sorted yet, so no problem with adding them randomly at the end }
qtotalsrow["topaccount"] = ""; // empty topaccount because it's grand \
cashflow qtotalsrow["return"] = helperIRR(grandCashflow).toString();
- m_rows += qtotalsrow;
+ m_rows.append(qtotalsrow);
}
-
}
void QueryTable::constructSplitsTable()
diff --git a/kmymoney/reports/tests/querytable-test.cpp \
b/kmymoney/reports/tests/querytable-test.cpp index 6612c8b6..93f55bc4 100644
--- a/kmymoney/reports/tests/querytable-test.cpp
+++ b/kmymoney/reports/tests/querytable-test.cpp
@@ -570,21 +570,15 @@ void QueryTableTest::testInvestment()
QVERIFY(MyMoneyMoney(rows[0]["sells"]) == MyMoneyMoney(44000.00));
QVERIFY(MyMoneyMoney(rows[0]["reinvestincome"]) == MyMoneyMoney(9000.00));
QVERIFY(MyMoneyMoney(rows[0]["cashincome"]) == MyMoneyMoney(3300.00));
- QVERIFY(MyMoneyMoney(rows[0]["shares"]) == MyMoneyMoney(1700.00));
- QVERIFY(MyMoneyMoney(rows[0]["price"]) == MyMoneyMoney(100.00));
QVERIFY(MyMoneyMoney(rows[1]["return"]) == MyMoneyMoney("1349/10000"));
QVERIFY(MyMoneyMoney(rows[1]["returninvestment"]) == MyMoneyMoney("1/10"));
- QVERIFY(MyMoneyMoney(rows[1]["shares"]) == MyMoneyMoney(1000.00));
- QVERIFY(MyMoneyMoney(rows[1]["price"]) == MyMoneyMoney(110.00));
QVERIFY(MyMoneyMoney(rows[1]["startingbal"]) == MyMoneyMoney(100000.00)); // \
this should stay non-zero to check if investment performance is calculated at \
non-zero starting balance
QVERIFY(MyMoneyMoney(rows[2]["return"]) == MyMoneyMoney("2501/2500"));
QVERIFY(MyMoneyMoney(rows[2]["returninvestment"]) == MyMoneyMoney("323/1250"));
QVERIFY(MyMoneyMoney(rows[2]["buys"]) == MyMoneyMoney(-95200.00));
QVERIFY(MyMoneyMoney(rows[2]["sells"]) == MyMoneyMoney(119800.00));
- QVERIFY(MyMoneyMoney(rows[2]["shares"]) == MyMoneyMoney(0.00));
- QVERIFY(MyMoneyMoney(rows[2]["price"]) == MyMoneyMoney(110.00));
QVERIFY(MyMoneyMoney(rows[2]["endingbal"]) == MyMoneyMoney(0.00)); // this \
should stay zero to check if investment performance is calculated at zero ending \
balance
QVERIFY(MyMoneyMoney(rows[4]["endingbal"]) == MyMoneyMoney(280000.00));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic