Make register use engine-provided xaccTransGetAccountConvRate() instead of

writing its own.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13426 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldfeatures/register-rewrite
Chris Shoemaker 21 years ago
parent c0962037f6
commit f32bc537d1

@ -1154,7 +1154,7 @@ gnc_split_register_handle_exchange (SplitRegister *reg, gboolean force_dialog)
/* UGGH -- we're not in either. That means we need to convert 'amount'
* from the register commodity to the txn currency.
*/
gnc_numeric rate = gnc_split_register_get_conv_rate (txn, reg_acc);
gnc_numeric rate = xaccTransGetAccountConvRate(txn, reg_acc);
/* XXX: should we tell the user we've done the conversion? */
amount = gnc_numeric_div (amount, rate, gnc_commodity_get_fraction (txn_cur),

@ -419,7 +419,7 @@ gnc_split_register_save_amount_values (SRSaveData *sd, SplitRegister *reg)
* Otherwise, we _can_ use the rate_cell!
*/
if (sd->reg_expanded && ! gnc_commodity_equal (reg_com, xfer_com))
amtconv = gnc_split_register_get_conv_rate (sd->trans, acc);
amtconv = xaccTransGetAccountConvRate(sd->trans, acc);
else
amtconv = convrate;
@ -534,8 +534,8 @@ gnc_split_register_save_cells (gpointer save_data,
* _both_ accounts -- so grab the other exchange rate.
*/
if (gnc_numeric_zero_p (rate) || split_needs_amount)
rate = gnc_split_register_get_conv_rate (xaccSplitGetParent (other_split),
acc);
rate = xaccTransGetAccountConvRate(xaccSplitGetParent (other_split),
acc);
amount = gnc_numeric_mul (value, rate, xaccAccountGetCommoditySCU (acc),
GNC_RND_ROUND);

@ -1413,56 +1413,6 @@ gnc_split_register_needs_conv_rate (SplitRegister *reg,
return TRUE;
}
/* Compute the conversion rate for the transaction to this account.
* Any "split value" (which is in the transaction currency),
* multiplied by this conversion rate, will give you the value you
* should display for this account.
*/
gnc_numeric
gnc_split_register_get_conv_rate (Transaction *txn, Account *acc)
{
gnc_numeric amount, value, convrate;
GList *splits;
Split *s;
gboolean found_acc_match = FALSE;
/* We need to compute the conversion rate into _this account_. So,
* find the first split into this account, compute the conversion
* rate (based on amount/value), and then return this conversion
* rate.
*/
splits = xaccTransGetSplitList(txn);
for (; splits; splits = splits->next) {
s = splits->data;
if (xaccSplitGetAccount (s) != acc)
continue;
found_acc_match = TRUE;
amount = xaccSplitGetAmount (s);
/* Ignore splits with "zero" amount */
if (gnc_numeric_zero_p (amount))
continue;
value = xaccSplitGetValue (s);
convrate = gnc_numeric_div (amount, value, GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
return convrate;
}
/* Don't error if we're in a GENERAL_LEDGER and have no account */
if (acc) {
/* If we did find a matching account but it's amount was zero,
* then perhaps this is a "special" income/loss transaction
*/
if (found_acc_match)
return gnc_numeric_zero();
else
PERR ("Cannot convert transaction -- no splits with proper conversion ratio");
}
return gnc_numeric_create (100, 100);
}
/* Convert the amount/value of the Split for viewing in the account --
* in particular we want to convert the Split to be in to_commodity.
* Returns the amount.
@ -1508,7 +1458,7 @@ gnc_split_register_convert_amount (Split *split, Account * account,
* compute the conversion rate (based on amount/value), and then multiply
* this times the split value.
*/
convrate = gnc_split_register_get_conv_rate (txn, account);
convrate = xaccTransGetAccountConvRate(txn, account);
value = xaccSplitGetValue (split);
return gnc_numeric_mul (value, convrate,
gnc_commodity_get_fraction (to_commodity),
@ -1563,7 +1513,7 @@ gnc_split_register_get_debcred_entry (VirtualLocation virt_loc,
acc = gnc_split_register_get_default_account (reg);
if (gnc_split_register_needs_conv_rate (reg, trans, acc)) {
imbalance = gnc_numeric_mul (imbalance,
gnc_split_register_get_conv_rate (trans, acc),
xaccTransGetAccountConvRate(trans, acc),
gnc_commodity_get_fraction (currency),
GNC_RND_ROUND);
} else {

@ -166,6 +166,5 @@ gnc_numeric gnc_split_register_debcred_cell_value (SplitRegister *reg);
gboolean gnc_split_reg_has_rate_cell (SplitRegisterType type);
gboolean gnc_split_register_split_needs_amount (SplitRegister *reg, Split *split);
gboolean gnc_split_register_needs_conv_rate (SplitRegister *reg, Transaction *txn, Account *acc);
gnc_numeric gnc_split_register_get_conv_rate (Transaction *txn, Account *acc);
#endif

Loading…
Cancel
Save