GnuCash  5.6-150-g038405b370+
Files | Data Structures | Macros | Typedefs | Enumerations | Functions

Splits are grouped into Accounts which are also known as "Ledgers" in accounting practice. More...

Files

file  Account.h
 Account handling public routines.
 
file  Account.hpp
 Account public routines (C++ api)
 

Data Structures

struct  AccountClass
 

Macros

#define GNC_TYPE_ACCOUNT   (gnc_account_get_type ())
 
#define GNC_ACCOUNT(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ACCOUNT, Account))
 
#define GNC_ACCOUNT_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ACCOUNT, AccountClass))
 
#define GNC_IS_ACCOUNT(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ACCOUNT))
 
#define GNC_IS_ACCOUNT_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ACCOUNT))
 
#define GNC_ACCOUNT_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ACCOUNT, AccountClass))
 

Typedefs

typedef gnc_numeric(* xaccGetBalanceFn) (const Account *account)
 
typedef gnc_numeric(* xaccGetBalanceInCurrencyFn) (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
typedef gnc_numeric(* xaccGetBalanceAsOfDateFn) (Account *account, time64 date)
 
typedef void(* AccountCb) (Account *a, gpointer data)
 
typedef gpointer(* AccountCb2) (Account *a, gpointer data)
 
using SplitsVec = std::vector< Split * >
 
using AccountVec = std::vector< Account * >
 

Enumerations

enum  GNCAccountType {
  ACCT_TYPE_INVALID = -1, ACCT_TYPE_NONE = -1, ACCT_TYPE_BANK = 0, ACCT_TYPE_CASH = 1,
  ACCT_TYPE_CREDIT = 3, ACCT_TYPE_ASSET = 2, ACCT_TYPE_LIABILITY = 4, ACCT_TYPE_STOCK = 5,
  ACCT_TYPE_MUTUAL = 6, ACCT_TYPE_CURRENCY = 7, ACCT_TYPE_INCOME = 8, ACCT_TYPE_EXPENSE = 9,
  ACCT_TYPE_EQUITY = 10, ACCT_TYPE_RECEIVABLE = 11, ACCT_TYPE_PAYABLE = 12, ACCT_TYPE_ROOT = 13,
  ACCT_TYPE_TRADING = 14, NUM_ACCOUNT_TYPES = 15, ACCT_TYPE_CHECKING = 15, ACCT_TYPE_SAVINGS = 16,
  ACCT_TYPE_MONEYMRKT = 17, ACCT_TYPE_CREDITLINE = 18, ACCT_TYPE_LAST
}
 The account types are used to determine how the transaction data in the account is displayed. More...
 

Functions

GType gnc_account_get_type (void)
 Returns the GType type system description of the Account class. More...
 
gboolean gnc_account_and_descendants_empty (Account *acc)
 
gchar * gnc_account_name_violations_errmsg (const gchar *separator, GList *invalid_account_names)
 Composes a translatable error message showing which account names clash with the current account separator. More...
 
GList * gnc_account_list_name_violations (QofBook *book, const gchar *separator)
 Runs through all the accounts and returns a list of account names that contain the provided separator character. More...
 
void xaccAccountSetReconcileChildrenStatus (Account *account, gboolean status)
 DOCUMENT ME!
 
gboolean xaccAccountGetReconcileChildrenStatus (const Account *account)
 DOCUMENT ME!
 
gboolean xaccAccountHasAncestor (const Account *acc, const Account *ancestor)
 Returns true if the account is 'ancestor' or has 'ancestor' as an ancestor. More...
 
const SplitsVec & xaccAccountGetSplits (const Account *)
 
void gnc_account_foreach_descendant (const Account *, std::function< void(Account *)> func)
 
void gnc_account_foreach_split (const Account *, std::function< void(Split *)>)
 
void gnc_account_foreach_split_until_date (const Account *acc, time64 end_date, std::function< void(Split *)> f)
 
Split * gnc_account_find_split (const Account *, std::function< bool(const Split *)>, bool)
 scans account split list (in forward or reverse order) until predicate split->bool returns true. More...
 
std::vector< const Account * > gnc_account_get_all_parents (const Account *account)
 

Account Constructors, Edit/Commit, Comparison

AccountxaccMallocAccount (QofBook *book)
 Constructor.
 
Accountgnc_account_create_root (QofBook *book)
 Create a new root level account. More...
 
AccountxaccCloneAccount (const Account *source, QofBook *book)
 The xaccCloneAccount() routine makes a simple copy of the indicated account, placing it in the indicated book. More...
 
void xaccAccountBeginEdit (Account *account)
 The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account updates. More...
 
void xaccAccountCommitEdit (Account *account)
 ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account updates. More...
 
void xaccAccountDestroy (Account *account)
 The xaccAccountDestroy() routine can be used to get rid of an account. More...
 
void xaccAccountDestroyAllTransactions (Account *acc)
 Destroy all of the transactions that parent splits in an account.
 
gboolean xaccAccountEqual (const Account *a, const Account *b, gboolean check_guids)
 Compare two accounts for equality - this is a deep compare. More...
 
int xaccAccountOrder (const Account *account_1, const Account *account_2)
 The xaccAccountOrder() subroutine defines a sorting order on accounts. More...
 

Account lookup and GncGUID routines

const gchar * gnc_get_account_separator_string (void)
 Returns the account separation character chosen by the user. More...
 
gunichar gnc_get_account_separator (void)
 
void gnc_set_account_separator (const gchar *separator)
 
Accountgnc_book_get_root_account (QofBook *book)
 
void gnc_book_set_root_account (QofBook *book, Account *root)
 
AccountxaccAccountLookup (const GncGUID *guid, QofBook *book)
 The xaccAccountLookup() subroutine will return the account associated with the given id, or NULL if there is no such account. More...
 
#define xaccAccountGetGUID(X)   qof_entity_get_guid(QOF_INSTANCE(X))
 
#define xaccAccountReturnGUID(X)   (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
 
#define xaccAccountLookupDirect(g, b)   xaccAccountLookup(&(g),b)
 

Account general setters/getters

QofBookgnc_account_get_book (const Account *account)
 
void xaccAccountSetType (Account *account, GNCAccountType)
 Set the account's type.
 
void xaccAccountSetName (Account *account, const char *name)
 Set the account's name.
 
void xaccAccountSetCode (Account *account, const char *code)
 Set the account's accounting code.
 
void xaccAccountSetDescription (Account *account, const char *desc)
 Set the account's description.
 
void xaccAccountSetColor (Account *account, const char *color)
 Set the account's Color.
 
void xaccAccountSetFilter (Account *account, const char *filter)
 Set the account's Filter.
 
void xaccAccountSetSortOrder (Account *account, const char *sortorder)
 Set the account's Sort Order.
 
void xaccAccountSetSortReversed (Account *account, gboolean sortreversed)
 Set the account's Sort Order direction.
 
void xaccAccountSetNotes (Account *account, const char *notes)
 Set the account's notes.
 
void xaccAccountSetOnlineID (Account *account, const char *id)
 Set the account's online_id, the identifier (e.g. More...
 
void xaccAccountSetAssociatedAccount (Account *acc, const char *tag, const Account *assoc_acct)
 Set the account's associated account e.g. More...
 
void xaccAccountSetLastNum (Account *account, const char *num)
 Set the last num field of an Account.
 
void gnc_account_set_policy (Account *account, GNCPolicy *policy)
 Set the account's lot order policy.
 
GNCAccountType xaccAccountGetType (const Account *account)
 Returns the account's account type. More...
 
gboolean xaccAccountIsPriced (const Account *acc)
 Returns true if the account is a stock, mutual fund or currency, otherwise false. More...
 
void gnc_account_set_start_balance (Account *acc, const gnc_numeric start_baln)
 This function will set the starting commodity balance for this account. More...
 
void gnc_account_set_start_cleared_balance (Account *acc, const gnc_numeric start_baln)
 This function will set the starting cleared commodity balance for this account. More...
 
void gnc_account_set_start_reconciled_balance (Account *acc, const gnc_numeric start_baln)
 This function will set the starting reconciled commodity balance for this account. More...
 
void gnc_account_set_balance_dirty (Account *acc)
 Tell the account that the running balances may be incorrect and need to be recomputed. More...
 
void gnc_account_set_sort_dirty (Account *acc)
 Tell the account believes that the splits may be incorrectly sorted and need to be resorted. More...
 
void gnc_account_set_defer_bal_computation (Account *acc, gboolean defer)
 Set the defer balance flag. More...
 
gboolean gnc_account_insert_split (Account *acc, Split *s)
 Insert the given split from an account. More...
 
gboolean gnc_account_remove_split (Account *acc, Split *s)
 Remove the given split from an account. More...
 
const char * xaccAccountGetName (const Account *account)
 Get the account's name.
 
const char * xaccAccountGetCode (const Account *account)
 Get the account's accounting code.
 
const char * xaccAccountGetDescription (const Account *account)
 Get the account's description.
 
const char * xaccAccountGetColor (const Account *account)
 Get the account's color.
 
const char * xaccAccountGetFilter (const Account *account)
 Get the account's filter.
 
const char * xaccAccountGetSortOrder (const Account *account)
 Get the account's Sort Order.
 
gboolean xaccAccountGetSortReversed (const Account *account)
 Get the account's Sort Order direction.
 
const char * xaccAccountGetNotes (const Account *account)
 Get the account's notes.
 
const char * xaccAccountGetOnlineID (const Account *account)
 Get the account's online_id (see xaccAccountSetOnlineID). More...
 
AccountxaccAccountGetAssociatedAccount (const Account *acc, const char *tag)
 Get the account's associated account e.g. More...
 
const char * xaccAccountGetLastNum (const Account *account)
 Get the last num field of an Account.
 
GNCPolicy * gnc_account_get_policy (Account *account)
 Get the account's lot order policy.
 
gboolean gnc_account_get_defer_bal_computation (Account *acc)
 Get the account's flag for deferred balance computation.
 
void xaccAccountRecomputeBalance (Account *)
 The following recompute the partial balances (stored with the transaction) and the total balance, for this account.
 
void xaccAccountSortSplits (Account *acc, gboolean force)
 The xaccAccountSortSplits() routine will resort the account's splits if the sort is dirty. More...
 
gchar * gnc_account_get_full_name (const Account *account)
 The gnc_account_get_full_name routine returns the fully qualified name of the account using the given separator char. More...
 
AccountxaccAccountGainsAccount (Account *acc, gnc_commodity *curr)
 Retrieve the gains account used by this account for the indicated currency, creating and recording a new one if necessary. More...
 
void dxaccAccountSetPriceSrc (Account *account, const char *src)
 Set a string that identifies the Finance::Quote backend that should be used to retrieve online prices. More...
 
const char * dxaccAccountGetPriceSrc (const Account *account)
 Get a string that identifies the Finance::Quote backend that should be used to retrieve online prices. More...
 

Account Commodity setters/getters

Accounts are used to store an amount of 'something', that 'something'
is called the 'commodity'.

An account can only hold one kind of commodity. The following are used to get and set the commodity, and also to set the SCU, the 'Smallest Commodity Unit'.

Note that when we say that a 'split' holds an 'amount', that amount is denominated in the account commodity. Do not confuse 'amount' and 'value'. The 'value' of a split is the value of the amount expressed in the currency of the transaction. Thus, for example, the 'amount' may be 12 apples, where the account commodity is 'apples'. The value of these 12 apples may be 12 dollars, where the transaction currency is 'dollars'.

The SCU is the 'Smallest Commodity Unit', signifying the smallest non-zero amount that can be stored in the account. It is represented as the integer denominator of a fraction. Thus, for example, a SCU of 12 means that 1/12 of something is the smallest amount that can be stored in the account. SCU's can be any value; they do not need to be decimal. This allows the use of accounts with unusual, non-decimal commodities and currencies.

Normally, the SCU is determined by the commodity of the account. However, this default SCU can be over-ridden and set to an account-specific value. This is account-specific value is called the 'non-standard' value in the documentation below.

void xaccAccountSetCommodity (Account *account, gnc_commodity *comm)
 Set the account's commodity.
 
gnc_commodity * xaccAccountGetCommodity (const Account *account)
 Get the account's commodity.
 
gnc_commodity * gnc_account_get_currency_or_parent (const Account *account)
 Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency. More...
 
int xaccAccountGetCommoditySCU (const Account *account)
 Return the SCU for the account. More...
 
int xaccAccountGetCommoditySCUi (const Account *account)
 Return the 'internal' SCU setting. More...
 
void xaccAccountSetCommoditySCU (Account *account, int frac)
 Set the SCU for the account. More...
 
void xaccAccountSetNonStdSCU (Account *account, gboolean flag)
 Set the flag indicating that this account uses a non-standard SCU. More...
 
gboolean xaccAccountGetNonStdSCU (const Account *account)
 Return boolean, indicating whether this account uses a non-standard SCU. More...
 

Account Balance

gnc_numeric xaccAccountGetBalance (const Account *account)
 Get the current balance of the account, which may include future splits.
 
gnc_numeric xaccAccountGetClearedBalance (const Account *account)
 Get the current balance of the account, only including cleared transactions.
 
gnc_numeric xaccAccountGetReconciledBalance (const Account *account)
 Get the current balance of the account, only including reconciled transactions.
 
gnc_numeric xaccAccountGetPresentBalance (const Account *account)
 
gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account)
 
gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account, time64 date)
 Get the balance of the account at the end of the day before the date specified. More...
 
gnc_numeric xaccAccountGetReconciledBalanceAsOfDate (Account *account, time64 date)
 Get the reconciled balance of the account at the end of the day of the date specified. More...
 
gnc_numeric xaccAccountConvertBalanceToCurrency (const Account *account, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
 
gnc_numeric xaccAccountConvertBalanceToCurrencyAsOfDate (const Account *account, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 date)
 
gnc_numeric xaccAccountGetBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetClearedBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetReconciledBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetPresentBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetProjectedMinimumBalanceInCurrency (const Account *account, const gnc_commodity *report_commodity, gboolean include_children)
 
gnc_numeric xaccAccountGetNoclosingBalanceAsOfDateInCurrency (Account *acc, time64 date, gnc_commodity *report_commodity, gboolean include_children)
 This function gets the balance at the end of the given date, ignoring closing entries, in the desired commodity. More...
 
gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency (Account *account, time64 date, gnc_commodity *report_commodity, gboolean include_children)
 This function gets the balance at the end of the given date in the desired commodity. More...
 
gnc_numeric xaccAccountGetNoclosingBalanceChangeForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 
gnc_numeric xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 
gnc_numeric xaccAccountGetBalanceChangeForPeriod (Account *acc, time64 date1, time64 date2, gboolean recurse)
 
gboolean xaccAccountHasStockSplit (const Account *acc)
 Returns true if the account has a stock split, otherwise false. More...
 

Account Children and Parents.

The set of accounts is represented as a doubly-linked tree, so that given any account, both its parent and its children can be easily found.

At the top of the tree hierarchy lies a single root node, the root account.

The account tree hierarchy is unique, in that a given account can have only one parent account.

void gnc_account_append_child (Account *new_parent, Account *child)
 This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent. More...
 
void gnc_account_remove_child (Account *parent, Account *child)
 This function will remove the specified child account from the specified parent account. More...
 
Accountgnc_account_get_parent (const Account *account)
 This routine returns a pointer to the parent of the specified account. More...
 
Accountgnc_account_get_root (Account *account)
 This routine returns the root account of the account tree that the specified account belongs to. More...
 
gboolean gnc_account_is_root (const Account *account)
 This routine indicates whether the specified account is the root node of an account tree. More...
 
GList * gnc_account_get_children (const Account *account)
 This routine returns a GList of all children accounts of the specified account. More...
 
GList * gnc_account_get_children_sorted (const Account *account)
 This routine returns a GList of all children accounts of the specified account, ordered by xaccAccountOrder(). More...
 
gint gnc_account_n_children (const Account *account)
 Return the number of children of the specified account. More...
 
gint gnc_account_child_index (const Account *parent, const Account *child)
 Return the index of the specified child within the list of the parent's children. More...
 
Accountgnc_account_nth_child (const Account *parent, gint num)
 Return the n'th child account of the specified parent account. More...
 
GList * gnc_account_get_descendants (const Account *account)
 This routine returns a flat list of all of the accounts that are descendants of the specified account. More...
 
GList * gnc_account_get_descendants_sorted (const Account *account)
 This function returns a GList containing all the descendants of the specified account, sorted at each level. More...
 
gint gnc_account_n_descendants (const Account *account)
 Return the number of descendants of the specified account. More...
 
gint gnc_account_get_current_depth (const Account *account)
 Return the number of levels of this account below the root account. More...
 
gint gnc_account_get_tree_depth (const Account *account)
 Return the number of levels of descendants accounts below the specified account. More...
 

ForEach

void gnc_account_foreach_child (const Account *account, AccountCb func, gpointer user_data)
 This method will traverse the immediate children of this accounts, calling 'func' on each account. More...
 
void gnc_account_foreach_descendant (const Account *account, AccountCb func, gpointer user_data)
 This method will traverse all children of this accounts and their descendants, calling 'func' on each account. More...
 
gpointer gnc_account_foreach_descendant_until (const Account *account, AccountCb2 func, gpointer user_data)
 This method will traverse all children of this accounts and their descendants, calling 'func' on each account. More...
 

Concatenation, Merging

void gnc_account_join_children (Account *to_parent, Account *from_parent)
 The gnc_account_join_children() subroutine will move (reparent) all child accounts from the from_parent account to the to_parent account, preserving the account hierarchy. More...
 
void gnc_account_merge_children (Account *parent)
 The gnc_account_merge_children() subroutine will go through an account, merging all child accounts that have the same name and description. More...
 

Detailed Description

Splits are grouped into Accounts which are also known as "Ledgers" in accounting practice.

Each Account consists of a list of Splits that debit that Account. To ensure consistency, if a Split points to an Account, then the Account must point to the Split, and vice-versa. A Split can belong to at most one Account. Besides merely containing a list of Splits, the Account structure also gives the Account a name, a code number, description and notes fields, a key-value frame, a pointer to the commodity that is used for all splits in this account. The commodity can be the name of anything traded and tradeable: a stock (e.g. "IBM", "McDonald's"), a currency (e.g. "USD", "GBP"), or anything added to the commodity table.

Accounts can be arranged in a hierarchical tree. By accounting convention, the value of an Account is equal to the value of all of its Splits plus the value of all of its sub-Accounts.

Macro Definition Documentation

◆ xaccAccountGetGUID

#define xaccAccountGetGUID (   X)    qof_entity_get_guid(QOF_INSTANCE(X))
Deprecated:

Definition at line 252 of file Account.h.

Enumeration Type Documentation

◆ GNCAccountType

The account types are used to determine how the transaction data in the account is displayed.

These values can be safely changed from one release to the next. Note that if values are added, the file IO translation routines need to be updated. Note also that GUI code depends on these numbers.

Note
IMPORTANT: If you do change the enumeration names (not the numbers), you need to update xaccAccountTypeEnumAsString — used for text file exports
Enumerator
ACCT_TYPE_INVALID 

Not a type.

ACCT_TYPE_NONE 

Not a type.

ACCT_TYPE_BANK 

The bank account type denotes a savings or checking account held at a bank.

Often interest bearing.

ACCT_TYPE_CASH 

The cash account type is used to denote a shoe-box or pillowcase stuffed with * cash.

ACCT_TYPE_CREDIT 

The Credit card account is used to denote credit (e.g.

amex) and debit (e.g. visa, mastercard) card accounts

ACCT_TYPE_ASSET 

asset (and liability) accounts indicate generic, generalized accounts that are none of the above.

ACCT_TYPE_LIABILITY 

liability (and asset) accounts indicate generic, generalized accounts that are none of the above.

ACCT_TYPE_STOCK 

Stock accounts will typically be shown in registers which show three columns: price, number of shares, and value.

ACCT_TYPE_MUTUAL 

Mutual Fund accounts will typically be shown in registers which show three columns: price, number of shares, and value.

ACCT_TYPE_CURRENCY 

The currency account type indicates that the account is a currency trading account.

In many ways, a currency trading account is like a stock * trading account. It is shown in the register with three columns: price, number of shares, and value. Note: Since version 1.7.0, this account is * no longer needed to exchange currencies between accounts, so this type is DEPRECATED.

ACCT_TYPE_INCOME 

Income accounts are used to denote income.

ACCT_TYPE_EXPENSE 

Expense accounts are used to denote expenses.

ACCT_TYPE_EQUITY 

Equity account is used to balance the balance sheet.

ACCT_TYPE_RECEIVABLE 

A/R account type.

ACCT_TYPE_PAYABLE 

A/P account type.

ACCT_TYPE_ROOT 

The hidden root account of an account tree.

ACCT_TYPE_TRADING 

Account used to record multiple commodity transactions.

This is not the same as ACCT_TYPE_CURRENCY above. Multiple commodity transactions have splits in these accounts to make the transaction balance in each commodity as well as in total value.

NUM_ACCOUNT_TYPES 

stop here; the following types just aren't ready for prime time

ACCT_TYPE_CHECKING 

bank account type – don't use this for now, see NUM_ACCOUNT_TYPES

ACCT_TYPE_SAVINGS 

bank account type – don't use this for now, see NUM_ACCOUNT_TYPES

ACCT_TYPE_MONEYMRKT 

bank account type – don't use this for now, see NUM_ACCOUNT_TYPES

ACCT_TYPE_CREDITLINE 

line of credit – don't use this for now, see NUM_ACCOUNT_TYPES

Definition at line 101 of file Account.h.

103 {
104  ACCT_TYPE_INVALID = -1,
105  ACCT_TYPE_NONE = -1,
107  ACCT_TYPE_BANK = 0,
110  ACCT_TYPE_CASH = 1,
113  ACCT_TYPE_CREDIT = 3,
116  ACCT_TYPE_ASSET = 2,
122  ACCT_TYPE_STOCK = 5,
125  ACCT_TYPE_MUTUAL = 6,
129  ACCT_TYPE_CURRENCY = 7,
140  ACCT_TYPE_INCOME = 8,
143  ACCT_TYPE_EXPENSE = 9,
146  ACCT_TYPE_EQUITY = 10,
151  ACCT_TYPE_PAYABLE = 12,
153  ACCT_TYPE_ROOT = 13,
155  ACCT_TYPE_TRADING = 14,
161  NUM_ACCOUNT_TYPES = 15,
164  /* bank account types */
165  ACCT_TYPE_CHECKING = 15,
167  ACCT_TYPE_SAVINGS = 16,
169  ACCT_TYPE_MONEYMRKT = 17,
171  ACCT_TYPE_CREDITLINE = 18,
173  ACCT_TYPE_LAST
174 #ifdef __cplusplus
175 };
176 #else
Expense accounts are used to denote expenses.
Definition: Account.h:143
Mutual Fund accounts will typically be shown in registers which show three columns: price...
Definition: Account.h:125
stop here; the following types just aren&#39;t ready for prime time
Definition: Account.h:161
The cash account type is used to denote a shoe-box or pillowcase stuffed with * cash.
Definition: Account.h:110
Account used to record multiple commodity transactions.
Definition: Account.h:155
Stock accounts will typically be shown in registers which show three columns: price, number of shares, and value.
Definition: Account.h:122
bank account type – don&#39;t use this for now, see NUM_ACCOUNT_TYPES
Definition: Account.h:165
Income accounts are used to denote income.
Definition: Account.h:140
line of credit – don&#39;t use this for now, see NUM_ACCOUNT_TYPES
Definition: Account.h:171
The bank account type denotes a savings or checking account held at a bank.
Definition: Account.h:107
A/P account type.
Definition: Account.h:151
bank account type – don&#39;t use this for now, see NUM_ACCOUNT_TYPES
Definition: Account.h:167
asset (and liability) accounts indicate generic, generalized accounts that are none of the above...
Definition: Account.h:116
The currency account type indicates that the account is a currency trading account.
Definition: Account.h:129
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
Definition: Account.h:101
Not a type.
Definition: Account.h:104
liability (and asset) accounts indicate generic, generalized accounts that are none of the above...
Definition: Account.h:119
A/R account type.
Definition: Account.h:149
bank account type – don&#39;t use this for now, see NUM_ACCOUNT_TYPES
Definition: Account.h:169
Equity account is used to balance the balance sheet.
Definition: Account.h:146
Not a type.
Definition: Account.h:105
The hidden root account of an account tree.
Definition: Account.h:153
The Credit card account is used to denote credit (e.g.
Definition: Account.h:113

Function Documentation

◆ dxaccAccountGetPriceSrc()

const char* dxaccAccountGetPriceSrc ( const Account account)

Get a string that identifies the Finance::Quote backend that should be used to retrieve online prices.

See price-quotes.scm for more information. This function uses a static char*.

Deprecated:
Price quote information is now stored on the commodity, not the account.

Definition at line 4847 of file Account.cpp.

4848 {
4849  if (!acc) return nullptr;
4850 
4851  if (!xaccAccountIsPriced(acc)) return nullptr;
4852 
4853  return get_kvp_string_path (acc, {"old-price-source"});
4854 }
gboolean xaccAccountIsPriced(const Account *acc)
Returns true if the account is a stock, mutual fund or currency, otherwise false. ...
Definition: Account.cpp:4551

◆ dxaccAccountSetPriceSrc()

void dxaccAccountSetPriceSrc ( Account account,
const char *  src 
)

Set a string that identifies the Finance::Quote backend that should be used to retrieve online prices.

See price-quotes.scm for more information

Deprecated:
Price quote information is now stored on the commodity, not the account.

Definition at line 4835 of file Account.cpp.

4836 {
4837  if (!acc) return;
4838 
4839  if (xaccAccountIsPriced(acc))
4840  set_kvp_string_path (acc, {"old-price-source"}, src);
4841 }
gboolean xaccAccountIsPriced(const Account *acc)
Returns true if the account is a stock, mutual fund or currency, otherwise false. ...
Definition: Account.cpp:4551

◆ gnc_account_append_child()

void gnc_account_append_child ( Account new_parent,
Account child 
)

This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.

The exception to this is when the old and new parent accounts are the same, in which case this function does nothing.

If the child account belongs to a different book than the specified new parent account, the child will be removed from the other book (and thus, the other book's entity tables, generating a destroy event), and will be added to the new book (generating a create event).

Parameters
new_parentThe new parent account to which the child should be attached.
childThe account to attach.

Definition at line 2836 of file Account.cpp.

2837 {
2838  AccountPrivate *ppriv, *cpriv;
2839  Account *old_parent;
2840  QofCollection *col;
2841 
2842  /* errors */
2843  g_assert(GNC_IS_ACCOUNT(new_parent));
2844  g_assert(GNC_IS_ACCOUNT(child));
2845 
2846  /* optimizations */
2847  ppriv = GET_PRIVATE(new_parent);
2848  cpriv = GET_PRIVATE(child);
2849  old_parent = cpriv->parent;
2850  if (old_parent == new_parent)
2851  return;
2852 
2853  // xaccAccountBeginEdit(new_parent);
2854  xaccAccountBeginEdit(child);
2855  if (old_parent)
2856  {
2857  gnc_account_remove_child(old_parent, child);
2858 
2859  if (!qof_instance_books_equal(old_parent, new_parent))
2860  {
2861  /* hack alert -- this implementation is not exactly correct.
2862  * If the entity tables are not identical, then the 'from' book
2863  * may have a different backend than the 'to' book. This means
2864  * that we should get the 'from' backend to destroy this account,
2865  * and the 'to' backend to save it. Right now, this is broken.
2866  *
2867  * A 'correct' implementation similar to this is in Period.c
2868  * except its for transactions ...
2869  *
2870  * Note also, we need to reparent the children to the new book as well.
2871  */
2872  PWARN ("reparenting accounts across books is not correctly supported\n");
2873 
2874  qof_event_gen (&child->inst, QOF_EVENT_DESTROY, nullptr);
2876  GNC_ID_ACCOUNT);
2877  qof_collection_insert_entity (col, &child->inst);
2878  qof_event_gen (&child->inst, QOF_EVENT_CREATE, nullptr);
2879  }
2880  }
2881  cpriv->parent = new_parent;
2882  ppriv->children.push_back (child);
2883  qof_instance_set_dirty(&new_parent->inst);
2884  qof_instance_set_dirty(&child->inst);
2885 
2886  /* Send events data. Warning: The call to commit_edit is also going
2887  * to send a MODIFY event. If the gtktreemodelfilter code gets the
2888  * MODIFY before it gets the ADD, it gets very confused and thinks
2889  * that two nodes have been added. */
2890  qof_event_gen (&child->inst, QOF_EVENT_ADD, nullptr);
2891  // qof_event_gen (&new_parent->inst, QOF_EVENT_MODIFY, nullptr);
2892 
2893  xaccAccountCommitEdit (child);
2894  // xaccAccountCommitEdit(new_parent);
2895 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
STRUCTS.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
void gnc_account_remove_child(Account *parent, Account *child)
This function will remove the specified child account from the specified parent account.
Definition: Account.cpp:2898
void qof_collection_insert_entity(QofCollection *, QofInstance *)
Take entity, remove it from whatever collection its currently in, and place it in a new collection...
Definition: qofid.cpp:95
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
See if two QofInstances share the same book.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1475
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:231
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1516

◆ gnc_account_child_index()

gint gnc_account_child_index ( const Account parent,
const Account child 
)

Return the index of the specified child within the list of the parent's children.

The first child index is 0. This function returns -1 if the parent account is NULL of if the specified child does not belong to the parent account.

Parameters
parentThe parent account to check.
childThe child account to find.
Returns
The index of the child account within the specified parent, or -1.

Definition at line 2983 of file Account.cpp.

2984 {
2985  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), -1);
2986  g_return_val_if_fail(GNC_IS_ACCOUNT(child), -1);
2987  auto& children = GET_PRIVATE(parent)->children;
2988  auto find_it = std::find (children.begin(), children.end(), child);
2989  return find_it == children.end() ? -1 : std::distance (children.begin(), find_it);
2990 }

◆ gnc_account_create_root()

Account* gnc_account_create_root ( QofBook book)

Create a new root level account.

Definition at line 1284 of file Account.cpp.

1285 {
1286  Account *root;
1287  AccountPrivate *rpriv;
1288 
1289  root = xaccMallocAccount(book);
1290  rpriv = GET_PRIVATE(root);
1291  xaccAccountBeginEdit(root);
1292  rpriv->type = ACCT_TYPE_ROOT;
1293  rpriv->accountName = qof_string_cache_replace(rpriv->accountName, "Root Account");
1294  mark_account (root);
1295  xaccAccountCommitEdit(root);
1296  gnc_book_set_root_account(book, root);
1297  return root;
1298 }
const char * qof_string_cache_replace(char const *dst, char const *src)
Same as CACHE_REPLACE below, but safe to call from C++.
STRUCTS.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1475
Account * xaccMallocAccount(QofBook *book)
Constructor.
Definition: Account.cpp:1270
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1516
The hidden root account of an account tree.
Definition: Account.h:153

◆ gnc_account_find_split()

Split* gnc_account_find_split ( const Account ,
std::function< bool(const Split *)>  ,
bool   
)

scans account split list (in forward or reverse order) until predicate split->bool returns true.

Maybe return the split.

Parameters
accThe account to which the split should be added.
predicateA split->bool predicate.
reverseTo scan in reverse order
Returns
Split* or nullptr if not found

Definition at line 1167 of file Account.cpp.

1169 {
1170  if (!GNC_IS_ACCOUNT (acc))
1171  return nullptr;
1172 
1173  const auto& splits{GET_PRIVATE(acc)->splits};
1174  if (reverse)
1175  {
1176  auto latest = std::find_if(splits.rbegin(), splits.rend(), predicate);
1177  return (latest == splits.rend()) ? nullptr : *latest;
1178  }
1179  else
1180  {
1181  auto earliest = std::find_if(splits.begin(), splits.end(), predicate);
1182  return (earliest == splits.end()) ? nullptr : *earliest;
1183  }
1184 }

◆ gnc_account_foreach_child()

void gnc_account_foreach_child ( const Account account,
AccountCb  func,
gpointer  user_data 
)

This method will traverse the immediate children of this accounts, calling 'func' on each account.

This function traverses all children nodes. To traverse only a subset of the child nodes use the gnc_account_foreach_child_until() function.

Parameters
accountA pointer to the account on whose children the function should be called.
funcA function taking two arguments, an Account and a gpointer.
user_dataThis data will be passed to each call of func.

Definition at line 3225 of file Account.cpp.

3228 {
3229  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3230  g_return_if_fail(thunk);
3231  std::for_each (GET_PRIVATE(acc)->children.begin(), GET_PRIVATE(acc)->children.end(),
3232  [user_data, thunk](auto a){ thunk (a, user_data); });
3233 }

◆ gnc_account_foreach_descendant()

void gnc_account_foreach_descendant ( const Account account,
AccountCb  func,
gpointer  user_data 
)

This method will traverse all children of this accounts and their descendants, calling 'func' on each account.

This function traverses all descendant nodes. To traverse only a subset of the descendant nodes use the gnc_account_foreach_descendant_until() function.

Parameters
accountA pointer to the account on whose descendants the function should be called.
funcA function taking two arguments, an Account and a gpointer.
user_dataThis data will be passed to each call of func.

Definition at line 3236 of file Account.cpp.

3239 {
3240  gnc_account_foreach_descendant (acc, [&](auto acc){ thunk (acc, user_data); });
3241 }
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling &#39;func&#39; on each...
Definition: Account.cpp:3236

◆ gnc_account_foreach_descendant_until()

gpointer gnc_account_foreach_descendant_until ( const Account account,
AccountCb2  func,
gpointer  user_data 
)

This method will traverse all children of this accounts and their descendants, calling 'func' on each account.

Traversal will stop when func returns a non-null value, and the routine will return with that value. Therefore, this function will return null if func returns null for every account. For a simpler function that always traverses all children nodes, use the gnc_account_foreach_descendant() function.

Parameters
accountA pointer to the account on whose descendants the function should be called.
funcA function taking two arguments, an Account and a gpointer.
user_dataThis data will be passed to each call of func.

Definition at line 3244 of file Account.cpp.

3247 {
3248  gpointer result {nullptr};
3249 
3250  g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr);
3251  g_return_val_if_fail (thunk, nullptr);
3252 
3253  for (auto child : GET_PRIVATE(acc)->children)
3254  {
3255  result = thunk (child, user_data);
3256  if (result) break;
3257 
3258  result = gnc_account_foreach_descendant_until (child, thunk, user_data);
3259  if (result) break;
3260  }
3261 
3262  return result;
3263 }
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling &#39;func&#39; on each...
Definition: Account.cpp:3244

