Factor out and create new function: xaccAccountIsPriced() that does the

common STOCK, MUTUAL or CURRENCY check.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13513 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker 2006-03-07 05:31:54 +00:00
parent 5badb824e6
commit c2ae90cc94
9 changed files with 39 additions and 108 deletions

View File

@ -206,12 +206,9 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices,
{
GNCPotentialQuote *q = (GNCPotentialQuote *) item->data;
Account *split_acct = xaccSplitGetAccount(q->split);
GNCAccountType acct_type = xaccAccountGetType(split_acct);
/* at this point, we already know it's a split with a zero amount */
if((acct_type == STOCK) ||
(acct_type == MUTUAL) ||
(acct_type == CURRENCY)) {
if (xaccAccountIsPriced(split_acct)) {
/* this is a quote -- file it in the db and kill the split */
Transaction *txn = xaccSplitGetParent(q->split);
GNCPrice *price = gnc_price_create(book);
@ -739,18 +736,11 @@ readAccount( QofBook *book, int fd, AccountGroup *grp, int token )
if (!tmp || *tmp == '\0')
{
GNCAccountType account_type;
if (xaccAccountIsPriced(acc)) {
if (tmp) g_free (tmp);
account_type = xaccAccountGetType (acc);
if (account_type == STOCK ||
account_type == MUTUAL ||
account_type == CURRENCY)
{
if (tmp) g_free (tmp);
tmp = strdup (xaccAccountGetName (acc));
if (tmp == NULL) return NULL;
tmp = strdup (xaccAccountGetName (acc));
if (tmp == NULL) return NULL;
}
}

View File

@ -2162,7 +2162,14 @@ xaccAccountTypesValid(void)
return mask;
}
gboolean
xaccAccountIsPriced(const Account *acc)
{
if (!acc) return FALSE;
return (acc->type == STOCK || acc->type == MUTUAL ||
acc->type == CURRENCY);
}
/********************************************************************\
\********************************************************************/
@ -2404,16 +2411,13 @@ dxaccAccountSetPriceSrc(Account *acc, const char *src)
if (!acc) return;
xaccAccountBeginEdit(acc);
{
GNCAccountType t = acc->type;
if ((t == STOCK) || (t == MUTUAL) || (t == CURRENCY)) {
if (xaccAccountIsPriced(acc)) {
kvp_frame_set_slot_nc(acc->inst.kvp_data,
"old-price-source",
src ? kvp_value_new_string(src) : NULL);
mark_account (acc);
}
}
acc->inst.dirty = TRUE;
xaccAccountCommitEdit(acc);
}
@ -2424,14 +2428,12 @@ dxaccAccountSetPriceSrc(Account *acc, const char *src)
const char*
dxaccAccountGetPriceSrc(const Account *acc)
{
GNCAccountType t;
if(!acc) return NULL;
t = acc->type;
if((t == STOCK) || (t == MUTUAL) || (t == CURRENCY))
{
KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data, "old-price-source");
if(value) return (kvp_value_get_string(value));
if (xaccAccountIsPriced(acc)) {
KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data,
"old-price-source");
if (value) return (kvp_value_get_string(value));
}
return NULL;
}
@ -2442,18 +2444,14 @@ dxaccAccountGetPriceSrc(const Account *acc)
void
dxaccAccountSetQuoteTZ(Account *acc, const char *tz)
{
if(!acc) return;
if (!acc) return;
xaccAccountBeginEdit(acc);
{
GNCAccountType t = acc->type;
if((t == STOCK) || (t == MUTUAL) || (t == CURRENCY)) {
if (xaccAccountIsPriced(acc)) {
kvp_frame_set_slot_nc(acc->inst.kvp_data,
"old-quote-tz",
tz ? kvp_value_new_string(tz) : NULL);
mark_account (acc);
}
}
acc->inst.dirty = TRUE;
xaccAccountCommitEdit(acc);
@ -2465,14 +2463,11 @@ dxaccAccountSetQuoteTZ(Account *acc, const char *tz)
const char*
dxaccAccountGetQuoteTZ(const Account *acc)
{
GNCAccountType t;
if(!acc) return NULL;
if (!acc) return NULL;
t = acc->type;
if((t == STOCK) || (t == MUTUAL) || (t == CURRENCY))
{
KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data, "old-quote-tz");
if(value) return (kvp_value_get_string(value));
if (xaccAccountIsPriced(acc)) {
KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data, "old-quote-tz");
if(value) return (kvp_value_get_string(value));
}
return NULL;
}

View File

@ -217,8 +217,10 @@ void xaccAccountSetDescription (Account *account, const char *desc);
void xaccAccountSetNotes (Account *account, const char *notes);
/** Set the last num field of an Account */
void xaccAccountSetLastNum (Account *account, const char *num);
/** Set the account's type */
/** Get the account's type */
GNCAccountType xaccAccountGetType (const Account *account);
/** Is the account a stock, mutual fund or currency? */
gboolean xaccAccountIsPriced(const Account *acc);
/** Get the account's name */
const char * xaccAccountGetName (const Account *account);

View File

@ -208,11 +208,9 @@ gnc_tracking_associate_income_accounts(Account *stock_account,
{
KvpFrame *account_frame, *inc_account_frame;
KvpValue *kvpd_on_account_list;
GNCAccountType type;
g_return_if_fail(stock_account);
type = xaccAccountGetType(stock_account);
g_return_if_fail(type == STOCK || type == MUTUAL);
g_return_if_fail(xaccAccountIsPriced(stock_account));
account_frame = xaccAccountGetSlots(stock_account);
g_return_if_fail(account_frame);
g_return_if_fail(category >= 0);
@ -250,11 +248,9 @@ gnc_tracking_asssociate_expense_account(Account *stock_account,
{
KvpFrame *account_frame, *expense_acc_frame;
KvpValue *kvpd_on_account_list;
GNCAccountType type;
g_return_if_fail(stock_account);
type = xaccAccountGetType(stock_account);
g_return_if_fail(type == STOCK || type == MUTUAL);
g_return_if_fail(xaccAccountIsPriced(stock_account));
account_frame = xaccAccountGetSlots(stock_account);
g_return_if_fail(account_frame);
g_return_if_fail(category >= 0);
@ -286,15 +282,12 @@ GList *
gnc_tracking_find_expense_accounts(Account *stock_account,
GNCTrackingExpenseCategory category)
{
GNCAccountType type;
KvpFrame *account_frame, *expense_acc_frame;
KvpValue *kvpd_on_account_list;
type = xaccAccountGetType(stock_account);
g_return_val_if_fail(xaccAccountIsPriced(stock_account), NULL);
g_return_val_if_fail(category >= 0 && category < GNC_TR_EXP_N_CATEGORIES,
NULL);
g_return_val_if_fail(type == STOCK || type == MUTUAL, NULL);
account_frame = xaccAccountGetSlots(stock_account);
g_return_val_if_fail(account_frame, NULL);
@ -321,14 +314,12 @@ GList *
gnc_tracking_find_income_accounts(Account *stock_account,
GNCTrackingIncomeCategory category)
{
GNCAccountType type;
KvpFrame *account_frame, *income_acc_frame;
KvpValue *kvpd_on_account_list;
type = xaccAccountGetType(stock_account);
g_return_val_if_fail(xaccAccountIsPriced(stock_account), NULL);
g_return_val_if_fail(category >= 0 && category < GNC_TR_INC_N_CATEGORIES,
NULL);
g_return_val_if_fail(type == STOCK || type == MUTUAL, NULL);
account_frame = xaccAccountGetSlots(stock_account);
g_return_val_if_fail(account_frame, NULL);

View File

@ -126,19 +126,16 @@ fill_account_list (StockSplitInfo *info, Account *account)
Account *account = node->data;
GNCPrintAmountInfo print_info;
const gnc_commodity *commodity;
GNCAccountType account_type;
gnc_numeric balance;
char *strings[4];
gint row;
account_type = xaccAccountGetType (account);
if (account_type != STOCK &&
account_type != MUTUAL)
continue;
if (!xaccAccountIsPriced(account))
continue;
balance = xaccAccountGetBalance (account);
if (gnc_numeric_zero_p (balance))
continue;
continue;
if (xaccAccountGetPlaceholder (account))
continue;

View File

@ -1791,7 +1791,6 @@ add_summary_label (GtkWidget *summarybar, const char *label_str)
GtkWidget *
gsr_create_summary_bar( GNCSplitReg *gsr )
{
gboolean has_shares;
GtkWidget *summarybar;
gsr->cleared_label = NULL;
@ -1807,30 +1806,9 @@ gsr_create_summary_bar( GNCSplitReg *gsr )
return NULL;
}
{
Account *account;
GNCAccountType atype;
account = gnc_ledger_display_leader( gsr->ledger );
atype = xaccAccountGetType (account);
switch (atype)
{
case STOCK:
case MUTUAL:
case CURRENCY:
has_shares = TRUE;
break;
default:
has_shares = FALSE;
break;
}
}
summarybar = gtk_hbox_new (FALSE, 4);
if (!has_shares)
if (!xaccAccountIsPriced(gnc_ledger_display_leader(gsr->ledger)))
{
gsr->balance_label = add_summary_label (summarybar, _("Present:"));
gsr->future_label = add_summary_label (summarybar, _("Future:"));

View File

@ -227,16 +227,7 @@ gnc_get_default_register_style (GNCAccountType type)
static gpointer
look_for_portfolio_cb (Account *account, gpointer data)
{
GNCAccountType le_type;
le_type = xaccAccountGetType (account);
if ((STOCK == le_type) ||
(MUTUAL == le_type) ||
(CURRENCY == le_type))
{
return (gpointer) PORTFOLIO_LEDGER;
}
return NULL;
return xaccAccountIsPriced(account) ? (gpointer) PORTFOLIO_LEDGER : NULL;
}
static SplitRegisterType

View File

@ -61,7 +61,6 @@ static gboolean
gnc_split_register_use_security_cells (SplitRegister *reg,
VirtualLocation virt_loc)
{
GNCAccountType account_type;
CursorClass cursor_class;
Account *account;
Split *split;
@ -93,14 +92,7 @@ gnc_split_register_use_security_cells (SplitRegister *reg,
if (!account)
return TRUE;
account_type = xaccAccountGetType (account);
if (account_type == STOCK ||
account_type == MUTUAL ||
account_type == CURRENCY)
return TRUE;
return FALSE;
return xaccAccountIsPriced(account);
}
static const char *

View File

@ -1600,7 +1600,6 @@ gnc_split_register_auto_calc (SplitRegister *reg, Split *split)
gboolean recalc_shares = FALSE;
gboolean recalc_price = FALSE;
gboolean recalc_value = FALSE;
GNCAccountType account_type;
gboolean price_changed;
gboolean amount_changed; /* please s/amount_changed/value_changed/ */
gboolean shares_changed;
@ -1624,12 +1623,8 @@ gnc_split_register_auto_calc (SplitRegister *reg, Split *split)
if (!account)
account = gnc_split_register_get_default_account (reg);
account_type = xaccAccountGetType (account);
if (account_type != STOCK &&
account_type != MUTUAL &&
account_type != CURRENCY)
return TRUE;
if (!xaccAccountIsPriced(account))
return TRUE;
price_changed = gnc_table_layout_get_cell_changed (reg->table->layout,
PRIC_CELL, TRUE);