Bug 284122

Summary: The "Balance" field at the bottom of the "Payees" screen adds transactions in different currencies together
Product: [Applications] kmymoney Reporter: ej
Component: generalAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 4.6.0   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: KMM XML file to demonstrate this bug

Description ej 2011-10-15 19:01:29 UTC
Version:           4.6.0 (using KDE 4.7.2) 
OS:                Linux

If a Payee has transactions in different currencies (say GBP and EUR), they are shown on the "Payees" screen each in their original currency (why not), and the "Balance" field at the bottom of the screen is the sum of all these transactions in their original currency. The latter is clearly incorrect, as it's adding apples and oranges,

This is best examplified by creating a single transaction, a transfer between two accounts in two different currencies (e.g. GBP and EUR) for a new Payee. Say I transfer GBP 100.00 from the account in GBP to the account in EUR, which becomes EUR 114.56 at the other end. The list of Transactions under "Payees" for that Payee shows two transactions: a Deposit of 114.56 (EUR) and a Payment of 100.00 (GBP). This is not incorrect per se, although it could be misleading. What is clearly incorrect is that the "Balance" at the bottom is 14.56. This is incorrect as it's subtracting a GBP amount from a EUR amount. Given that these are the two sides of a single transaction, the Balance should be 0, which KMyMoney should arrive to by applying the Exchange Rate used when the transaction was created.

Reproducible: Always

Steps to Reproduce:
- Create a new account in GBP (or use an existing one)
- Create a new account in EUR (or use an existing one)
- Create a transaction from the account in GBP:
   . Pay to: <A new Payee> (for clarity's sake)
   . Transfer to: <The account in EUR>
   . Amount: 100.00
- <Enter>
- In the Exchange Rate/Price Editor window:
   . To amount: 114.56
   . Update Price history is ticked
- <OK>
- Go to <Payees>
- Select the new Payee
- Balance at the bottom is: 14.56

NB: I have checked by selecting  Tools > Prices... that the FX has been stored for that date: GBP -> EUR Price = 1.1456

Actual Results:  
Balance: 14.56

Expected Results:  
Balance: 0

My suggestion is that each individual transaction on the list under "Payees" should be converted into the Base Currency. This should be done using the stored Exchange Rates/Prices. If no stored Exchange Rate/Price is found for this date, then the most recent one going backwards into the past from the transaction date should be used. If none is found, then a default Exchange Rate of 1 should be used. This situation would result in the same result as above (Balance: 14.56), but this would be justified by the absence of any stored FX value for that pair of currencies.
The Balance field can then safely be calculated by adding/subtracting the amounts for all these transactions.

OS: Linux (i686) release 3.0.0-12-generic
Compiler: gcc
Comment 1 ej 2011-10-15 19:22:15 UTC
Created attachment 64556 [details]
KMM XML file to demonstrate this bug

NB: I have also manually created the reverse FX (EUR->GBP = 0.8729) just in case, but this does not fix it.
Comment 2 Thomas Baumgart 2011-10-16 07:06:05 UTC
Good catch. Using an exchange rate as you describe is actually the way KMyMoney works with them. And entering the reverse exchange rate does not help, because KMyMoney works with only one as it knows about the reciprocal in the other case.
Comment 3 Thomas Baumgart 2011-10-16 07:44:31 UTC
SVN commit 1259124 by tbaumgart:

Use price information to calculate the balance over all transactions shown for a payee in the payees view.

Needs backport to stable

BUG: 284122

 M  +31 -12    kpayeesview.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1259124
Comment 4 Cristian OneČ› 2011-10-22 08:15:51 UTC
SVN commit 1260150 by conet:

Use price information to calculate the balance over all transactions shown for a payee in the payees view.

Backported to stable branch.

BUG: 284122



 M  +31 -12    kpayeesview.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1260150