Пример #1
0
static void
test_dom_tree_to_commodity_ref(void)
{
    int i;
    for (i = 0; i < 20; i++)
    {
        gnc_commodity *test_com1;
        gchar *test_str1;
        gchar *test_str2;
        gnc_commodity *test_com2;
        xmlNodePtr test_node;
        QofBook *book;

        book = qof_book_new ();

        test_str1 = get_random_string();
        test_str2 = get_random_string();

        test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0);
        test_node = commodity_ref_to_dom_tree("test-com", test_com1);

        test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book);

        do_test(gnc_commodity_equiv(test_com1, test_com2),
                "dom_tree_to_commodity_ref_no_engine");

        xmlFreeNode(test_node);
        gnc_commodity_destroy(test_com1);
        gnc_commodity_destroy(test_com2);
        g_free(test_str1);
        g_free(test_str2);

        qof_book_destroy (book);
    }
}
Пример #2
0
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);

}
Пример #3
0
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);
}
Пример #4
0
static gboolean
gnc_commodity_end_handler(gpointer data_for_children,
                          GSList* data_from_children, GSList* sibling_data,
                          gpointer parent_data, gpointer global_data,
                          gpointer *result, const gchar *tag)
{
    gnc_commodity *com, *old_com;
    xmlNodePtr achild;
    xmlNodePtr tree = (xmlNodePtr)data_for_children;
    gxpf_data *gdata = (gxpf_data*)global_data;
    QofBook *book = static_cast<decltype(book)>(gdata->bookdata);

    if (parent_data)
    {
        return TRUE;
    }

    /* OK.  For some messed up reason this is getting called again with a
       NULL tag.  So we ignore those cases */
    if (!tag)
    {
        return TRUE;
    }

    g_return_val_if_fail(tree, FALSE);

    com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0);
    old_com = gnc_commodity_find_currency(book, tree);
    if (old_com)
        gnc_commodity_copy(com, old_com);

    for (achild = tree->xmlChildrenNode; achild; achild = achild->next)
    {
        set_commodity_value(achild, com);
    }

    if (!valid_commodity(com))
    {
        PWARN("Invalid commodity parsed");
        xmlElemDump(stdout, NULL, tree);
        printf("\n");
        fflush(stdout);
        gnc_commodity_destroy(com);
        return FALSE;
    }

    gdata->cb(tag, gdata->parsedata, com);

    xmlFreeNode(tree);

    return TRUE;
}
static /*@ dependent @*/ gnc_commodity*
load_single_commodity( GncSqlBackend* be, GncSqlRow* row )
{
    QofBook* pBook = be->book;
    gnc_commodity* pCommodity;

    pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
    gnc_commodity_begin_edit( pCommodity );
    gnc_sql_load_object( be, row, GNC_ID_COMMODITY, pCommodity, col_table );
    gnc_commodity_commit_edit( pCommodity );

    return pCommodity;
}
Пример #6
0
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;
}
Пример #7
0
int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data)
{
    const char* cusip = NULL;
    const char* default_fullname = NULL;
    const char* default_mnemonic = NULL;

    if (data.unique_id_valid)
    {
        cusip = data.unique_id;
    }
    if (data.secname_valid)
    {
        default_fullname = data.secname;
    }
    if (data.ticker_valid)
    {
        default_mnemonic = data.ticker;
    }

    if (auto_create_commodity)
    {
        gnc_commodity *commodity =
            gnc_import_select_commodity(cusip,
                                        FALSE,
                                        default_fullname,
                                        default_mnemonic);

        if (!commodity)
        {
            QofBook *book = gnc_get_current_book();
            gnc_quote_source *source;
            gint source_selection = 0; // FIXME: This is just a wild guess
            const char *commodity_namespace = NULL;
            int fraction = 1;

            if (data.unique_id_type_valid)
            {
                commodity_namespace = data.unique_id_type;
            }

            g_warning("Creating a new commodity, cusip=%s", cusip);
            /* Create the new commodity */
            commodity = gnc_commodity_new(book,
                                          default_fullname,
                                          commodity_namespace,
                                          default_mnemonic,
                                          cusip,
                                          fraction);

            /* Also set a single quote source */
            gnc_commodity_begin_edit(commodity);
            gnc_commodity_user_set_quote_flag (commodity, TRUE);
            source = gnc_quote_source_lookup_by_ti (SOURCE_SINGLE, source_selection);
            gnc_commodity_set_quote_source(commodity, source);
            gnc_commodity_commit_edit(commodity);

            /* Remember the commodity */
            gnc_commodity_table_insert(gnc_get_current_commodities(), commodity);

            /* Remember this new commodity for us as well */
            ofx_created_commodites = g_list_prepend(ofx_created_commodites, commodity);
        }
    }
    else
    {
        gnc_import_select_commodity(cusip,
                                    TRUE,
                                    default_fullname,
                                    default_mnemonic);
    }
    return 0;
}