◆ gnc_account_get_children()

GList* gnc_account_get_children ( const Account account)

This routine returns a GList of all children accounts of the specified account.

This function only returns the immediate children of the specified account. For a list of all descendant accounts, use the gnc_account_get_descendants() function.

If you are looking for the splits of this account, use xaccAccountGetSplitList() instead. This function here deals with children accounts inside the account tree.

Parameters
accountThe account whose children should be returned.
Returns
A GList of account pointers, or NULL if there are no children accounts. It is the callers responsibility to free any returned list with the g_list_free() function.

Definition at line 2960 of file Account.cpp.

2961 {
2962  g_return_val_if_fail(GNC_IS_ACCOUNT(account), nullptr);
2963  auto& children = GET_PRIVATE(account)->children;
2964  return std::accumulate (children.rbegin(), children.rend(), static_cast<GList*>(nullptr),
2965  g_list_prepend);
2966 }

◆ gnc_account_get_children_sorted()

GList* gnc_account_get_children_sorted ( const Account account)

This routine returns a GList of all children accounts of the specified account, ordered by xaccAccountOrder().

See also
gnc_account_get_children()

Definition at line 2969 of file Account.cpp.

2970 {
2971  g_return_val_if_fail(GNC_IS_ACCOUNT(account), nullptr);
2972  return g_list_sort(gnc_account_get_children (account), (GCompareFunc)xaccAccountOrder);
2973 }
int xaccAccountOrder(const Account *aa, const Account *ab)
The xaccAccountOrder() subroutine defines a sorting order on accounts.
Definition: Account.cpp:2375
GList * gnc_account_get_children(const Account *account)
This routine returns a GList of all children accounts of the specified account.
Definition: Account.cpp:2960

