r14562 - gnucash/branches/2.0 - Properly round invoice entries and totals. Fixes #300042.
Derek Atkins
warlord at cvs.gnucash.org
Tue Jul 25 22:36:23 EDT 2006
Author: warlord
Date: 2006-07-25 22:36:22 -0400 (Tue, 25 Jul 2006)
New Revision: 14562
Trac: http://svn.gnucash.org/trac/changeset/14562
Modified:
gnucash/branches/2.0/
gnucash/branches/2.0/ChangeLog
gnucash/branches/2.0/src/business/business-core/gncEntry.c
gnucash/branches/2.0/src/business/business-core/gncEntry.h
gnucash/branches/2.0/src/business/business-ledger/gncEntryLedger.c
Log:
Properly round invoice entries and totals. Fixes #300042.
Perform internal computations to LCD, but then export rounded values.
Now, using the test case in Bug #300042 I get the same values
in the invoice window, in the printable invoice report, and
in the CoA Registers.
Compute the commodity scu from the ledger invoice (#300042).
This way the SCU is no longer hard-coded into the business ledger.
Audited by chris.
Merged r14531 and r14545.
Property changes on: gnucash/branches/2.0
___________________________________________________________________
Name: svk:merge
- d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/2.0:12934
+ d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/2.0:12935
Modified: gnucash/branches/2.0/ChangeLog
===================================================================
--- gnucash/branches/2.0/ChangeLog 2006-07-26 02:36:11 UTC (rev 14561)
+++ gnucash/branches/2.0/ChangeLog 2006-07-26 02:36:22 UTC (rev 14562)
@@ -43,6 +43,14 @@
or as "seventeen thousand five hundred". Note that numbers STILL
default to decimal-radix instead of asking the user to choose.
+ * src/business/business-core/gncEntry.[ch]:
+ * src/business/business-ledger/gncEntryLedger.c:
+ Properly round invoice entries and totals. Fixes #300042.
+ Perform internal computations to LCD, but then export rounded values.
+ Now, using the test case in Bug #300042 I get the same values
+ in the invoice window, in the printable invoice report, and
+ in the CoA Registers.
+
* src/business/business-gnome/dialog-invoice.c:
Set the summary bar values when the window is first opened (#345978).
Modified: gnucash/branches/2.0/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/branches/2.0/src/business/business-core/gncEntry.c 2006-07-26 02:36:11 UTC (rev 14561)
+++ gnucash/branches/2.0/src/business/business-core/gncEntry.c 2006-07-26 02:36:22 UTC (rev 14562)
@@ -839,13 +839,15 @@
* the amount the merchant gets; the taxes are the amount the gov't
* gets, and the customer pays the sum or value + taxes.
*
+ * The SCU is the denominator to convert the value.
+ *
* The discount return value is just for entertainment -- you may way
* to let a consumer know how much they saved.
*/
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
GncTaxTable *tax_table, gboolean tax_included,
gnc_numeric discount, GncAmountType discount_type,
- GncDiscountHow discount_how,
+ GncDiscountHow discount_how, int SCU,
gnc_numeric *value, gnc_numeric *discount_value,
GList **tax_value)
{
@@ -975,11 +977,15 @@
* need to compute taxes (based on 'pretax') if the caller wants it.
*/
- if (discount_value != NULL)
+ if (discount_value != NULL) {
+ if (SCU) discount = gnc_numeric_convert(discount, SCU, GNC_RND_ROUND);
*discount_value = discount;
+ }
- if (value != NULL)
+ if (value != NULL) {
+ if (SCU) result = gnc_numeric_convert(result, SCU, GNC_RND_ROUND);
*value = result;
+ }
/* Now... Compute the list of tax values (if the caller wants it) */
@@ -995,12 +1001,14 @@
switch (gncTaxTableEntryGetType (entry)) {
case GNC_AMT_TYPE_VALUE:
+ if (SCU) amount = gnc_numeric_convert(amount, SCU, GNC_RND_ROUND);
taxes = gncAccountValueAdd (taxes, acc, amount);
break;
case GNC_AMT_TYPE_PERCENT:
amount = gnc_numeric_div (amount, percent, GNC_DENOM_AUTO,
GNC_DENOM_LCD);
tax = gnc_numeric_mul (pretax, amount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+ if (SCU) tax = gnc_numeric_convert(tax, SCU, GNC_RND_ROUND);
taxes = gncAccountValueAdd (taxes, acc, tax);
break;
default:
@@ -1066,12 +1074,16 @@
entry->b_tax_values = NULL;
}
+ /* Determine the commodity denominator */
+ denom = get_entry_commodity_denom (entry);
+
/* Compute the invoice values */
gncEntryComputeValue (entry->quantity, entry->i_price,
(entry->i_taxable ? entry->i_tax_table : NULL),
entry->i_taxincluded,
entry->i_discount, entry->i_disc_type,
entry->i_disc_how,
+ denom,
&(entry->i_value), &(entry->i_disc_value),
&(entry->i_tax_values));
@@ -1080,9 +1092,9 @@
(entry->b_taxable ? entry->b_tax_table : NULL),
entry->b_taxincluded,
gnc_numeric_zero(), GNC_AMT_TYPE_VALUE, GNC_DISC_PRETAX,
+ denom,
&(entry->b_value), NULL, &(entry->b_tax_values));
- denom = get_entry_commodity_denom (entry);
entry->i_value_rounded = gnc_numeric_convert (entry->i_value, denom,
GNC_RND_ROUND);
entry->i_disc_value_rounded = gnc_numeric_convert (entry->i_disc_value, denom,
Modified: gnucash/branches/2.0/src/business/business-core/gncEntry.h
===================================================================
--- gnucash/branches/2.0/src/business/business-core/gncEntry.h 2006-07-26 02:36:11 UTC (rev 14561)
+++ gnucash/branches/2.0/src/business/business-core/gncEntry.h 2006-07-26 02:36:22 UTC (rev 14562)
@@ -174,7 +174,9 @@
/** Compute the Entry value, tax-value, and discount_value, based on
* the quantity, price, discount, tax-table, and types. The value is
* the amount the merchant gets, the taxes are what the gov't gets,
- * and the discount is how much the customer saved.
+ * and the discount is how much the customer saved. The SCU is the
+ * target denominator of the value and tax -- it should be the
+ * account or commodity SCU of the target.
*
* The tax_values list is the property of the entry and will be
* destroyed automatically, so use it quickly. Note that all return
@@ -187,7 +189,7 @@
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
GncTaxTable *tax_table, gboolean tax_included,
gnc_numeric discount, GncAmountType discount_type,
- GncDiscountHow discount_how,
+ GncDiscountHow discount_how, int SCU,
/* return values */
gnc_numeric *value, gnc_numeric *discount_value,
GList **tax_values);
Modified: gnucash/branches/2.0/src/business/business-ledger/gncEntryLedger.c
===================================================================
--- gnucash/branches/2.0/src/business/business-ledger/gncEntryLedger.c 2006-07-26 02:36:11 UTC (rev 14561)
+++ gnucash/branches/2.0/src/business/business-ledger/gncEntryLedger.c 2006-07-26 02:36:22 UTC (rev 14562)
@@ -627,6 +627,7 @@
gboolean taxable, taxincluded;
GncTaxTable *table;
GList *taxes = NULL;
+ int denom = 100;
gnc_entry_ledger_get_numeric (ledger, ENTRY_QTY_CELL, &qty);
gnc_entry_ledger_get_numeric (ledger, ENTRY_PRIC_CELL, &price);
@@ -670,18 +671,20 @@
table = NULL;
}
+ if (ledger->invoice)
+ {
+ gnc_commodity *currency = gncInvoiceGetCurrency(ledger->invoice);
+ if (currency)
+ denom = gnc_commodity_get_fraction(currency);
+ }
+
gncEntryComputeValue (qty, price, (taxable ? table : NULL), taxincluded,
- discount, disc_type, disc_how,
+ discount, disc_type, disc_how, denom,
value, NULL, &taxes);
- /* Now convert the values to the proper denomination */
- if (value)
- *value = gnc_numeric_convert (*value, 100 /* XXX */, GNC_RND_ROUND);
-
- if (tax_value) {
+ /* return the tax value */
+ if (tax_value)
*tax_value = gncAccountValueTotal (taxes);
- *tax_value = gnc_numeric_convert (*tax_value, 100 /* XXX */, GNC_RND_ROUND);
- }
}
gboolean
More information about the gnucash-changes
mailing list