mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-08-26 05:07:21 -05:00
[account.cpp] add more account metadata - assoc account
the tag denotes the type of associated account eg. "dividend" "capgains" "cash" "fees"
This commit is contained in:
@@ -2579,6 +2579,34 @@ xaccAccountSetNotes (Account *acc, const char *str)
|
||||
set_kvp_string_tag (acc, "notes", str);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
xaccAccountSetAssociatedAccount (Account *acc, const char *tag, const Account* assoc_acct)
|
||||
{
|
||||
g_return_if_fail (GNC_IS_ACCOUNT(acc));
|
||||
g_return_if_fail (tag && *tag);
|
||||
|
||||
std::vector<std::string> path = { "associated-account", tag };
|
||||
xaccAccountBeginEdit(acc);
|
||||
|
||||
PINFO ("setting %s assoc %s account = %s", xaccAccountGetName (acc), tag,
|
||||
assoc_acct ? xaccAccountGetName (assoc_acct) : nullptr);
|
||||
|
||||
if (GNC_IS_ACCOUNT(assoc_acct))
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_value_init (&v, GNC_TYPE_GUID);
|
||||
g_value_set_static_boxed (&v, xaccAccountGetGUID (assoc_acct));
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path);
|
||||
g_value_unset (&v);
|
||||
}
|
||||
else
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, path);
|
||||
|
||||
mark_account (acc);
|
||||
xaccAccountCommitEdit(acc);
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetCommodity (Account * acc, gnc_commodity * com)
|
||||
{
|
||||
@@ -3367,6 +3395,28 @@ xaccAccountGetNotes (const Account *acc)
|
||||
return rv;
|
||||
}
|
||||
|
||||
Account*
|
||||
xaccAccountGetAssociatedAccount (const Account *acc, const char *tag)
|
||||
{
|
||||
g_return_val_if_fail (GNC_IS_ACCOUNT(acc), nullptr);
|
||||
g_return_val_if_fail (tag && *tag, nullptr);
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, { "associated-account", tag });
|
||||
|
||||
auto guid = static_cast<GncGUID*>(G_VALUE_HOLDS_BOXED (&v) ? g_value_get_boxed(&v) : nullptr);
|
||||
g_value_unset (&v);
|
||||
|
||||
if (!guid)
|
||||
return nullptr;
|
||||
|
||||
auto assoc_acct = xaccAccountLookup (guid, gnc_account_get_book (acc));
|
||||
PINFO ("retuning %s assoc %s account = %s", xaccAccountGetName (acc), tag,
|
||||
xaccAccountGetName (assoc_acct));
|
||||
return assoc_acct;
|
||||
}
|
||||
|
||||
|
||||
gnc_commodity *
|
||||
DxaccAccountGetCurrency (const Account *acc)
|
||||
{
|
||||
|
||||
@@ -312,6 +312,11 @@ typedef enum
|
||||
void xaccAccountSetSortReversed (Account *account, gboolean sortreversed);
|
||||
/** Set the account's notes */
|
||||
void xaccAccountSetNotes (Account *account, const char *notes);
|
||||
|
||||
/** Set the account's associated account e.g. stock account -> dividend account */
|
||||
void xaccAccountSetAssociatedAccount (Account *acc, const char *tag,
|
||||
const Account *assoc_acct);
|
||||
|
||||
/** Set the last num field of an Account */
|
||||
void xaccAccountSetLastNum (Account *account, const char *num);
|
||||
/** Set the account's lot order policy */
|
||||
@@ -416,6 +421,9 @@ typedef enum
|
||||
gboolean xaccAccountGetSortReversed (const Account *account);
|
||||
/** Get the account's notes */
|
||||
const char * xaccAccountGetNotes (const Account *account);
|
||||
|
||||
/** Get the account's associated account e.g. stock account -> dividend account */
|
||||
Account* xaccAccountGetAssociatedAccount (const Account *acc, const char *tag);
|
||||
/** Get the last num field of an Account */
|
||||
const char * xaccAccountGetLastNum (const Account *account);
|
||||
/** Get the account's lot order policy */
|
||||
|
||||
@@ -1237,6 +1237,25 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
xaccAccountSetNotes (account, nullptr);
|
||||
g_assert_cmpstr (xaccAccountGetNotes (account), ==, nullptr);
|
||||
|
||||
// Associated Account getter/setter
|
||||
g_assert_null (xaccAccountGetAssociatedAccount (account, "test"));
|
||||
|
||||
g_test_expect_message ("gnc.engine", G_LOG_LEVEL_CRITICAL,
|
||||
"*xaccAccountSetAssociatedAccount*assertion*tag && *tag*");
|
||||
xaccAccountSetAssociatedAccount (account, nullptr, account);
|
||||
g_test_assert_expected_messages();
|
||||
|
||||
g_test_expect_message ("gnc.engine", G_LOG_LEVEL_CRITICAL,
|
||||
"*xaccAccountSetAssociatedAccount*assertion*GNC_IS_ACCOUNT(acc)*");
|
||||
xaccAccountSetAssociatedAccount (nullptr, "test", account);
|
||||
g_test_assert_expected_messages();
|
||||
|
||||
xaccAccountSetAssociatedAccount (account, "test", account);
|
||||
g_assert_true (xaccAccountGetAssociatedAccount (account, "test") == account);
|
||||
|
||||
xaccAccountSetAssociatedAccount (account, "test", nullptr);
|
||||
g_assert_null (xaccAccountGetAssociatedAccount (account, "test"));
|
||||
|
||||
// Balance Limits getter/setter
|
||||
g_assert_true (xaccAccountGetHigherBalanceLimit (account, &balance_limit) == false);
|
||||
g_assert_true (xaccAccountGetLowerBalanceLimit (account, &balance_limit) == false);
|
||||
|
||||
Reference in New Issue
Block a user