◆ gnc_account_get_currency_or_parent()

gnc_commodity* gnc_account_get_currency_or_parent ( const Account account)

Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.

The gnc_commodity is taken either from the current account, or from the next parent account that has a gnc_commodity that is a currency. If neither this account nor any of its parent has such a commodity that is a currency, NULL is returned. In that case, you can use gnc_default_currency() but you might want to show a warning dialog first.

Definition at line 3415 of file Account.cpp.

3416 {
3417  g_return_val_if_fail (GNC_IS_ACCOUNT (account), nullptr);
3418 
3419  for (auto acc = account; acc; acc = gnc_account_get_parent (acc))
3420  if (auto comm = xaccAccountGetCommodity (acc); gnc_commodity_is_currency (comm))
3421  return comm;
3422 
3423  return nullptr; // no suitable commodity found.
3424 }
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
Definition: Account.cpp:2935
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency...
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account&#39;s commodity.
Definition: Account.cpp:3408

◆ gnc_account_get_current_depth()

gint gnc_account_get_current_depth ( const Account account)

Return the number of levels of this account below the root account.

Parameters
accountThe account to query.
Returns
The number of levels below the root.

Definition at line 3010 of file Account.cpp.

3011 {
3012  AccountPrivate *priv;
3013  int depth = 0;
3014 
3015  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
3016 
3017  priv = GET_PRIVATE(account);
3018  while (priv->parent && (priv->type != ACCT_TYPE_ROOT))
3019  {
3020  account = priv->parent;
3021  priv = GET_PRIVATE(account);
3022  depth++;
3023  }
3024 
3025  return depth;
3026 }
The hidden root account of an account tree.
Definition: Account.h:153

◆ gnc_account_get_descendants()

GList* gnc_account_get_descendants ( const Account account)

This routine returns a flat list of all of the accounts that are descendants of the specified account.

This includes not only the the children, but the children of the children, etc. For a list of only the immediate child accounts, use the gnc_account_get_children() function. Within each set of child accounts, the accounts returned by this function are unordered. For a list of descendants where each set of children is sorted via the standard account sort function, use the gnc_account_get_descendants_sorted() function.

Parameters
accountThe account whose descendants should be returned.
Returns
A GList of account pointers, or NULL if there are no descendants. It is the callers responsibility to free any returned list with the g_list_free() function.

Definition at line 3044 of file Account.cpp.

3045 {
3046  GList* list = nullptr;
3047  gnc_account_foreach_descendant (account, [&list](auto a){ list = g_list_prepend (list, a); });
3048  return g_list_reverse (list);
3049 }
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling &#39;func&#39; on each...
Definition: Account.cpp:3236

◆ gnc_account_get_descendants_sorted()

GList* gnc_account_get_descendants_sorted ( const Account account)

This function returns a GList containing all the descendants of the specified account, sorted at each level.

This includes not only the the children, but the children of the children, etc. Within each set of child accounts, the accounts returned by this function are ordered via the standard account sort function. For a list of descendants where each set of children is unordered, use the gnc_account_get_descendants() function.

Note: Use this function where the results are intended for display to the user. If the results are internal to GnuCash or will be resorted at some later point in time you should use the gnc_account_get_descendants() function.

Parameters
accountThe account whose descendants should be returned.
Returns
A GList of account pointers, or NULL if there are no descendants. It is the callers responsibility to free any returned list with the g_list_free() function.

Definition at line 3052 of file Account.cpp.

3053 {
3054  GList* list = nullptr;
3055  account_foreach_descendant_sorted (account, [&list](auto a){ list = g_list_prepend (list, a); });
3056  return g_list_reverse (list);
3057 }

◆ gnc_account_get_full_name()

gchar* gnc_account_get_full_name ( const Account account)

The gnc_account_get_full_name routine returns the fully qualified name of the account using the given separator char.

The name must be g_free'd after use. The fully qualified name of an account is the concatenation of the names of the account and all its ancestor accounts starting with the topmost account and ending with the given account. Each name is separated by the given character.

Note
: WAKE UP! Unlike all other gets, the string returned by gnc_account_get_full_name() must be freed by you the user !!! hack alert – since it breaks the rule of string allocation, maybe this routine should not be in this library, but some utility library?

Definition at line 3305 of file Account.cpp.

3306 {
3307  /* So much for hardening the API. Too many callers to this function don't
3308  * bother to check if they have a non-nullptr pointer before calling. */
3309  if (nullptr == account)
3310  return g_strdup("");
3311 
3312  /* errors */
3313  g_return_val_if_fail(GNC_IS_ACCOUNT(account), g_strdup(""));
3314 
3315  auto path{gnc_account_get_all_parents (account)};
3316  auto seps_size{path.empty() ? 0 : strlen (account_separator) * (path.size() - 1)};
3317  auto alloc_size{std::accumulate (path.begin(), path.end(), seps_size,
3318  [](auto sum, auto acc)
3319  { return sum + strlen (xaccAccountGetName (acc)); })};
3320  auto rv = g_new (char, alloc_size + 1);
3321  auto p = rv;
3322 
3323  std::for_each (path.rbegin(), path.rend(),
3324  [&p, rv](auto a)
3325  {
3326  if (p != rv)
3327  p = stpcpy (p, account_separator);
3328  p = stpcpy (p, xaccAccountGetName (a));
3329  });
3330  *p = '\0';
3331 
3332  return rv;
3333 }
const char * xaccAccountGetName(const Account *acc)
Get the account&#39;s name.
Definition: Account.cpp:3289

◆ gnc_account_get_parent()

Account* gnc_account_get_parent ( const Account account)

This routine returns a pointer to the parent of the specified account.

If the account has no parent, i.e it is either the root node or is a disconnected account, then its parent will be NULL.

Parameters
accountA pointer to any exiting account.
Returns
A pointer to the parent account node, or NULL if there is no parent account.

Definition at line 2935 of file Account.cpp.

2936 {
2937  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
2938  return GET_PRIVATE(acc)->parent;
2939 }

◆ gnc_account_get_root()

Account* gnc_account_get_root ( Account account)

This routine returns the root account of the account tree that the specified account belongs to.

It is the equivalent of repeatedly calling the gnc_account_get_parent() routine until that routine returns NULL.

Parameters
accountA pointer to any existing account.
Returns
The root node of the account tree to which this account belongs. NULL if the account is not part of any account tree.

Definition at line 2942 of file Account.cpp.

2943 {
2944  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), nullptr);
2945 
2946  while (auto parent = gnc_account_get_parent (acc))
2947  acc = parent;
2948 
2949  return acc;
2950 }
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
Definition: Account.cpp:2935

◆ gnc_account_get_tree_depth()

gint gnc_account_get_tree_depth ( const Account account)

Return the number of levels of descendants accounts below the specified account.

The returned number does not include the specified account itself.

Parameters
accountThe account to query.
Returns
The number of levels of descendants.

Definition at line 3029 of file Account.cpp.

3030 {
3031  AccountPrivate *priv;
3032  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
3033 
3034  priv = GET_PRIVATE(account);
3035  if (!priv->children.size())
3036  return 1;
3037 
3038  return 1 + std::accumulate (priv->children.begin(), priv->children.end(),
3039  0, [](auto a, auto b)
3040  { return std::max (a, gnc_account_get_tree_depth (b)); });
3041 }
gint gnc_account_get_tree_depth(const Account *account)
Return the number of levels of descendants accounts below the specified account.
Definition: Account.cpp:3029

◆ gnc_account_get_type()

GType gnc_account_get_type ( void  )

Returns the GType type system description of the Account class.

This must not be confused with the GNCAccountType as returned by xaccAccountGetType().

Definition at line 27 of file gmock-Account.cpp.

28 {
29  return gnc_mockaccount_get_type();
30 }

◆ gnc_account_insert_split()

gboolean gnc_account_insert_split ( Account acc,
Split *  s 
)

Insert the given split from an account.

Parameters
accThe account to which the split should be added.
sThe split to be added.
Returns
TRUE is the split is successfully added to the set of splits in the account. FALSE if the addition fails for any reason (including that the split is already in the account).

