Bug 246815 - Cannot create Loan account when I lend money
Summary: Cannot create Loan account when I lend money
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-05 16:14 UTC by Petr Bravenec
Modified: 2010-08-06 12:13 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Bravenec 2010-08-05 16:14:25 UTC
Version:           unspecified (using KDE 4.4.5) 
OS:                Linux

When creating Loan account when I lend money the Account creation wizard ands with a dialog:

Unable to create account: Account has invalid type

Version: 3.98.1
and 3.98.2-svn1159082

Reproducible: Didn't try

Steps to Reproduce:
Create account
Choose account type "Loan"
Choose 
What is the type of the loan? "I am lending money"
Continue
Comment 1 Petr Bravenec 2010-08-05 16:19:33 UTC
Reproducible: Didn't try --- sory 
Reproducible: Always
Comment 2 Cristian Oneț 2010-08-05 22:07:32 UTC
I can confirm this.
Comment 3 Cristian Oneț 2010-08-05 23:02:08 UTC
Hint for the developers: the problem is that if money is lent the account type is set to m_account.setAccountType(MyMoneyAccount::AssetLoan); which is not present in the account type combo which is the final source of the account type thus resulting in an Unknown account type. Suggestion: use m_account as the final source of account instead of the account type combo.
Comment 4 Alvaro Soliverez 2010-08-06 05:52:37 UTC
SVN commit 1159736 by asoliverez:

Fixed how the account type is assigned to the account type combo when it is a loan

BUG:246815

 M  +6 -1      knewaccountwizard.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1159736
Comment 5 Cristian Oneț 2010-08-06 07:32:49 UTC
I'm afraid that this fix is not correct since when the user will lend money an account with type 'Loan' instead of one with type 'AssetLoan' will be created which is a BUG.
Comment 6 Alvaro Soliverez 2010-08-06 11:36:01 UTC
What do you mean? I tried it and it creates an Investment Loan account, which is the AssetLoan type.
Comment 7 Cristian Oneț 2010-08-06 11:45:14 UTC
That is what's displayed in the summary page or is it the type of the account that was saved in the kmymoney file?
Comment 8 Cristian Oneț 2010-08-06 11:48:00 UTC
(In reply to comment #7)
> That is what's displayed in the summary page or is it the type of the account
> that was saved in the kmymoney file?

I'm saying this because after displaying the summary account the account() method of the wizard will be called again and it will set the type of the saved account to 'Loan' because that's in the combobox.
Comment 9 Alvaro Soliverez 2010-08-06 11:50:47 UTC
Actually, that display on the summary page is done on purpose. It beats me why
they did it, but that's existing code.

-----------------------
if (acc.accountType() == MyMoneyAccount::AssetLoan)
    m_dataList->append(QString(i18n("Type") + ": %1").arg(i18n("Loan")));
  else
    m_dataList->append(QString(i18n("Type") + ":
%1").arg(m_wizard->m_accountTypePage->m_typeSelection->currentText()));
-----------------------

Finish the wizard and you'll see it creates an asset loan.
Comment 10 Cristian Oneț 2010-08-06 12:03:06 UTC
(In reply to comment #9)
> Actually, that display on the summary page is done on purpose. It beats me why
> they did it, but that's existing code.
> 
> -----------------------
> if (acc.accountType() == MyMoneyAccount::AssetLoan)
>     m_dataList->append(QString(i18n("Type") + ": %1").arg(i18n("Loan")));
>   else
>     m_dataList->append(QString(i18n("Type") + ":
> %1").arg(m_wizard->m_accountTypePage->m_typeSelection->currentText()));
> -----------------------
> 
> Finish the wizard and you'll see it creates an asset loan.

I'll test this when I get home but frankly I don't see how finishing the wizard will create an account of type 'MyMoneyAccount::AssetLoan'.

Isn't the last call to Wizard::account() done in KMyMoneyApp::slotAccountNew() wizard->account()? 
Which in turn will set the account type to m_account.setAccountType(m_accountTypePage->accountType()); which in turn is set by your commit to 'MyMoneyAccount::Loan', is this right?
Comment 11 Cristian Oneț 2010-08-06 12:13:59 UTC
I was missing the following code in the account() method:
------------------------------
if (m_account.isLoan()) {
   // in case we lend the money we adjust the account type
   if (!moneyBorrowed())
     m_account.setAccountType(MyMoneyAccount::AssetLoan);
------------------------------

So I guess we can close this as fixed. Thanks for the discussion :).