Stock "price" transactions

Bill Carlson wwc@wwcnet.nu
Tue, 5 Dec 2000 00:51:16 -0500


Hi All,

	In my working on the latest CVS source, I noticed some
problems with a number of stock "price only" transactions that
I have (as per the manual) getting imported from the binary file
badly (turns up as zero price!).  The following set of patches fixes
these problems.  The basic concept is that now that we are
using REAL rational numbers, we can actually use a zero deamount
as an accurate flag for the "price only" split.  This makes perfect
sense as we are not changing the damount, only the overall 
value.  The only changes that needed to be made are in the accessor
functions to return the "right" value for these sorts of splits.
I've tested this change on my pretty big (~10000 trans) file and
it does well.  Please accept these changes into the CVS source
(or feel free to propose an alternative if this is not the way
to handle it!).  By the way, I also have an idea as to how todeal with 
splits and the like using a "zero value" but changing damount.  Works 
well.  If people are interested, I could do that up, test it, and
send it in.

		Cheers,

		Bill Carlson
		wwc@wwcnet.nu


Index: src/engine/Account.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Account.c,v
retrieving revision 1.98
diff -r1.98 Account.c
535c535,536
<     return gnc_numeric_zero();
---
>     return gnc_numeric_mul(share_count, s->value,
> 			   gnc_numeric_denom(s->value), GNC_RND_ROUND);
Index: src/engine/Scrub.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Scrub.c,v
retrieving revision 1.18
diff -r1.18 Scrub.c
163a164,167
>   /*
>    * don't adjust splits in STOCK or MUTUAL accounts, because some
>    * users have not set securities for all such accounts
>    */
165c169,170
<   if (!account)
---
>   if (!account || xaccAccountGetType(account) == STOCK
>       || xaccAccountGetType(account) == MUTUAL)
Index: src/engine/Transaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Transaction.c,v
retrieving revision 1.137
diff -r1.137 Transaction.c
383,384c383,393
<   s->value   = gnc_numeric_mul(s->damount, price, 
<                                get_currency_denom(s), GNC_RND_ROUND);
---
> 
>   /*
>    * if amount is REALLY zero, set value to price because this
>    * is a price-setting split that has no effect on share balance
>    */
>   if (gnc_numeric_zero_p (amt))
>     s->value = gnc_numeric_convert(price, get_currency_denom(s),
> 				   GNC_RND_ROUND);
>   else
>     s->value = gnc_numeric_mul(s->damount, price, 
> 				 get_currency_denom(s), GNC_RND_ROUND);
402,403c411,420
<   s->value = gnc_numeric_mul(s->damount, price, get_currency_denom(s),
<                              GNC_RND_ROUND);
---
>   /*
>    * if amount is REALLY zero, set value to price because this
>    * is a price-setting split that has no effect on share balance
>    */
>   if (gnc_numeric_zero_p (s->damount))
>     s->value = gnc_numeric_convert(price, get_currency_denom(s),
> 				   GNC_RND_ROUND);
>   else
>     s->value = gnc_numeric_mul(s->damount, price, get_currency_denom(s),
> 			       GNC_RND_ROUND);
2173a2191,2195
> DxaccSplitGetRawValue (Split * split) {
>   return gnc_numeric_to_double(xaccSplitGetRawValue(split));
> }
> 
> double
2188a2211,2228
>   /*
>    * zero damount means this is a special price-only split,
>    * meaning the value of the split is really zero
>    */
>   if (gnc_numeric_zero_p(split->damount))
>     return gnc_numeric_zero();
> 
>   return split->value; 
> }
> 
> /*
>  * A function which returns the raw value, mainly
>  * for saving 
>  */
> gnc_numeric
> xaccSplitGetRawValue (Split * split) {
>   if (!split) return gnc_numeric_zero();
> 
2194c2234
<   if(!split || gnc_numeric_zero_p(split->damount)) {
---
>   if(!split) {
2196,2199c2236,2240
<   }
<   return gnc_numeric_div(split->value, 
<                          split->damount,
<                          PRICE_DENOM, GNC_RND_ROUND);
---
>   } else if (gnc_numeric_zero_p(split->damount)) {
>     return split->value;
>   } 
>   return gnc_numeric_div(split->value, split->damount,
>                          get_security_denom(split), GNC_RND_ROUND);
Index: src/engine/Transaction.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Transaction.h,v
retrieving revision 1.81
diff -r1.81 Transaction.h
426a427
> double        DxaccSplitGetRawValue (Split * split);
430a432
> gnc_numeric   xaccSplitGetRawValue (Split * split);
Index: src/engine/io-gncbin-r.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/io-gncbin-r.c,v
retrieving revision 1.5
diff -r1.5 io-gncbin-r.c
1124a1125
>       split->acc = acc;
Index: src/engine/io-gncxml-w.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/io-gncxml-w.c,v
retrieving revision 1.8
diff -r1.8 io-gncxml-w.c
567c567
<   if(!xml_add_gnc_numeric(split_xml, "value", xaccSplitGetValue(s)))
---
>   if(!xml_add_gnc_numeric(split_xml, "value", xaccSplitGetRawValue(s)))