Definition at line 1943 of file Account.cpp.

1944 {
1945  AccountPrivate *priv;
1946 
1947  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1948  g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1949 
1950  priv = GET_PRIVATE(acc);
1951  if (!g_hash_table_add (priv->splits_hash, s))
1952  return false;
1953 
1954  priv->splits.push_back (s);
1955 
1956  if (qof_instance_get_editlevel(acc) == 0)
1957  std::sort (priv->splits.begin(), priv->splits.end(), split_cmp_less);
1958  else
1959  priv->sort_dirty = true;
1960 
1961  //FIXME: find better event
1962  qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, nullptr);
1963  /* Also send an event based on the account */
1964  qof_event_gen(&acc->inst, GNC_EVENT_ITEM_ADDED, s);
1965 
1966  priv->balance_dirty = TRUE;
1967 // DRH: Should the below be added? It is present in the delete path.
1968 // xaccAccountRecomputeBalance(acc);
1969  return TRUE;
1970 }
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:231
#define GNC_EVENT_ITEM_ADDED
These events are used when a split is added to an account.
Definition: gnc-event.h:45

◆ gnc_account_is_root()

gboolean gnc_account_is_root ( const Account account)

This routine indicates whether the specified account is the root node of an account tree.

Parameters
accountA pointer to any account.
Returns
TRUE if this account is of type ROOT. FALSE otherwise.

Definition at line 2953 of file Account.cpp.

2954 {
2955  g_return_val_if_fail(GNC_IS_ACCOUNT(account), FALSE);
2956  return (GET_PRIVATE(account)->parent == nullptr);
2957 }

◆ gnc_account_join_children()

void gnc_account_join_children ( Account to_parent,
Account from_parent 
)

The gnc_account_join_children() subroutine will move (reparent) all child accounts from the from_parent account to the to_parent account, preserving the account hierarchy.

It will also take care that the moved accounts will have the to_parent's book parent as well.

Definition at line 4931 of file Account.cpp.

4932 {
4933 
4934  /* errors */
4935  g_return_if_fail(GNC_IS_ACCOUNT(to_parent));
4936  g_return_if_fail(GNC_IS_ACCOUNT(from_parent));
4937 
4938  /* optimizations */
4939  auto from_priv = GET_PRIVATE(from_parent);
4940  if (from_priv->children.empty())
4941  return;
4942 
4943  ENTER (" ");
4944  auto children = from_priv->children;
4945  for (auto child : children)
4946  gnc_account_append_child(to_parent, child);
4947  LEAVE (" ");
4948 }
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
Definition: Account.cpp:2836
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_account_list_name_violations()

GList* gnc_account_list_name_violations ( QofBook book,
const gchar *  separator 
)

Runs through all the accounts and returns a list of account names that contain the provided separator character.

This can be used to check if certain account names are invalid.

Parameters
bookPointer to the book with accounts to verify
separatorThe separator character to verify against
Returns
A GList of invalid account names. Should be freed with g_list_free_full (value, g_free) when no longer needed.

Definition at line 273 of file Account.cpp.

274 {
275  g_return_val_if_fail (separator != nullptr, nullptr);
276  if (!book) return nullptr;
277  ViolationData cb = { nullptr, separator };
278  gnc_account_foreach_descendant (gnc_book_get_root_account (book),
279  (AccountCb)check_acct_name, &cb);
280  return cb.list;
281 }
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling &#39;func&#39; on each...
Definition: Account.cpp:3236

◆ gnc_account_merge_children()

void gnc_account_merge_children ( Account parent)

The gnc_account_merge_children() subroutine will go through an account, merging all child accounts that have the same name and description.

This function is useful when importing Quicken(TM) files.

Definition at line 4953 of file Account.cpp.

4954 {
4955  g_return_if_fail(GNC_IS_ACCOUNT(parent));
4956 
4957  auto ppriv = GET_PRIVATE(parent);
4958  for (auto it_a = ppriv->children.begin(); it_a != ppriv->children.end(); it_a++)
4959  {
4960  auto acc_a = *it_a;
4961  auto priv_a = GET_PRIVATE(acc_a);
4962  for (auto it_b = std::next(it_a); it_b != ppriv->children.end(); it_b++)
4963  {
4964  auto acc_b = *it_b;
4965  auto priv_b = GET_PRIVATE(acc_b);
4966  if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
4967  continue;
4968  if (0 != null_strcmp(priv_a->accountCode, priv_b->accountCode))
4969  continue;
4970  if (0 != null_strcmp(priv_a->description, priv_b->description))
4971  continue;
4972  if (0 != null_strcmp(xaccAccountGetColor(acc_a),
4973  xaccAccountGetColor(acc_b)))
4974  continue;
4975  if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
4976  continue;
4977  if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
4978  xaccAccountGetNotes(acc_b)))
4979  continue;
4980  if (priv_a->type != priv_b->type)
4981  continue;
4982 
4983  /* consolidate children */
4984  if (!priv_b->children.empty())
4985  {
4986  auto work = priv_b->children;
4987  for (auto w : work)
4988  gnc_account_append_child (acc_a, w);
4989 
4990  qof_event_gen (&acc_a->inst, QOF_EVENT_MODIFY, nullptr);
4991  qof_event_gen (&acc_b->inst, QOF_EVENT_MODIFY, nullptr);
4992  }
4993 
4994  /* recurse to do the children's children */
4996 
4997  /* consolidate transactions */
4998  while (!priv_b->splits.empty())
4999  xaccSplitSetAccount (priv_b->splits.front(), acc_a);
5000 
5001  /* move back one before removal. next iteration around the loop
5002  * will get the node after node_b */
5003  it_b--;
5004 
5005  /* The destroy function will remove from list -- node_a is ok,
5006  * it's before node_b */
5007  xaccAccountBeginEdit (acc_b);
5008  xaccAccountDestroy (acc_b);
5009  }
5010  }
5011 }
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
Definition: Account.cpp:2836
void xaccAccountDestroy(Account *acc)
The xaccAccountDestroy() routine can be used to get rid of an account.
Definition: Account.cpp:1590
const char * xaccAccountGetColor(const Account *acc)
Get the account&#39;s color.
Definition: Account.cpp:3350
gint null_strcmp(const gchar *da, const gchar *db)
The null_strcmp compares strings a and b the same way that strcmp() does, except that either may be n...
Definition: qofutil.cpp:123
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1475
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:231
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
void gnc_account_merge_children(Account *parent)
The gnc_account_merge_children() subroutine will go through an account, merging all child accounts th...
Definition: Account.cpp:4953
const char * xaccAccountGetNotes(const Account *acc)
Get the account&#39;s notes.
Definition: Account.cpp:3374

◆ gnc_account_n_children()

gint gnc_account_n_children ( const Account account)

Return the number of children of the specified account.

The returned number does not include the account itself.

Parameters
accountThe account to query.
Returns
The number of children of the specified account.

Definition at line 2976 of file Account.cpp.

2977 {
2978  g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
2979  return GET_PRIVATE(account)->children.size();
2980 }

◆ gnc_account_n_descendants()

gint gnc_account_n_descendants ( const Account account)

Return the number of descendants of the specified account.

The returned number does not include the account itself.

Parameters
accountThe account to query.
Returns
The number of descendants of the specified account.

Definition at line 3002 of file Account.cpp.

3003 {
3004  int count {0};
3005  gnc_account_foreach_descendant (account, [&count](auto acc){ count++; });
3006  return count;
3007 }
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling &#39;func&#39; on each...
Definition: Account.cpp:3236

◆ gnc_account_name_violations_errmsg()

gchar* gnc_account_name_violations_errmsg ( const gchar *  separator,
GList *  invalid_account_names 
)

Composes a translatable error message showing which account names clash with the current account separator.

Can be called after gnc_account_list_name_violations to have a consistent error message in different parts of GnuCash

Parameters
separatorThe separator character that was verified against
invalid_account_namesA GList of invalid account names.
Returns
An error message that can be displayed to the user or logged. This message string should be freed with g_free when no longer needed.

Definition at line 235 of file Account.cpp.

236 {
237  gchar *message = nullptr;
238 
239  if ( !invalid_account_names )
240  return nullptr;
241 
242  auto account_list {gnc_g_list_stringjoin (invalid_account_names, "\n")};
243 
244  /* Translators: The first %s will be the account separator character,
245  the second %s is a list of account names.
246  The resulting string will be displayed to the user if there are
247  account names containing the separator character. */
248  message = g_strdup_printf(
249  _("The separator character \"%s\" is used in one or more account names.\n\n"
250  "This will result in unexpected behaviour. "
251  "Either change the account names or choose another separator character.\n\n"
252  "Below you will find the list of invalid account names:\n"
253  "%s"), separator, account_list );
254  g_free ( account_list );
255  return message;
256 }
gchar * gnc_g_list_stringjoin(GList *list_of_strings, const gchar *sep)
Return a string joining a GList whose elements are gchar* strings.

◆ gnc_account_nth_child()

Account* gnc_account_nth_child ( const Account parent,
gint  num 
)

Return the n'th child account of the specified parent account.

If the parent account is not specified or the child index number is invalid, this function returns NULL.

Parameters
parentThe parent account to check.
numThe index number of the child account that should be returned.
Returns
A pointer to the specified child account, or NULL

Definition at line 2993 of file Account.cpp.

2994 {
2995  g_return_val_if_fail(GNC_IS_ACCOUNT(parent), nullptr);
2996  if ((size_t)num >= GET_PRIVATE(parent)->children.size())
2997  return nullptr;
2998  return static_cast<Account*>(GET_PRIVATE(parent)->children.at (num));
2999 }
STRUCTS.

◆ gnc_account_remove_child()

void gnc_account_remove_child ( Account parent,
Account child 
)

This function will remove the specified child account from the specified parent account.

It will NOT free the associated memory or otherwise alter the account: the account can now be reparented to a new location. Note, however, that it will mark the old parents as having been modified.

Parameters
parentThe parent account from which the child should be removed.
childThe child account to remove.

Definition at line 2898 of file Account.cpp.

