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;
}
Exemplo n.º 2
0
void
GncSqlBackend::load (QofBook* book, QofBackendLoadType loadType)
{
    Account* root;

    g_return_if_fail (book != NULL);

    ENTER ("sql_be=%p, book=%p", this, book);

    m_loading = TRUE;

    if (loadType == LOAD_TYPE_INITIAL_LOAD)
    {
        assert (m_book == nullptr);
        m_book = book;

        /* Load any initial stuff. Some of this needs to happen in a certain order */
        for (auto type : fixed_load_order)
        {
            auto obe = m_backend_registry.get_object_backend(type);
            if (obe)
            {
                update_progress();
                obe->load_all(this);
            }
        }
        for (auto type : business_fixed_load_order)
        {
            auto obe = m_backend_registry.get_object_backend(type);
            if (obe)
            {
                update_progress();
                obe->load_all(this);
            }
        }

        root = gnc_book_get_root_account( book );
        gnc_account_foreach_descendant(root, (AccountCb)xaccAccountBeginEdit,
                                       nullptr);

        m_backend_registry.load_remaining(this);

        gnc_account_foreach_descendant(root, (AccountCb)xaccAccountCommitEdit,
                                       nullptr);
    }
    else if (loadType == LOAD_TYPE_LOAD_ALL)
    {
        // Load all transactions
        auto obe = m_backend_registry.get_object_backend (GNC_ID_TRANS);
        obe->load_all (this);
    }

    m_loading = FALSE;
    std::for_each(m_postload_commodities.begin(), m_postload_commodities.end(),
                 [](gnc_commodity* comm) {
                      gnc_commodity_begin_edit(comm);
                      gnc_commodity_commit_edit(comm);
                  });
    m_postload_commodities.empty();

    /* Mark the sessoion as clean -- though it should never be marked
     * dirty with this backend
     */
    qof_book_mark_session_saved (book);
    finish_progress();

    LEAVE ("");
}
Exemplo n.º 3
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;
}