Crash in multi-currency transactions (was: [gnucash-de] Bug im
HBCI-Teil)
BenoitGrégoire
bock at step.polymtl.ca
Wed Aug 13 22:57:10 CDT 2003
On Wednesday 13 August 2003 18:17, Derek Atkins wrote:
> Christian Stimming <stimming at tuhh.de> writes:
> > This is a bug discovered by Tobias Krais in the multi-currency
> > transaction handling, version 1.8.4. I'll translate the description:
> >
> > Some transactions have been imported (by HBCI, but this doesn't matter
> > here). The transactions are imported into a EUR account, and the
> > problematic transactions have a CHF (swiss franks) account as 'other'
> > account.
> >
> > After finishing the importer GUI, the EUR amount in the EUR account is
> > correctly displayed. However, in the CHF account no amount is displayed
> > at all -- the field is empty. Now Tobias goes into the (empty) amount
> > field and enters an amount. Then he leaves the transaction. The dialog
> > opens: "The current transaction is not balanced". He selected "Adjust
> > current account split" (third out of four radio buttons, picture
> > attached). Gnucash crashes.
> >
> > From the importing code I can tell: the Transaction in question has EUR
> > currency; the amount of the split in the EUR account is set by calling
> > xaccSplitSetBaseValue(split, eur_amount, EUR_currency) in
> > import-export/hbci/gnc-hbci-gettrans.c:313; the amount of the split in
> > the CHF account is set by calling xaccSplitSetBaseValue(split,
> > eur_amount_negative, EUR_currency) in import-export/import-backend.c:825
> > .
>
> Ahh, this is just setting the split->value, not the split->amount. So
> split->amount is left as zero (which is obviously wrong). From
> xaccSplitSetBaseValue():
>
> /* If the base_currency is the transaction's commodity ('currency'),
> * set the value. If it's the account commodity, set the
> * amount. If both, set both. */
>
> So what's going on is that you're setting the value but not the
> amount, which is causing problems later. You probably want to use
> xaccSplitSetValue() and xaccSplitSetAmount() directly, instead of
> using the SetBaseValue() API.
>
> > When any of the other radio buttons are selected, gnucash doesn't crash.
> > In any case, a bunch (50 times) of warnings are printed on the console:
> > Warning: PrintAmountInternal: Bad numeric.
> >
> > Anybody (Derek :) an idea?
>
> The bug is that you aren't setting the transaction split amount/values
> properly. This is a bug in the importer, IMHO.
Derek is right. Tough we should probably get rid of xaccSplitSetBaseValue()
in head, I just checked it's code as well as the calls in both the OFX and
HBCI code and we are using it correctly.
The problem is in import-backend. When I wrote it it never occurred to me
that someone could select an account with a different currency as the
destination account for a new transaction. I don't know how to fix it
properly without some lookup to the pricedb or popping a dialog asking the
user to supply a new amount.
We are way too close to release for me to do something like that. In the
meantime, I propose replacing the call to xaccSetBaseValue() in
import-export/import-backend.c:825 by to calls (xaccSplitSetValue() and
xaccSplitSetAmount()) BOTH with the same amount, and spit a FIXME in the
console. The value will be good, the amount WILL be wrong, but at least
gnucash won't crash or do anything weird.
Good night,
--
Benoit Grégoire
http://step.polymtl.ca/~bock/
More information about the gnucash-devel
mailing list