mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add routine to find clones of accounts in different books
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6049 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
9b87639c5b
commit
9cc5dcce25
@ -250,6 +250,49 @@ gemini (kvp_frame *kvp_root, const GUID *acct_guid,
|
||||
kvp_frame_set_slot_nc (cwd, "date", vvv);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
Account *
|
||||
xaccAccountLookupTwin (Account *acc, GNCBook *book)
|
||||
{
|
||||
kvp_value *v_ncopies;
|
||||
int i, ncopies = 0;
|
||||
|
||||
if (!acc || !book) return NULL;
|
||||
|
||||
v_ncopies = kvp_frame_get_slot_path (acc->kvp_data, "gemini", "ncopies");
|
||||
if (!v_ncopies) return NULL;
|
||||
ncopies = kvp_value_get_gint64 (v_ncopies);
|
||||
for (i=0; i<ncopies; i++)
|
||||
{
|
||||
GUID * book_guid;
|
||||
kvp_value *v_book_guid;
|
||||
char buff[80];
|
||||
|
||||
sprintf (buff, "%d", i);
|
||||
v_book_guid = kvp_frame_get_slot_path (acc->kvp_data,
|
||||
"gemini", buff, "book_guid");
|
||||
if (!v_book_guid) continue;
|
||||
book_guid = kvp_value_get_guid (v_book_guid);
|
||||
|
||||
if (guid_equal(book_guid, &book->guid))
|
||||
{
|
||||
Account *twin;
|
||||
GUID * acct_guid;
|
||||
kvp_value *v_acct_guid;
|
||||
|
||||
v_acct_guid = kvp_frame_get_slot_path (acc->kvp_data,
|
||||
"gemini", buff, "acct_guid");
|
||||
if (!v_acct_guid) return NULL;
|
||||
acct_guid = kvp_value_get_guid (v_acct_guid);
|
||||
|
||||
twin = xaccAccountLookup (acct_guid, book);
|
||||
return twin;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
@ -147,6 +147,8 @@ void xaccAccountDestroy (Account *account);
|
||||
kvp_frame * xaccAccountGetSlots (Account *account);
|
||||
void xaccAccountSetSlots_nc(Account *account, kvp_frame *frame);
|
||||
|
||||
GNCBook * xaccAccountGetBook (Account *account);
|
||||
|
||||
/* ------------------ */
|
||||
/*
|
||||
* The xaccAccountGetGUID() subroutine will return the
|
||||
@ -165,7 +167,20 @@ GUID xaccAccountReturnGUID (Account *account);
|
||||
Account * xaccAccountLookup (const GUID *guid, GNCBook *book);
|
||||
Account * xaccAccountLookupDirect (GUID guid, GNCBook *book);
|
||||
|
||||
GNCBook * xaccAccountGetBook (Account *account);
|
||||
/* The xaccAccountLookupTwin() routine will find the
|
||||
* "twin" of this account (if it exists) in another book.
|
||||
* When accounts are copied or cloned, both of the pair
|
||||
* are marked with the guid of thier copy, thus allowing
|
||||
* the sibling-copy of an account to be found. Since the
|
||||
* sibling may end up in a different book, we need a way
|
||||
* of finding it, given only that we know the book, and
|
||||
* that we know its twin. That's what this routine does.
|
||||
* Given some book 'book', and an account 'acc', it will
|
||||
* find the sibling account of 'acc' that is in 'book',
|
||||
* and return it. If not found, it returns NULL.
|
||||
* This routine uses the 'gemini' kvp values to do its work.
|
||||
*/
|
||||
Account * xaccAccountLookupTwin (Account *acc, GNCBook *book);
|
||||
|
||||
/* ------------------ */
|
||||
|
||||
|
@ -64,15 +64,20 @@ Use: subdirectory holding identification of the first copied account.
|
||||
Other copies would appear in directories /gemini/1/, /gemini/2/,
|
||||
etc.
|
||||
|
||||
Name: /gemini/0/guid
|
||||
Name: /gemini/0/acct_guid
|
||||
Type: guid
|
||||
Entities: Accounts
|
||||
Use: guid of another account that is a copy of this one.
|
||||
|
||||
Name: /gemini/0/book_guid
|
||||
Type: guid
|
||||
Entities: Accounts
|
||||
Use: guid of the book that the other account belongs to.
|
||||
|
||||
Name: /gemini/0/date
|
||||
Type: timespec
|
||||
Entities: Accounts
|
||||
Use: date that copy was created.
|
||||
Use: date that the copy was created.
|
||||
|
||||
Name: last-num
|
||||
Type: string
|
||||
|
Loading…
Reference in New Issue
Block a user