2899 {
2900  AccountPrivate *ppriv, *cpriv;
2901  GncEventData ed;
2902 
2903  if (!child) return;
2904 
2905  /* Note this routine might be called on accounts which
2906  * are not yet parented. */
2907  if (!parent) return;
2908 
2909  ppriv = GET_PRIVATE(parent);
2910  cpriv = GET_PRIVATE(child);
2911 
2912  if (cpriv->parent != parent)
2913  {
2914  PERR ("account not a child of parent");
2915  return;
2916  }
2917 
2918  /* Gather event data */
2919  ed.node = parent;
2920  ed.idx = gnc_account_child_index (parent, child);
2921 
2922  ppriv->children.erase (std::remove (ppriv->children.begin(), ppriv->children.end(), child),
2923  ppriv->children.end());
2924 
2925  /* Now send the event. */
2926  qof_event_gen(&child->inst, QOF_EVENT_REMOVE, &ed);
2927 
2928  /* clear the account's parent pointer after REMOVE event generation. */
2929  cpriv->parent = nullptr;
2930 
2931  qof_event_gen (&parent->inst, QOF_EVENT_MODIFY, nullptr);
2932 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
gint gnc_account_child_index(const Account *parent, const Account *child)
Return the index of the specified child within the list of the parent&#39;s children. ...
Definition: Account.cpp:2983
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:231

◆ gnc_account_remove_split()

gboolean gnc_account_remove_split ( Account acc,
Split *  s 
)

Remove the given split from an account.

Parameters
accThe account from which the split should be removed.
sThe split to be removed.
Returns
TRUE is the split is successfully removed from the set of splits in the account. FALSE if the removal fails for any reason.

Definition at line 1973 of file Account.cpp.

1974 {
1975  AccountPrivate *priv;
1976 
1977  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
1978  g_return_val_if_fail(GNC_IS_SPLIT(s), FALSE);
1979 
1980  priv = GET_PRIVATE(acc);
1981 
1982  if (!g_hash_table_remove (priv->splits_hash, s))
1983  return false;
1984 
1985  // shortcut pruning the last element. this is the most common
1986  // remove_split operation during UI or book shutdown.
1987  if (s == priv->splits.back())
1988  priv->splits.pop_back();
1989  else
1990  priv->splits.erase (std::remove (priv->splits.begin(), priv->splits.end(), s),
1991  priv->splits.end());
1992 
1993  //FIXME: find better event type
1994  qof_event_gen(&acc->inst, QOF_EVENT_MODIFY, nullptr);
1995  // And send the account-based event, too
1996  qof_event_gen(&acc->inst, GNC_EVENT_ITEM_REMOVED, s);
1997 
1998  priv->balance_dirty = TRUE;
2000  return TRUE;
2001 }
void xaccAccountRecomputeBalance(Account *acc)
The following recompute the partial balances (stored with the transaction) and the total balance...
Definition: Account.cpp:2275
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:231

◆ gnc_account_set_balance_dirty()

void gnc_account_set_balance_dirty ( Account acc)

Tell the account that the running balances may be incorrect and need to be recomputed.

Parameters
accSet the flag on this account.

Definition at line 1898 of file Account.cpp.

1899 {
1900  AccountPrivate *priv;
1901 
1902  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1903 
1904  if (qof_instance_get_destroying(acc))
1905  return;
1906 
1907  priv = GET_PRIVATE(acc);
1908  priv->balance_dirty = TRUE;
1909 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.

◆ gnc_account_set_defer_bal_computation()

void gnc_account_set_defer_bal_computation ( Account acc,
gboolean  defer 
)

Set the defer balance flag.

If defer is true, the account balance is not automatically computed, which can save a lot of time if multiple operations have to be done on the same account. If defer is false, further operations on account will cause the balance to be recomputed as normal.

Parameters
accSet the flag on this account.
deferNew value for the flag.

Definition at line 1911 of file Account.cpp.

1912 {
1913  AccountPrivate *priv;
1914 
1915  g_return_if_fail (GNC_IS_ACCOUNT (acc));
1916 
1917  if (qof_instance_get_destroying (acc))
1918  return;
1919 
1920  priv = GET_PRIVATE (acc);
1921  priv->defer_bal_computation = defer;
1922 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.

◆ gnc_account_set_sort_dirty()

void gnc_account_set_sort_dirty ( Account acc)

Tell the account believes that the splits may be incorrectly sorted and need to be resorted.

Parameters
accSet the flag on this account.

Definition at line 1884 of file Account.cpp.

1885 {
1886  AccountPrivate *priv;
1887 
1888  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1889 
1890  if (qof_instance_get_destroying(acc))
1891  return;
1892 
1893  priv = GET_PRIVATE(acc);
1894  priv->sort_dirty = TRUE;
1895 }
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.

◆ gnc_account_set_start_balance()

void gnc_account_set_start_balance ( Account acc,
const gnc_numeric  start_baln 
)

This function will set the starting commodity balance for this account.

This routine is intended for use with backends that do not return the complete list of splits for an account, but rather return a partial list. In such a case, the backend will typically return all of the splits after some certain date, and the 'starting balance' will represent the summation of the splits up to that date.

Definition at line 3429 of file Account.cpp.

3430 {
3431  AccountPrivate *priv;
3432 
3433  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3434 
3435  priv = GET_PRIVATE(acc);
3436  priv->starting_balance = start_baln;
3437  priv->balance_dirty = TRUE;
3438 }

◆ gnc_account_set_start_cleared_balance()

void gnc_account_set_start_cleared_balance ( Account acc,
const gnc_numeric  start_baln 
)

This function will set the starting cleared commodity balance for this account.

This routine is intended for use with backends that do not return the complete list of splits for an account, but rather return a partial list. In such a case, the backend will typically return all of the splits after some certain date, and the 'starting balance' will represent the summation of the splits up to that date.

Definition at line 3441 of file Account.cpp.

3443 {
3444  AccountPrivate *priv;
3445 
3446  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3447 
3448  priv = GET_PRIVATE(acc);
3449  priv->starting_cleared_balance = start_baln;
3450  priv->balance_dirty = TRUE;
3451 }

◆ gnc_account_set_start_reconciled_balance()

void gnc_account_set_start_reconciled_balance ( Account acc,
const gnc_numeric  start_baln 
)

This function will set the starting reconciled commodity balance for this account.

This routine is intended for use with backends that do not return the complete list of splits for an account, but rather return a partial list. In such a case, the backend will typically return all of the splits after some certain date, and the 'starting balance' will represent the summation of the splits up to that date.

Definition at line 3454 of file Account.cpp.

3456 {
3457  AccountPrivate *priv;
3458 
3459  g_return_if_fail(GNC_IS_ACCOUNT(acc));
3460 
3461  priv = GET_PRIVATE(acc);
3462  priv->starting_reconciled_balance = start_baln;
3463  priv->balance_dirty = TRUE;
3464 }

◆ gnc_get_account_separator_string()

const gchar* gnc_get_account_separator_string ( void  )

Returns the account separation character chosen by the user.

Returns
The character to use.

Definition at line 205 of file Account.cpp.

206 {
207  return account_separator;
208 }

◆ xaccAccountBeginEdit()

void xaccAccountBeginEdit ( Account account)

The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account updates.

Definition at line 1475 of file Account.cpp.

1476 {
1477  g_return_if_fail(acc);
1478  qof_begin_edit(&acc->inst);
1479 }
gboolean qof_begin_edit(QofInstance *inst)
begin_edit

◆ xaccAccountCommitEdit()

void xaccAccountCommitEdit ( Account account)

ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account updates.

Definition at line 1516 of file Account.cpp.

1517 {
1518  AccountPrivate *priv;
1519  QofBook *book;
1520 
1521  g_return_if_fail(acc);
1522  if (!qof_commit_edit(&acc->inst)) return;
1523 
1524  /* If marked for deletion, get rid of subaccounts first,
1525  * and then the splits ... */
1526  priv = GET_PRIVATE(acc);
1527  if (qof_instance_get_destroying(acc))
1528  {
1529  QofCollection *col;
1530 
1531  qof_instance_increase_editlevel(acc);
1532 
1533  /* First, recursively free children */
1534  xaccFreeAccountChildren(acc);
1535 
1536  PINFO ("freeing splits for account %p (%s)",
1537  acc, priv->accountName ? priv->accountName : "(null)");
1538 
1539  book = qof_instance_get_book(acc);
1540 
1541  /* If book is shutting down, just clear the split list. The splits
1542  themselves will be destroyed by the transaction code */
1543  if (!qof_book_shutting_down(book))
1544  {
1545  // We need to delete in reverse order so that the vector's iterators aren't invalidated.
1546  for_each(priv->splits.rbegin(), priv->splits.rend(), [](Split *s) {
1547  xaccSplitDestroy (s); });
1548  }
1549  else
1550  {
1551  priv->splits.clear();
1552  g_hash_table_remove_all (priv->splits_hash);
1553  }
1554 
1555  /* It turns out there's a case where this assertion does not hold:
1556  When the user tries to delete an Imbalance account, while also
1557  deleting all the splits in it. The splits will just get
1558  recreated and put right back into the same account!
1559 
1560  g_assert(priv->splits == nullptr || qof_book_shutting_down(acc->inst.book));
1561  */
1562 
1563  if (!qof_book_shutting_down(book))
1564  {
1565  col = qof_book_get_collection(book, GNC_ID_TRANS);
1566  qof_collection_foreach(col, destroy_pending_splits_for_account, acc);
1567 
1568  /* the lots should be empty by now */
1569  for (auto lp = priv->lots; lp; lp = lp->next)
1570  {
1571  GNCLot *lot = static_cast<GNCLot*>(lp->data);
1572  gnc_lot_destroy (lot);
1573  }
1574  }
1575  g_list_free(priv->lots);
1576  priv->lots = nullptr;
1577 
1578  qof_instance_set_dirty(&acc->inst);
1579  qof_instance_decrease_editlevel(acc);
1580  }
1581  else
1582  {
1583  xaccAccountBringUpToDate(acc);
1584  }
1585 
1586  qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free);
1587 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
gboolean xaccSplitDestroy(Split *split)
Destructor.
Definition: Split.cpp:1506
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
QofBook reference.
Definition: qofbook-p.hpp:46
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521
gboolean qof_book_shutting_down(const QofBook *book)
Is the book shutting down?
Definition: qofbook.cpp:447

◆ xaccAccountDestroy()

void xaccAccountDestroy ( Account account)

The xaccAccountDestroy() routine can be used to get rid of an account.

The account should have been opened for editing (by calling xaccAccountBeginEdit()) before calling this routine.

Definition at line 1590 of file Account.cpp.

1591 {
1592  g_return_if_fail(GNC_IS_ACCOUNT(acc));
1593 
1594  qof_instance_set_destroying(acc, TRUE);
1595 
1596  xaccAccountCommitEdit (acc);
1597 }
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1516

◆ xaccAccountEqual()

gboolean xaccAccountEqual ( const Account a,
const Account b,
gboolean  check_guids 
)

Compare two accounts for equality - this is a deep compare.

Definition at line 1666 of file Account.cpp.

1667 {
1668  AccountPrivate *priv_aa, *priv_ab;
1669 
1670  if (!aa && !ab) return TRUE;
1671 
1672  g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
1673  g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
1674 
1675  priv_aa = GET_PRIVATE(aa);
1676  priv_ab = GET_PRIVATE(ab);
1677  if (priv_aa->type != priv_ab->type)
1678  {
1679  PWARN ("types differ: %d vs %d", priv_aa->type, priv_ab->type);
1680  return FALSE;
1681  }
1682 
1683  if (g_strcmp0(priv_aa->accountName, priv_ab->accountName) != 0)
1684  {
1685  PWARN ("names differ: %s vs %s", priv_aa->accountName, priv_ab->accountName);
1686  return FALSE;
1687  }
1688 
1689  if (g_strcmp0(priv_aa->accountCode, priv_ab->accountCode) != 0)
1690  {
1691  PWARN ("codes differ: %s vs %s", priv_aa->accountCode, priv_ab->accountCode);
1692  return FALSE;
1693  }
1694 
1695  if (g_strcmp0(priv_aa->description, priv_ab->description) != 0)
1696  {
1697  PWARN ("descriptions differ: %s vs %s", priv_aa->description, priv_ab->description);
1698  return FALSE;
1699  }
1700 
1701  if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
1702  {
1703  PWARN ("commodities differ");
1704  return FALSE;
1705  }
1706 
1707  if (check_guids)
1708  {
1709  if (qof_instance_guid_compare(aa, ab) != 0)
1710  {
1711  PWARN ("GUIDs differ");
1712  return FALSE;
1713  }
1714  }
1715 
1716  if (qof_instance_compare_kvp (QOF_INSTANCE (aa), QOF_INSTANCE (ab)) != 0)
1717  {
1718  char *frame_a;
1719  char *frame_b;
1720 
1721  frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (aa));
1722  frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (ab));
1723 
1724  PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
1725 
1726  g_free (frame_a);
1727  g_free (frame_b);
1728 
1729  return FALSE;
1730  }
1731 
1732  if (!gnc_numeric_equal(priv_aa->starting_balance, priv_ab->starting_balance))
1733  {
1734  char *str_a;
1735  char *str_b;
1736 
1737  str_a = gnc_numeric_to_string(priv_aa->starting_balance);
1738  str_b = gnc_numeric_to_string(priv_ab->starting_balance);
1739 
1740  PWARN ("starting balances differ: %s vs %s", str_a, str_b);
1741 
1742  g_free (str_a);
1743  g_free (str_b);
1744 
1745  return FALSE;
1746  }
1747 
1748  if (!gnc_numeric_equal(priv_aa->starting_noclosing_balance,
1749  priv_ab->starting_noclosing_balance))
1750  {
1751  char *str_a;
1752  char *str_b;
1753 
1754  str_a = gnc_numeric_to_string(priv_aa->starting_noclosing_balance);
1755  str_b = gnc_numeric_to_string(priv_ab->starting_noclosing_balance);
1756 
1757  PWARN ("starting noclosing balances differ: %s vs %s", str_a, str_b);
1758 
1759  g_free (str_a);
1760  g_free (str_b);
1761 
1762  return FALSE;
1763  }
1764  if (!gnc_numeric_equal(priv_aa->starting_cleared_balance,
1765  priv_ab->starting_cleared_balance))
1766  {
1767  char *str_a;
1768  char *str_b;
1769 
1770  str_a = gnc_numeric_to_string(priv_aa->starting_cleared_balance);
1771  str_b = gnc_numeric_to_string(priv_ab->starting_cleared_balance);
1772 
1773  PWARN ("starting cleared balances differ: %s vs %s", str_a, str_b);
1774 
1775  g_free (str_a);
1776  g_free (str_b);
1777 
1778  return FALSE;
1779  }
1780 
1781  if (!gnc_numeric_equal(priv_aa->starting_reconciled_balance,
1782  priv_ab->starting_reconciled_balance))
1783  {
1784  char *str_a;
1785  char *str_b;
1786 
1787  str_a = gnc_numeric_to_string(priv_aa->starting_reconciled_balance);
1788  str_b = gnc_numeric_to_string(priv_ab->starting_reconciled_balance);
1789 
1790  PWARN ("starting reconciled balances differ: %s vs %s", str_a, str_b);
1791 
1792  g_free (str_a);
1793  g_free (str_b);
1794 
1795  return FALSE;
1796  }
1797 
1798  if (!gnc_numeric_equal(priv_aa->balance, priv_ab->balance))
1799  {
1800  char *str_a;
1801  char *str_b;
1802 
1803  str_a = gnc_numeric_to_string(priv_aa->balance);
1804  str_b = gnc_numeric_to_string(priv_ab->balance);
1805 
1806  PWARN ("balances differ: %s vs %s", str_a, str_b);
1807 
1808  g_free (str_a);
1809  g_free (str_b);
1810 
1811  return FALSE;
1812  }
1813 
1814  if (!gnc_numeric_equal(priv_aa->noclosing_balance, priv_ab->noclosing_balance))
1815  {
1816  char *str_a;
1817  char *str_b;
1818 
1819  str_a = gnc_numeric_to_string(priv_aa->noclosing_balance);
1820  str_b = gnc_numeric_to_string(priv_ab->noclosing_balance);
1821 
1822  PWARN ("noclosing balances differ: %s vs %s", str_a, str_b);
1823 
1824  g_free (str_a);
1825  g_free (str_b);
1826 
1827  return FALSE;
1828  }
1829  if (!gnc_numeric_equal(priv_aa->cleared_balance, priv_ab->cleared_balance))
1830  {
1831  char *str_a;
1832  char *str_b;
1833 
1834  str_a = gnc_numeric_to_string(priv_aa->cleared_balance);
1835  str_b = gnc_numeric_to_string(priv_ab->cleared_balance);
1836 
1837  PWARN ("cleared balances differ: %s vs %s", str_a, str_b);
1838 
1839  g_free (str_a);
1840  g_free (str_b);
1841 
1842  return FALSE;
1843  }
1844 
1845  if (!gnc_numeric_equal(priv_aa->reconciled_balance, priv_ab->reconciled_balance))
1846  {
1847  char *str_a;
1848  char *str_b;
1849 
1850  str_a = gnc_numeric_to_string(priv_aa->reconciled_balance);
1851  str_b = gnc_numeric_to_string(priv_ab->reconciled_balance);
1852 
1853  PWARN ("reconciled balances differ: %s vs %s", str_a, str_b);
1854 
1855  g_free (str_a);
1856  g_free (str_b);
1857 
1858  return FALSE;
1859  }
1860 
1861  /* no parent; always compare downwards. */
1862 
1863  if (!std::equal (priv_aa->splits.begin(), priv_aa->splits.end(),
1864  priv_ab->splits.begin(), priv_ab->splits.end(),
1865  [check_guids](auto sa, auto sb)
1866  { return xaccSplitEqual(sa, sb, check_guids, true, false); }))
1867  {
1868  PWARN ("splits differ");
1869  return false;
1870  }
1871 
1872  if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
1873  {
1874  PWARN ("children differ");
1875  return FALSE;
1876  }
1877 
1878  return(TRUE);
1879 }
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
Definition: Split.cpp:819
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.

◆ xaccAccountGainsAccount()

Account* xaccAccountGainsAccount ( Account acc,
gnc_commodity *  curr 
)

Retrieve the gains account used by this account for the indicated currency, creating and recording a new one if necessary.

FIXME: There is at present no interface to designate an existing account, and the new account name is hard coded to "Orphaned Gains -- CUR"

FIXME: There is no provision for creating separate accounts for anything other than currency, e.g. holding period of a security.

Definition at line 4817 of file Account.cpp.

4818 {
4819  Path path {KEY_LOT_MGMT, "gains-acct", gnc_commodity_get_unique_name (curr)};
4820  auto gains_account = get_kvp_account_path (acc, path);
4821 
4822  if (gains_account == nullptr) /* No gains account for this currency */
4823  {
4824  gains_account = GetOrMakeOrphanAccount (gnc_account_get_root (acc), curr);
4825  set_kvp_account_path (acc, path, gains_account);
4826  }
4827 
4828  return gains_account;
4829 }
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the &#39;unique&#39; name for the specified commodity.
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to...
Definition: Account.cpp:2942

◆ xaccAccountGetAssociatedAccount()

Account* xaccAccountGetAssociatedAccount ( const Account acc,
const char *  tag 
)

Get the account's associated account e.g.

stock account -> dividend account

Definition at line 3387 of file Account.cpp.

3388 {
3389  g_return_val_if_fail (tag && *tag, nullptr);
3390 
3391  return get_kvp_account_path (acc, {"associated-account", tag});
3392 }

◆ xaccAccountGetBalanceAsOfDate()

gnc_numeric xaccAccountGetBalanceAsOfDate ( Account account,
time64  date 
)

Get the balance of the account at the end of the day before the date specified.

Definition at line 3533 of file Account.cpp.

3534 {
3535  return GetBalanceAsOfDate (acc, date, xaccSplitGetBalance);
3536 }
gnc_numeric xaccSplitGetBalance(const Split *s)
Returns the running balance up to and including the indicated split.
Definition: Split.cpp:1316

◆ xaccAccountGetBalanceAsOfDateInCurrency()

gnc_numeric xaccAccountGetBalanceAsOfDateInCurrency ( Account account,
time64  date,
gnc_commodity *  report_commodity,
gboolean  include_children 
)

This function gets the balance at the end of the given date in the desired commodity.

Definition at line 3851 of file Account.cpp.

3854 {
3855  return xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive (
3856  acc, date, xaccAccountGetBalanceAsOfDate, report_commodity,
3857  include_children);
3858 }
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
Get the balance of the account at the end of the day before the date specified.
Definition: Account.cpp:3533

◆ xaccAccountGetCommoditySCU()

int xaccAccountGetCommoditySCU ( const Account account)

Return the SCU for the account.

If a non-standard SCU has been set for the account, that is returned; else the default SCU for the account commodity is returned.

Definition at line 2745 of file Account.cpp.

2746 {
2747  AccountPrivate *priv;
2748 
2749  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2750 
2751  priv = GET_PRIVATE(acc);
2752  if (priv->non_standard_scu || !priv->commodity)
2753  return priv->commodity_scu;
2754  return gnc_commodity_get_fraction(priv->commodity);
2755 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.

◆ xaccAccountGetCommoditySCUi()

int xaccAccountGetCommoditySCUi ( const Account account)

Return the 'internal' SCU setting.

This returns the over-ride SCU for the account (which might not be set, and might be zero).

Definition at line 2738 of file Account.cpp.

2739 {
2740  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2741  return GET_PRIVATE(acc)->commodity_scu;
2742 }

◆ xaccAccountGetNoclosingBalanceAsOfDateInCurrency()

gnc_numeric xaccAccountGetNoclosingBalanceAsOfDateInCurrency ( Account acc,
time64  date,
gnc_commodity *  report_commodity,
gboolean  include_children 
)

This function gets the balance at the end of the given date, ignoring closing entries, in the desired commodity.

Definition at line 3861 of file Account.cpp.

3864 {
3865  return xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive
3866  (acc, date, xaccAccountGetNoclosingBalanceAsOfDate,
3867  report_commodity, include_children);
3868 }

◆ xaccAccountGetNonStdSCU()

gboolean xaccAccountGetNonStdSCU ( const Account account)

Return boolean, indicating whether this account uses a non-standard SCU.

Definition at line 2774 of file Account.cpp.

2775 {
2776  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
2777  return GET_PRIVATE(acc)->non_standard_scu;
2778 }

◆ xaccAccountGetOnlineID()

const char* xaccAccountGetOnlineID ( const Account account)

Get the account's online_id (see xaccAccountSetOnlineID).

The returned string is owned by the account and must NOT be freed; returns NULL if no online_id is set.

Definition at line 3380 of file Account.cpp.

3381 {
3382  g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr);
3383  return get_kvp_string_path (acc, {KEY_ONLINE_ID});
3384 }

◆ xaccAccountGetReconciledBalanceAsOfDate()

gnc_numeric xaccAccountGetReconciledBalanceAsOfDate ( Account account,
time64  date 
)

Get the reconciled balance of the account at the end of the day of the date specified.

Definition at line 3545 of file Account.cpp.

3546 {
3547  return GetBalanceAsOfDate (acc, date, xaccSplitGetReconciledBalance);
3548 }
gnc_numeric xaccSplitGetReconciledBalance(const Split *s)
Returns the reconciled-balance of this split.
Definition: Split.cpp:1334

◆ xaccAccountGetType()

GNCAccountType xaccAccountGetType ( const Account account)

Returns the account's account type.

This must not be confused with the GType as returned by gnc_account_get_type(), which is related to glib's type system.

Definition at line 3267 of file Account.cpp.

3268 {
3269  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), ACCT_TYPE_NONE);
3270  return GET_PRIVATE(acc)->type;
3271 }
Not a type.
Definition: Account.h:105

