strange behaviour in stock buy transaction

Hale Boyes, Kevin Kevin.HaleBoyes at encana.com
Fri May 4 17:29:17 EDT 2007


Moving this over from -user.

Des,
Setting LC_MONETARY to en_CA works for me as well.  Thanks.


I've taken the patch from comment #7 and updated it to compile
in trunk.  It works for me when I go through the steps I originally
posted.

I've requested a bugzilla account so I can add the updated
patch to the bug report if that is useful.

The patch looks only at the parent of the account.  Can the parent
have a non-currency-type commodity in some cases?  If that can happen
should we visit ancestors until we find one?

K.

Here is the patch so far.  Is this the format I should use for the
attachment?

Index: src/register/ledger-core/split-register-load.c
===================================================================
--- src/register/ledger-core/split-register-load.c	(revision 16043)
+++ src/register/ledger-core/split-register-load.c	(working copy)
@@ -216,12 +216,26 @@
 
     /* Determine the proper currency to use for this transaction.
      * if default_account != NULL and default_account->commodity is
-     * a currency, then use that.  Otherwise use the default currency.
+     * a currency, then use that.  Otherwise, use the commodity
+     * of the parent account if it is a currency.
+     * Otherwise use the default currency.
      */
     if (default_account != NULL) {
       gnc_commodity * commodity = xaccAccountGetCommodity
(default_account);
       if (gnc_commodity_is_currency(commodity))
           currency = commodity;
+      else
+      {
+        /* Account commodity is not a currency, see if the parent
account
+           is a currency account and use it's currency if so. */
+        Account *parent_account = gnc_account_get_parent (
default_account );
+        if (parent_account)
+        {
+          commodity = xaccAccountGetCommodity (parent_account);
+          if (gnc_commodity_is_currency(commodity))
+            currency = commodity;
+        }
+      }
     }
 
     gnc_suspend_gui_refresh ();



-----Original Message-----
From: Derek Atkins [mailto:warlord at MIT.EDU] 
Sent: Friday, May 04, 2007 7:23 AM
To: Hale Boyes, Kevin 
Cc: gnucash-user at gnucash.org
Subject: Re: strange behaviour in stock buy transaction

"Hale Boyes, Kevin " <Kevin.HaleBoyes at encana.com> writes:

> Is there any way to tell what locale I'm in?

echo $LANG

> Would I be able to set me locale to en_CA and have it
> work properly? 

Yes.

> I've read the bug report but there doesn't seem to be any
> consensus on how this might be fixed.  The patch presented in
> comment #7 seems like it would work in my case but it is
> different than comment #4 which also seems like a workable
> solution.

I'm leaning towards the patch in #7.  It's not the BEST
solution, but it's better than others.  But it doesn't
solve the general problem of how you choose a currency
for any random register (e.g. General Ledger register or
a Search Results register).

> Is there anything I can do to help us reach an agreement
> on how to proceed?  Once that has happened I'm willing
> to work on a patch.

Umm..  Move over to -devel and propose a solution?

> Kevin.

-derek

>
> -----Original Message-----
> From: Derek Atkins [mailto:warlord at MIT.EDU] 
> Sent: Thursday, May 03, 2007 12:40 PM
> To: Hale Boyes, Kevin 
> Cc: gnucash-user at gnucash.org
> Subject: Re: strange behaviour in stock buy transaction
>
> Hi,
>
> I bet you're in the C locale (or maybe en_US), so your locale currency
> is USD, not CAD.   So you're probably hitting this bug:
>
> http://bugzilla.gnome.org/show_bug.cgi?id=116353
>
> -derek
>
> Quoting "Hale Boyes, Kevin " <Kevin.HaleBoyes at encana.com>:
>
>> I've been learning more about tracking stock purchases and sales
>> in GnuCash and have found something I don't understand.
>>
>> First some setup:
>>    - start GC with --nofile and then create a new file.
>>    - choose CAD for currency.
>>    - choose Common + Investment accounts with no opening balances.
>>    - create new accounts under "Brokerage Account"
>>        - type Cash named Cash.
>>        - type Stock named SUNW (for which I created a new commodity
>>            with fraction 1/100 on the NASDAQ.
>>    - move $1000 into "Checking Account" from Equity:Opening Balances.
>>
>> When I buy stock I tend to transfer money from my chequing account
> into
>> my brokerage account.  Then I buy the stock.  The end price may not
> use
>> up the full amount of cash that I transfered but that is fine as I
run
>> a positive cash balance in my brokerage account.
>>
>> So, I transfered $400 from chequing to the new cash account under
>> "Brokerage Account" -- Assets:Investments:Brokerage Account:Cash.
>> Now the balance shown in that ledger is $400.
>>
>> Then I buy some shares of SUNW.  So, in the SUNW ledger I enter a
>> buy with the offset account being Assets:Investments:Brokerage
>> Account:Cash
>> and everything looks fine until I look back into the cash account.
>> The buy transaction is displayed but the amount fields are blank and
>> the balance has not been adjusted and still displays $400.
>>
>> I expect the balance to have been adjusted for the money I just used
>> to buy the stock but maybe there is something that I'm missing.
>>
>> I've included a couple of screen shots.
>> This is happening with 2.0.5 and trunk on FC6.
>>
>> Thanks,
>> Kevin.
>>
>>
>> P.S.  Sorry for the following disclaimer but I have no control over
> it.
>>
>> This email communication and any files transmitted with it may 
>> contain confidential and or proprietary information and is provided 
>> for the use of the intended recipient only. Any review, 
>> retransmission or dissemination of this information by anyone other 
>> than the intended recipient is prohibited.  If you receive this email

>> in error, please contact the sender and delete this communication and

>> any copies immediately. Thank you.
>> http://www.encana.com
>>
>>
>>
>
>
>
> -- 
>        Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
>        Member, MIT Student Information Processing Board  (SIPB)
>        URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
>        warlord at MIT.EDU                        PGP key available
>
>
>

-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available



More information about the gnucash-devel mailing list