Commit 9fc583d3 authored by Alvaro Soliverez's avatar Alvaro Soliverez
Browse files

Multi-currency transaction reports: each individual should be shown in

its own currency, not the one of the main split.
Fixed the display of currency for those cases when the currency is
different from the base currency.
Added test for Transaction by Account report with multiple currencies,
contributed by Cristian Onet.

There might be some more fixing to do, as it's one of the most complex
reports.

BUG:297437
BUG:295533
REVIEW:104774
parent f51b44fe
......@@ -526,10 +526,6 @@ void QueryTable::constructTransactionTable(void)
xr = (splitAcc.deepCurrencyPrice((*it_transaction).postDate()) * splitAcc.baseCurrencyPrice((*it_transaction).postDate())).reduce();
} else {
xr = (splitAcc.deepCurrencyPrice((*it_transaction).postDate())).reduce();
//if the currency of the split is different from the currency of the main split, then convert to the currency of the main split
if (splitAcc.currency().id() != myBeginCurrency) {
xr = (xr * splitAcc.foreignCurrencyPrice(myBeginCurrency, (*it_transaction).postDate())).reduce();
}
}
if (splitAcc.isInvest()) {
......@@ -575,6 +571,8 @@ void QueryTable::constructTransactionTable(void)
qA["memo"] = a_memo;
qA["value"] = (((*it_split).shares()) * xr).convert(fraction).toString();
qS["reconciledate"] = qA["reconciledate"];
qS["reconcileflag"] = qA["reconcileflag"];
qS["number"] = qA["number"];
......@@ -666,13 +664,27 @@ void QueryTable::constructTransactionTable(void)
qA["split"] = "";
//multiply by currency and convert to lowest fraction
qA["value"] = ((-(*it_split).shares()) * xr).convert(fraction).toString();
// multiply by currency and convert to lowest fraction
// but only for income and expense
// transfers are dealt with somewhere else below
if (splitAcc.isIncomeExpense()) {
qA["value"] = ((-(*it_split).shares()) * xr).convert(fraction).toString();
}
qA["rank"] = '0';
}
qA ["memo"] = (*it_split).memo();
// if different from base currency and not converting
// show the currency of the split
if (splitAcc.currencyId() != file->baseCurrency().id()) {
if (!report.isConvertCurrency()) {
qS["currency"] = splitAcc.currencyId();
}
} else {
qS["currency"] = "";
}
if (! splitAcc.isIncomeExpense()) {
qA["category"] = ((*it_split).shares().isNegative()) ?
i18n("Transfer from %1", splitAcc.fullName())
......@@ -704,7 +716,6 @@ void QueryTable::constructTransactionTable(void)
if (m_config.includes(splitAcc) && use_transfers) {
if (! splitAcc.isIncomeExpense()) {
//multiply by currency and convert to lowest fraction
qS["value"] = ((*it_split).shares() * xr).convert(fraction).toString();
......@@ -1249,7 +1260,6 @@ void QueryTable::constructSplitsTable(void)
ReportAccount myBeginAcc = (*myBegin).accountId();
bool include_me = true;
bool transaction_text = false; //indicates whether a text should be considered as a match for the transaction or for a split only
QString a_fullname = "";
QString a_memo = "";
int pass = 1;
......@@ -1299,8 +1309,6 @@ void QueryTable::constructSplitsTable(void)
a_fullname = splitAcc.fullName();
a_memo = (*it_split).memo();
transaction_text = m_config.match(&(*it_split));
qA["price"] = xr.convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())).toString();
qA["account"] = splitAcc.name();
qA["accountid"] = splitAcc.id();
......
......@@ -645,6 +645,85 @@ void QueryTableTest::testBalanceColumn()
}
void QueryTableTest::testBalanceColumnWithMultipleCurrencies()
{
try {
MyMoneyMoney moJpyOpening(0.0, 1);
MyMoneyMoney moJpyPrice(0.010, 100);
MyMoneyMoney moJpyPrice2(0.011, 100);
MyMoneyMoney moJpyPrice3(0.024, 100);
MyMoneyMoney moTransaction(100, 1);
MyMoneyMoney moJpyTransaction(100, 1);
QString acJpyChecking = makeAccount(QString("Japanese Checking"), MyMoneyAccount::Checkings, moJpyOpening, QDate(2003, 11, 15), acAsset, "JPY");
makePrice("JPY", QDate(2004, 1, 1), MyMoneyMoney(moJpyPrice));
makePrice("JPY", QDate(2004, 5, 1), MyMoneyMoney(moJpyPrice2));
makePrice("JPY", QDate(2004, 6, 30), MyMoneyMoney(moJpyPrice3));
TransactionHelper t1(QDate(2004, 2, 20), MyMoneySplit::ActionTransfer, MyMoneyMoney(moJpyTransaction), acJpyChecking, acChecking, "JPY");
TransactionHelper t4(QDate(2004, 2, 20), MyMoneySplit::ActionDeposit, MyMoneyMoney(moTransaction), acCredit, acChecking);
TransactionHelper t2(QDate(2004, 5, 20), MyMoneySplit::ActionTransfer, MyMoneyMoney(moJpyTransaction), acJpyChecking, acChecking, "JPY");
TransactionHelper t5(QDate(2004, 5, 20), MyMoneySplit::ActionDeposit, MyMoneyMoney(moTransaction), acCredit, acChecking);
TransactionHelper t3(QDate(2004, 7, 20), MyMoneySplit::ActionTransfer, MyMoneyMoney(moJpyTransaction), acJpyChecking, acChecking, "JPY");
TransactionHelper t6(QDate(2004, 7, 20), MyMoneySplit::ActionDeposit, MyMoneyMoney(moTransaction), acCredit, acChecking);
unsigned cols;
MyMoneyReport filter;
filter.setRowType(MyMoneyReport::eAccount);
filter.setName("Transactions by Account");
cols = MyMoneyReport::eQCnumber | MyMoneyReport::eQCpayee | MyMoneyReport::eQCcategory | MyMoneyReport::eQCbalance;
filter.setQueryColumns(static_cast<MyMoneyReport::EQueryColumns>(cols));
// don't convert values to the default currency
filter.setConvertCurrency(false);
XMLandback(filter);
QueryTable qtbl_3(filter);
writeTabletoHTML(qtbl_3, "Transactions by Account (multiple currencies).html");
QString html = qtbl_3.renderBody();
QList<ListTable::TableRow> rows = qtbl_3.rows();
QVERIFY(rows.count() == 18);
//this is to make sure that the dates of closing and opening balances and the balance numbers are ok
QString openingDate = KGlobal::locale()->formatDate(QDate(2004, 2, 20), KLocale::ShortDate);
QString closingDate = KGlobal::locale()->formatDate(QDate(2004, 7, 20), KLocale::ShortDate);
// check the opening and closing balances
QVERIFY(html.indexOf(openingDate + "</td><td class=\"left\"></td><td class=\"left\">" + i18n("Opening Balance") + "</td><td class=\"left\"></td><td class=\"value\"></td><td>&nbsp;0.00</td></tr>") > 0);
QVERIFY(html.indexOf(closingDate + "</td><td class=\"left\"></td><td class=\"left\">" + i18n("Closing Balance") + "</td><td class=\"left\"></td><td class=\"value\"></td><td>&nbsp;304.00</td></tr>") > 0);
QVERIFY(html.indexOf(closingDate + "</td><td class=\"left\"></td><td class=\"left\">" + i18n("Closing Balance") + "</td><td class=\"left\"></td><td class=\"value\"></td><td>&nbsp;-300.00</td></tr>") > 0);
QVERIFY(html.indexOf(closingDate + "</td><td class=\"left\"></td><td class=\"left\">" + i18n("Closing Balance") + "</td><td class=\"left\"></td><td class=\"value\"></td><td>JPY&nbsp;-300.00</td></tr>") > 0);
// after a transfer of 100 JPY the balance should be 1.00 - price is 0.010 (precision of 2)
QVERIFY(html.indexOf("<a href=ledger?id=A000001&tid=T000000000000000001>2004-02-20</a></td><td class=\"left\"></td><td class=\"left\">Test Payee</td><td class=\"left\">Transfer from Japanese Checking</td><td class=\"value\">&nbsp;1.00</td><td>&nbsp;1.00</td></tr>") > 0);
// after a transfer of 100 the balance should be 101.00
QVERIFY(html.indexOf("<a href=ledger?id=A000001&tid=T000000000000000002>2004-02-20</a></td><td class=\"left\"></td><td class=\"left\">Test Payee</td><td class=\"left\">Transfer from Credit Card</td><td class=\"value\">&nbsp;100.00</td><td>&nbsp;101.00</td></tr>") > 0);
// after a transfer of 100 JPY the balance should be 102.00 - price is 0.011 (precision of 2)
QVERIFY(html.indexOf("<a href=ledger?id=A000001&tid=T000000000000000003>2004-05-20</a></td><td class=\"left\"></td><td class=\"left\">Test Payee</td><td class=\"left\">Transfer from Japanese Checking</td><td class=\"value\">&nbsp;1.00</td><td>&nbsp;102.00</td></tr>") > 0);
// after a transfer of 100 the balance should be 202.00
QVERIFY(html.indexOf("<a href=ledger?id=A000001&tid=T000000000000000004>2004-05-20</a></td><td class=\"left\"></td><td class=\"left\">Test Payee</td><td class=\"left\">Transfer from Credit Card</td><td class=\"value\">&nbsp;100.00</td><td>&nbsp;202.00</td></tr>") > 0);
// after a transfer of 100 JPY the balance should be 204.00 - price is 0.024 (precision of 2)
QVERIFY(html.indexOf("<a href=ledger?id=A000001&tid=T000000000000000005>2004-07-20</a></td><td class=\"left\"></td><td class=\"left\">Test Payee</td><td class=\"left\">Transfer from Japanese Checking</td><td class=\"value\">&nbsp;2.00</td><td>&nbsp;204.00</td></tr>") > 0);
// after a transfer of 100 the balance should be 304.00
QVERIFY(html.indexOf("<a href=ledger?id=A000001&tid=T000000000000000006>2004-07-20</a></td><td class=\"left\"></td><td class=\"left\">Test Payee</td><td class=\"left\">Transfer from Credit Card</td><td class=\"value\">&nbsp;100.00</td><td>&nbsp;304.00</td></tr>") > 0);
} catch (MyMoneyException *e) {
QFAIL(qPrintable(e->what()));
delete e;
}
}
void QueryTableTest::testTaxReport()
{
try {
......
......@@ -39,6 +39,7 @@ private slots:
void testAccountQuery();
void testInvestment();
void testBalanceColumn();
void testBalanceColumnWithMultipleCurrencies();
void testTaxReport();
};
......
Supports Markdown
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