◆ xaccAccountHasAncestor()

gboolean xaccAccountHasAncestor ( const Account acc,
const Account ancestor 
)

Returns true if the account is 'ancestor' or has 'ancestor' as an ancestor.

An ancestor account may be the accounts parent, its parent's parent, its parent's parent's parent, etc. Returns false if either one is NULL.

Definition at line 4224 of file Account.cpp.

4225 {
4226  const Account *parent;
4227 
4228  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4229  g_return_val_if_fail(GNC_IS_ACCOUNT(ancestor), FALSE);
4230 
4231  parent = acc;
4232  while (parent && parent != ancestor)
4233  parent = GET_PRIVATE(parent)->parent;
4234 
4235  return (parent == ancestor);
4236 }
STRUCTS.

◆ xaccAccountHasStockSplit()

gboolean xaccAccountHasStockSplit ( const Account acc)

Returns true if the account has a stock split, otherwise false.

Definition at line 3507 of file Account.cpp.

3508 {
3509  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), false);
3510  return GET_PRIVATE(acc)->has_stock_split;
3511 }

◆ xaccAccountIsPriced()

gboolean xaccAccountIsPriced ( const Account acc)

Returns true if the account is a stock, mutual fund or currency, otherwise false.

Definition at line 4551 of file Account.cpp.

