void xaccAccountScrubCommodity (Account *account) { gnc_commodity *commodity; if (!account) return; if (xaccAccountGetType(account) == ACCT_TYPE_ROOT) return; commodity = xaccAccountGetCommodity (account); if (commodity) return; /* Use the 'obsolete' routines to try to figure out what the * account commodity should have been. */ commodity = xaccAccountGetCommodity (account); if (commodity) { xaccAccountSetCommodity (account, commodity); return; } commodity = DxaccAccountGetCurrency (account); if (commodity) { xaccAccountSetCommodity (account, commodity); return; } PERR ("Account \"%s\" does not have a commodity!", xaccAccountGetName(account)); }
static gboolean test_add_account (const char* tag, gpointer globaldata, gpointer data) { Account* account = static_cast<decltype (account)> (data); act_data* gdata = (act_data*)globaldata; gnc_commodity* com; gnc_commodity* new_com; gnc_commodity_table* t; com = xaccAccountGetCommodity (account); t = gnc_commodity_table_get_table (sixbook); new_com = gnc_commodity_table_lookup (t, gnc_commodity_get_namespace (com), gnc_commodity_get_mnemonic (com)); if (new_com) { xaccAccountSetCommodity (account, new_com); } do_test_args (xaccAccountEqual ((Account*)account, (Account*) (gdata->act), TRUE), "gnc_account_sixtp_parser_create", __FILE__, __LINE__, "%d", gdata->value); return TRUE; }
static void test_generation () { int i; for (i = 0; i < 20; i++) { Account* ran_act; ran_act = get_random_account (sixbook); test_account (i, ran_act); delete_random_account (ran_act); } { /* empty some things. */ Account* act; const char* msg = "xaccAccountSetCommodity: assertion `GNC_IS_COMMODITY(com)' failed"; const char* logdomain = "gnc.engine"; GLogLevelFlags loglevel = static_cast<decltype (loglevel)> (G_LOG_LEVEL_CRITICAL); TestErrorStruct check = { loglevel, const_cast<char*> (logdomain), const_cast<char*> (msg) }; g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); act = get_random_account (sixbook); xaccAccountSetCode (act, ""); xaccAccountSetDescription (act, ""); xaccAccountSetCommodity (act, NULL); test_account (-1, act); delete_random_account (act); } /* { */ /* Account *act1; */ /* Account *act2; */ /* act1 = get_random_account(); */ /* act2 = get_random_account(); */ /* gnc_account_append_child(act1, act2); */ /* test_account(-1, act2); */ /* test_account(-1, act1); */ /* delete_random_account(act2); */ /* delete_random_account(act1); */ /* } */ }
static QofSession* create_session(void) { QofSession* session = qof_session_new(); QofBook* book = qof_session_get_book( session ); Account* root = gnc_book_get_root_account( book ); Account* acct1; Account* acct2; KvpFrame* frame; Transaction* tx; Split* spl1; Split* spl2; Timespec ts; struct timeval tv; gnc_commodity_table* table; gnc_commodity* currency; table = gnc_commodity_table_get_table( book ); currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" ); acct1 = xaccMallocAccount( book ); xaccAccountSetType( acct1, ACCT_TYPE_BANK ); xaccAccountSetName( acct1, "Bank 1" ); xaccAccountSetCommodity( acct1, currency ); frame = qof_instance_get_slots( QOF_INSTANCE(acct1) ); kvp_frame_set_gint64( frame, "int64-val", 100 ); kvp_frame_set_double( frame, "double-val", 3.14159 ); kvp_frame_set_numeric( frame, "numeric-val", gnc_numeric_zero() ); time( &(tv.tv_sec) ); tv.tv_usec = 0; ts.tv_sec = tv.tv_sec; ts.tv_nsec = 1000 * tv.tv_usec; kvp_frame_set_timespec( frame, "timespec-val", ts ); kvp_frame_set_string( frame, "string-val", "abcdefghijklmnop" ); kvp_frame_set_guid( frame, "guid-val", qof_instance_get_guid( QOF_INSTANCE(acct1) ) ); gnc_account_append_child( root, acct1 ); acct2 = xaccMallocAccount( book ); xaccAccountSetType( acct2, ACCT_TYPE_BANK ); xaccAccountSetName( acct2, "Bank 1" ); tx = xaccMallocTransaction( book ); xaccTransBeginEdit( tx ); xaccTransSetCurrency( tx, currency ); spl1 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl1 ); spl2 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl2 ); xaccTransCommitEdit( tx ); return session; }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); }
static Account* clone_account (const Account* from, gnc_commodity *com) { Account *ret; ret = xaccCloneAccount (from, gnc_get_current_book ()); xaccAccountSetCommodity (ret, com); return ret; }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); fixture->customer = gncCustomerCreate(fixture->book); gncOwnerInitCustomer(&fixture->owner, fixture->customer); }
void on_finish (GtkAssistant *gtkassistant, hierarchy_data *data) { GncHierarchyAssistantFinishedCallback when_completed; gnc_commodity *com; Account * root; ENTER (" "); com = gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT(data->currency_selector)); if (data->our_account_tree) { gnc_account_foreach_descendant (data->our_account_tree, (AccountCb)starting_balance_helper, data); } /* Set book options based on the user's choices */ if (data->new_book) finish_book_options_helper(data->optionwin, data->options); // delete before we suspend GUI events, and then muck with the model, // because the model doesn't seem to handle this correctly. if (data->initial_category) gtk_tree_row_reference_free(data->initial_category); delete_hierarchy_dialog (data); gnc_suspend_gui_refresh (); if (data->new_book) gtk_dialog_response(GTK_DIALOG(gnc_options_dialog_widget (data->optionwin)), GTK_RESPONSE_CANCEL); account_trees_merge(gnc_get_current_root_account(), data->our_account_tree); delete_our_account_tree (data); when_completed = data->when_completed; g_free(data); root = gnc_get_current_root_account(); xaccAccountSetCommodity(root, com); gnc_resume_gui_refresh (); if (when_completed) { (*when_completed)(); } LEAVE (" "); }
static gboolean tt_act_handler( xmlNodePtr node, gpointer data ) { gnc_template_xaction_data *txd = data; Account *acc; gnc_commodity *com; acc = dom_tree_to_account(node, txd->book); if ( acc == NULL ) { return FALSE; } else { xaccAccountBeginEdit (acc); /* Check for the lack of a commodity [signifying that the pre-7/11/2001-CIT-change SX template Account was parsed [but incorrectly]. */ if ( xaccAccountGetCommodity( acc ) == NULL ) { #if 1 gnc_commodity_table* table; table = gnc_commodity_table_get_table( txd->book ); com = gnc_commodity_table_lookup( table, "template", "template" ); #else /* FIXME: This should first look in the table of the book, maybe? The right thing happens [WRT file load/save] if we just _new all the time, but it doesn't seem right. This whole block should go away at some point, but the same concern still applies for SchedXaction.c:xaccSchedXactionInit... */ com = gnc_commodity_new( txd->book, "template", "template", "template", "template", 1 ); #endif xaccAccountSetCommodity( acc, com ); } txd->accts = g_list_append( txd->accts, acc ); } return TRUE; }
Account * xaccScrubUtilityGetOrMakeAccount (Account *root, gnc_commodity * currency, const char *accname, GNCAccountType acctype, gboolean placeholder) { Account * acc; g_return_val_if_fail (root, NULL); /* build the account name */ if (!currency) { PERR ("No currency specified!"); return NULL; } /* See if we've got one of these going already ... */ acc = gnc_account_lookup_by_name(root, accname); if (acc == NULL) { /* Guess not. We'll have to build one. */ acc = xaccMallocAccount(gnc_account_get_book (root)); xaccAccountBeginEdit (acc); xaccAccountSetName (acc, accname); xaccAccountSetCommodity (acc, currency); xaccAccountSetType (acc, acctype); xaccAccountSetPlaceholder (acc, placeholder); /* Hang the account off the root. */ gnc_account_append_child (root, acc); xaccAccountCommitEdit (acc); } return acc; }
static void xaccSchedXactionInit(SchedXaction *sx, QofBook *book) { Account *ra; const GncGUID *guid; gchar guidstr[GUID_ENCODING_LENGTH+1]; qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book); /* create a new template account for our splits */ sx->template_acct = xaccMallocAccount(book); guid = qof_instance_get_guid( sx ); xaccAccountBeginEdit( sx->template_acct ); guid_to_string_buff( guid, guidstr ); xaccAccountSetName( sx->template_acct, guidstr); xaccAccountSetCommodity (sx->template_acct, gnc_commodity_table_lookup( gnc_commodity_table_get_table(book), "template", "template") ); xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK ); xaccAccountCommitEdit( sx->template_acct ); ra = gnc_book_get_template_root( book ); gnc_account_append_child( ra, sx->template_acct ); }
static void test_transaction (void) { int i; for (i = 0; i < 50; i++) { Transaction* ran_trn; xmlNodePtr test_node; gnc_commodity* com, *new_com; gchar* filename1; int fd; /* The next line exists for its side effect of creating the * account tree. */ get_random_account_tree (book); ran_trn = get_random_transaction (book); new_com = get_random_commodity (book); if (!ran_trn) { failure_args ("transaction_xml", __FILE__, __LINE__, "get_random_transaction returned NULL"); return; } { /* xaccAccountInsertSplit can reorder the splits. */ GList* list = g_list_copy (xaccTransGetSplitList (ran_trn)); GList* node = list; for (; node; node = node->next) { Split* s = static_cast<decltype (s)> (node->data); Account* a = xaccMallocAccount (book); xaccAccountBeginEdit (a); xaccAccountSetCommodity (a, new_com); xaccAccountSetCommoditySCU (a, xaccSplitGetAmount (s).denom); xaccAccountInsertSplit (a, s); xaccAccountCommitEdit (a); } g_list_free (list); } com = xaccTransGetCurrency (ran_trn); test_node = gnc_transaction_dom_tree_create (ran_trn); if (!test_node) { failure_args ("transaction_xml", __FILE__, __LINE__, "gnc_transaction_dom_tree_create returned NULL"); really_get_rid_of_transaction (ran_trn); continue; } auto compare_msg = node_and_transaction_equal (test_node, ran_trn); if (compare_msg != nullptr) { failure_args ("transaction_xml", __FILE__, __LINE__, "node and transaction were not equal: %s", compare_msg); xmlElemDump (stdout, NULL, test_node); printf ("\n"); fflush (stdout); xmlFreeNode (test_node); really_get_rid_of_transaction (ran_trn); continue; } else { success_args ("transaction_xml", __FILE__, __LINE__, "%d", i); } filename1 = g_strdup_printf ("test_file_XXXXXX"); fd = g_mkstemp (filename1); write_dom_node_to_file (test_node, fd); close (fd); { GList* node = xaccTransGetSplitList (ran_trn); for (; node; node = node->next) { Split* s = static_cast<decltype (s)> (node->data); Account* a1 = xaccSplitGetAccount (s); Account* a2 = xaccMallocAccount (book); xaccAccountBeginEdit (a2); xaccAccountSetCommoditySCU (a2, xaccAccountGetCommoditySCU (a1)); xaccAccountSetGUID (a2, xaccAccountGetGUID (a1)); xaccAccountCommitEdit (a2); } } { sixtp* parser; tran_data data; const char* msg = "[xaccAccountScrubCommodity()] Account \"\" does not have a commodity!"; const char* logdomain = "gnc.engine.scrub"; GLogLevelFlags loglevel = static_cast<decltype (loglevel)> (G_LOG_LEVEL_CRITICAL); TestErrorStruct check = { loglevel, const_cast<char*> (logdomain), const_cast<char*> (msg) }; g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); data.trn = ran_trn; data.com = com; data.value = i; parser = gnc_transaction_sixtp_parser_create (); if (!gnc_xml_parse_file (parser, filename1, test_add_transaction, (gpointer)&data, book)) { failure_args ("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", i); } else really_get_rid_of_transaction (data.new_trn); } /* no handling of circular data structures. We'll do that later */ /* sixtp_destroy(parser); */ g_unlink (filename1); g_free (filename1); really_get_rid_of_transaction (ran_trn); xmlFreeNode (test_node); } }
static void gnc_plugin_business_cmd_test_init_data (GtkAction *action, GncMainWindowActionData *data) { QofBook *book = gnc_get_current_book(); GncCustomer *customer = gncCustomerCreate(book); GncAddress *address = gncCustomerGetAddr(customer); GncInvoice *invoice = gncInvoiceCreate(book); GncOwner *owner = gncOwnerNew(); GncJob *job = gncJobCreate(book); Account *root = gnc_book_get_root_account(book); Account *inc_acct = xaccMallocAccount(book); Account *bank_acct = xaccMallocAccount(book); Account *tax_acct = xaccMallocAccount(book); Account *ar_acct = xaccMallocAccount(book); Timespec now; // Create Customer gncCustomerSetID(customer, "000001"); gncCustomerSetName(customer, "Test Customer"); gncCustomerSetCurrency(customer, gnc_default_currency()); gncAddressSetName(address, "Contact Person"); gncAddressSetAddr1(address, "20 Customer Lane"); gncAddressSetAddr2(address, "Customer M/S"); gncAddressSetAddr3(address, "Addr3, XXX 12345"); // Create the Owner gncOwnerInitCustomer(owner, customer); // Create the Invoice timespecFromTime64(&now, time(NULL)); gncInvoiceSetID(invoice, "000012"); gncInvoiceSetOwner(invoice, owner); gncInvoiceSetDateOpened(invoice, now); gncInvoiceSetCurrency(invoice, gnc_default_currency()); // Create the Job gncJobSetID(job, "000025"); gncJobSetName(job, "Test Job"); gncJobSetReference(job, "Customer's ref#"); gncJobSetOwner(job, owner); // MODIFY THE OWNER gncOwnerInitJob(owner, job); // Create the A/R account xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE); xaccAccountSetName(ar_acct, "A/R"); xaccAccountSetCommodity(ar_acct, gnc_default_currency()); gnc_account_append_child(root, ar_acct); // Create the Income account xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME); xaccAccountSetName(inc_acct, "Income"); xaccAccountSetCommodity(inc_acct, gnc_default_currency()); gnc_account_append_child(root, inc_acct); // Create the Bank account xaccAccountSetType(bank_acct, ACCT_TYPE_BANK); xaccAccountSetName(bank_acct, "Bank"); xaccAccountSetCommodity(bank_acct, gnc_default_currency()); gnc_account_append_child(root, bank_acct); // Create the Tax account xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY); xaccAccountSetName(tax_acct, "Tax-Holding"); xaccAccountSetCommodity(tax_acct, gnc_default_currency()); gnc_account_append_child(root, tax_acct); // Launch the invoice editor gnc_ui_invoice_edit (GTK_WINDOW (data->window), invoice); }
static void test_transaction(void) { int i; for (i = 0; i < 50; i++) { Transaction *ran_trn; Account *root; xmlNodePtr test_node; gnc_commodity *com, *new_com; gchar *compare_msg; gchar *filename1; int fd; /* The next line exists for its side effect of creating the * account tree. */ root = get_random_account_tree(book); ran_trn = get_random_transaction(book); new_com = get_random_commodity( book ); if (!ran_trn) { failure_args("transaction_xml", __FILE__, __LINE__, "get_random_transaction returned NULL"); return; } { /* xaccAccountInsertSplit can reorder the splits. */ GList * list = g_list_copy(xaccTransGetSplitList (ran_trn)); GList * node = list; for ( ; node; node = node->next) { Split * s = node->data; Account * a = xaccMallocAccount(book); xaccAccountBeginEdit (a); xaccAccountSetCommodity( a, new_com ); xaccAccountSetCommoditySCU (a, xaccSplitGetAmount (s).denom); xaccAccountInsertSplit (a, s); xaccAccountCommitEdit (a); } g_list_free(list); } com = xaccTransGetCurrency (ran_trn); test_node = gnc_transaction_dom_tree_create(ran_trn); if (!test_node) { failure_args("transaction_xml", __FILE__, __LINE__, "gnc_transaction_dom_tree_create returned NULL"); really_get_rid_of_transaction(ran_trn); continue; } if ((compare_msg = node_and_transaction_equal(test_node, ran_trn)) != NULL) { failure_args("transaction_xml", __FILE__, __LINE__, "node and transaction were not equal: %s", compare_msg); xmlElemDump(stdout, NULL, test_node); printf("\n"); fflush(stdout); xmlFreeNode(test_node); really_get_rid_of_transaction(ran_trn); continue; } else { success_args("transaction_xml", __FILE__, __LINE__, "%d", i ); } filename1 = g_strdup_printf("test_file_XXXXXX"); fd = g_mkstemp(filename1); write_dom_node_to_file(test_node, fd); close(fd); { GList * node = xaccTransGetSplitList (ran_trn); for ( ; node; node = node->next) { Split * s = node->data; Account * a1 = xaccSplitGetAccount(s); Account * a2 = xaccMallocAccount(book); xaccAccountBeginEdit (a2); xaccAccountSetCommoditySCU (a2, xaccAccountGetCommoditySCU (a1)); xaccAccountSetGUID (a2, xaccAccountGetGUID (a1)); xaccAccountCommitEdit (a2); } } { sixtp *parser; tran_data data; data.trn = ran_trn; data.com = com; data.value = i; g_print(" There will follow a bunch of CRIT scrub errors about the account not having a commodity. There isn't an account in the XML, so of course not. Ignore the errors\n"); parser = gnc_transaction_sixtp_parser_create(); if (!gnc_xml_parse_file(parser, filename1, test_add_transaction, (gpointer)&data, book)) { failure_args("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", i); } else really_get_rid_of_transaction (data.new_trn); /* no handling of circular data structures. We'll do that later */ /* sixtp_destroy(parser); */ } g_unlink(filename1); g_free(filename1); really_get_rid_of_transaction(ran_trn); xmlFreeNode(test_node); } }