4552 {
4553  AccountPrivate *priv;
4554 
4555  g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
4556 
4557  priv = GET_PRIVATE(acc);
4558  return (priv->type == ACCT_TYPE_STOCK || priv->type == ACCT_TYPE_MUTUAL ||
4559  priv->type == ACCT_TYPE_CURRENCY);
4560 }
Mutual Fund accounts will typically be shown in registers which show three columns: price...
Definition: Account.h:125
Stock accounts will typically be shown in registers which show three columns: price, number of shares, and value.
Definition: Account.h:122
The currency account type indicates that the account is a currency trading account.
Definition: Account.h:129

◆ xaccAccountLookup()

Account* xaccAccountLookup ( const GncGUID guid,
QofBook book 
)

The xaccAccountLookup() subroutine will return the account associated with the given id, or NULL if there is no such account.

Definition at line 2050 of file Account.cpp.

2051 {
2052  QofCollection *col;
2053  if (!guid || !book) return nullptr;
2054  col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
2055  return (Account *) qof_collection_lookup_entity (col, guid);
2056 }
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition: qofid.cpp:209
STRUCTS.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521

◆ xaccAccountOrder()

int xaccAccountOrder ( const Account account_1,
const Account account_2 
)

The xaccAccountOrder() subroutine defines a sorting order on accounts.

It takes pointers to two accounts, and returns an int < 0 if the first account is "less than" the second, returns an int > 0 if the first is "greater than" the second, and 0 if they are equal. To determine the sort order, first the account codes are compared, and if these are equal, then account types, then account names. If still equal, it compares GUID to ensure that there aren't any ties.

Definition at line 2375 of file Account.cpp.

2376 {
2377  AccountPrivate *priv_aa, *priv_ab;
2378  const char *da, *db;
2379  int ta, tb, result;
2380 
2381  if (aa == ab) return 0;
2382  if (!ab) return -1;
2383  if (!aa) return +1;
2384 
2385  priv_aa = GET_PRIVATE(aa);
2386  priv_ab = GET_PRIVATE(ab);
2387 
2388  /* sort on accountCode strings */
2389  da = priv_aa->accountCode;
2390  db = priv_ab->accountCode;
2391 
2392  /* Otherwise do a string sort */
2393  result = g_strcmp0 (da, db);
2394  if (result)
2395  return result;
2396 
2397  /* if account-type-order array not initialized, initialize it */
2398  /* this will happen at most once during program invocation */
2399  if (-1 == revorder[0])
2400  {
2401  int i;
2402  for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
2403  {
2404  revorder [typeorder[i]] = i;
2405  }
2406  }
2407 
2408  /* otherwise, sort on account type */
2409  ta = priv_aa->type;
2410  tb = priv_ab->type;
2411  ta = revorder[ta];
2412  tb = revorder[tb];
2413  if (ta < tb) return -1;
2414  if (ta > tb) return +1;
2415 
2416  /* otherwise, sort on accountName strings */
2417  da = priv_aa->accountName;
2418  db = priv_ab->accountName;
2419  result = safe_utf8_collate(da, db);
2420  if (result)
2421  return result;
2422 
2423  /* guarantee a stable sort */
2424  return qof_instance_guid_compare(aa, ab);
2425 }
int safe_utf8_collate(const char *da, const char *db)
Collate two UTF-8 strings.
stop here; the following types just aren&#39;t ready for prime time
Definition: Account.h:161
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.

◆ xaccAccountSetAssociatedAccount()

void xaccAccountSetAssociatedAccount ( Account acc,
const char *  tag,
const Account assoc_acct 
)

Set the account's associated account e.g.

stock account -> dividend account

Definition at line 2669 of file Account.cpp.

2670 {
2671  g_return_if_fail (GNC_IS_ACCOUNT(acc));
2672  g_return_if_fail (tag && *tag);
2673 
2674  set_kvp_account_path (acc, {"associated-account", tag}, assoc_acct);
2675 }

◆ xaccAccountSetCommoditySCU()

void xaccAccountSetCommoditySCU ( Account account,
int  frac 
)

Set the SCU for the account.

Normally, this routine is not required, as the default SCU for an account is given by its commodity.

Definition at line 2722 of file Account.cpp.

2723 {
2724  AccountPrivate *priv;
2725 
2726  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2727 
2728  priv = GET_PRIVATE(acc);
2729  xaccAccountBeginEdit(acc);
2730  priv->commodity_scu = scu;
2731  if (scu != gnc_commodity_get_fraction(priv->commodity))
2732  priv->non_standard_scu = TRUE;
2733  mark_account(acc);
2734  xaccAccountCommitEdit(acc);
2735 }
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1475
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1516

◆ xaccAccountSetNonStdSCU()

void xaccAccountSetNonStdSCU ( Account account,
gboolean  flag 
)

Set the flag indicating that this account uses a non-standard SCU.

Definition at line 2758 of file Account.cpp.

2759 {
2760  AccountPrivate *priv;
2761 
2762  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2763 
2764  priv = GET_PRIVATE(acc);
2765  if (priv->non_standard_scu == flag)
2766  return;
2767  xaccAccountBeginEdit(acc);
2768  priv->non_standard_scu = flag;
2769  mark_account (acc);
2770  xaccAccountCommitEdit(acc);
2771 }
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1475
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1516

◆ xaccAccountSetOnlineID()

void xaccAccountSetOnlineID ( Account account,
const char *  id 
)

Set the account's online_id, the identifier (e.g.

an OFX/HBCI BANKID+ACCTID composite) of the online account this GnuCash account is mapped to for bank imports. This is the same value (engine KVP slot "online_id") that the desktop OFX/HBCI importer uses to match a downloaded statement to its GnuCash account. Passing NULL or "" clears it. Wraps its own begin/commit edit.

Definition at line 2661 of file Account.cpp.

2662 {
2663  g_return_if_fail (GNC_IS_ACCOUNT(acc));
2664  set_kvp_string_path (acc, {KEY_ONLINE_ID}, id);
2665 }

◆ xaccAccountSortSplits()

void xaccAccountSortSplits ( Account acc,
gboolean  force 
)

The xaccAccountSortSplits() routine will resort the account's splits if the sort is dirty.

If 'force' is true, the account is sorted even if the editlevel is not zero.

Definition at line 2004 of file Account.cpp.

2005 {
2006  AccountPrivate *priv;
2007 
2008  g_return_if_fail(GNC_IS_ACCOUNT(acc));
2009 
2010  priv = GET_PRIVATE(acc);
2011  if (!priv->sort_dirty || (!force && qof_instance_get_editlevel(acc) > 0))
2012  return;
2013  std::sort (priv->splits.begin(), priv->splits.end(), split_cmp_less);
2014  priv->sort_dirty = FALSE;
2015  priv->balance_dirty = TRUE;
2016 }

◆ xaccCloneAccount()

Account* xaccCloneAccount ( const Account source,
QofBook book 
)

The xaccCloneAccount() routine makes a simple copy of the indicated account, placing it in the indicated book.

It copies the account type, name, description, and the kvp values; it does not copy splits/transactions. The book should have a commodity table in it that has commodities with the same unique name as the ones being copied in the account (the commodities in the clone will be those from the book).

Definition at line 1301 of file Account.cpp.

1302 {
1303  Account *ret;
1304  AccountPrivate *from_priv, *priv;
1305 
1306  g_return_val_if_fail(GNC_IS_ACCOUNT(from), nullptr);
1307  g_return_val_if_fail(QOF_IS_BOOK(book), nullptr);
1308 
1309  ENTER (" ");
1310  ret = static_cast<Account*>(g_object_new (GNC_TYPE_ACCOUNT, nullptr));
1311  g_return_val_if_fail (ret, nullptr);
1312 
1313  from_priv = GET_PRIVATE(from);
1314  priv = GET_PRIVATE(ret);
1315  xaccInitAccount (ret, book);
1316 
1317  /* Do not Begin/CommitEdit() here; give the caller
1318  * a chance to fix things up, and let them do it.
1319  * Also let caller issue the generate_event (EVENT_CREATE) */
1320  priv->type = from_priv->type;
1321 
1322  priv->accountName = qof_string_cache_replace(priv->accountName, from_priv->accountName);
1323  priv->accountCode = qof_string_cache_replace(priv->accountCode, from_priv->accountCode);
1324  priv->description = qof_string_cache_replace(priv->description, from_priv->description);
1325 
1326  qof_instance_copy_kvp (QOF_INSTANCE (ret), QOF_INSTANCE (from));
1327 
1328  /* The new book should contain a commodity that matches
1329  * the one in the old book. Find it, use it. */
1330  priv->commodity = gnc_commodity_obtain_twin(from_priv->commodity, book);
1331  gnc_commodity_increment_usage_count(priv->commodity);
1332 
1333  priv->commodity_scu = from_priv->commodity_scu;
1334  priv->non_standard_scu = from_priv->non_standard_scu;
1335 
1336  qof_instance_set_dirty(&ret->inst);
1337  LEAVE (" ");
1338  return ret;
1339 }
const char * qof_string_cache_replace(char const *dst, char const *src)
Same as CACHE_REPLACE below, but safe to call from C++.
STRUCTS.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
Increment a commodity&#39;s internal counter that tracks how many accounts are using that commodity...
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
gnc_commodity * gnc_commodity_obtain_twin(const gnc_commodity *from, QofBook *book)
Given the commodity &#39;findlike&#39;, this routine will find and return the equivalent commodity (commodity...