Ejemplo n.º 1
0
static gboolean
vendor_guid_handler (xmlNodePtr node, gpointer vendor_pdata)
{
    struct vendor_pdata* pdata = static_cast<decltype (pdata)> (vendor_pdata);
    GncGUID* guid;
    GncVendor* vendor;

    guid = dom_tree_to_guid (node);
    g_return_val_if_fail (guid, FALSE);
    vendor = gncVendorLookup (pdata->book, guid);
    if (vendor)
    {
        gncVendorDestroy (pdata->vendor);
        pdata->vendor = vendor;
        gncVendorBeginEdit (vendor);
    }
    else
    {
        gncVendorSetGUID (pdata->vendor, guid);
    }

    g_free (guid);

    return TRUE;
}
Ejemplo n.º 2
0
static void
load_owner( const GncSqlBackend* be, GncSqlRow* row,
            QofSetterFunc setter, gpointer pObject,
            const GncSqlColumnTableEntry* table_row )
{
    const GValue* val;
    gchar* buf;
    GncOwnerType type;
    GncGUID guid;
    QofBook* book;
    GncOwner owner;
    GncGUID* pGuid = NULL;

    g_return_if_fail( be != NULL );
    g_return_if_fail( row != NULL );
    g_return_if_fail( pObject != NULL );
    g_return_if_fail( table_row != NULL );

    book = be->primary_book;
    buf = g_strdup_printf( "%s_type", table_row->col_name );
    val = gnc_sql_row_get_value_at_col_name( row, buf );
    type = (GncOwnerType)gnc_sql_get_integer_value( val );
    g_free( buf );
    buf = g_strdup_printf( "%s_guid", table_row->col_name );
    val = gnc_sql_row_get_value_at_col_name( row, buf );
    g_free( buf );

    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
    {
        string_to_guid( g_value_get_string( val ), &guid );
        pGuid = &guid;
    }

    switch ( type )
    {
    case GNC_OWNER_CUSTOMER:
    {
        GncCustomer *cust = NULL;

        if ( pGuid != NULL )
        {
            cust = gncCustomerLookup( book, pGuid );
            if ( cust == NULL )
            {
                cust = gncCustomerCreate( book );
                gncCustomerSetGUID( cust, &guid );
            }
        }
        gncOwnerInitCustomer( &owner, cust );
        break;
    }

    case GNC_OWNER_JOB:
    {
        GncJob *job = NULL;

        if ( pGuid != NULL )
        {
            job = gncJobLookup( book, pGuid );
            if ( job == NULL )
            {
                job = gncJobCreate( book );
                gncJobSetGUID( job, &guid );
            }
        }
        gncOwnerInitJob( &owner, job );
        break;
    }

    case GNC_OWNER_VENDOR:
    {
        GncVendor *vendor = NULL;

        if ( pGuid != NULL )
        {
            vendor = gncVendorLookup( book, pGuid );
            if ( vendor == NULL )
            {
                vendor = gncVendorCreate( book );
                gncVendorSetGUID( vendor, &guid );
            }
        }
        gncOwnerInitVendor( &owner, vendor );
        break;
    }

    case GNC_OWNER_EMPLOYEE:
    {
        GncEmployee *employee = NULL;

        if ( pGuid != NULL )
        {
            employee = gncEmployeeLookup( book, pGuid );
            if ( employee == NULL )
            {
                employee = gncEmployeeCreate( book );
                gncEmployeeSetGUID( employee, &guid );
            }
        }
        gncOwnerInitEmployee( &owner, employee );
        break;
    }

    default:
        PWARN("Invalid owner type: %d\n", type );
    }

    if ( table_row->gobj_param_name != NULL )
    {
        g_object_set( pObject, table_row->gobj_param_name, &owner, NULL );
    }
    else
    {
        (*setter)( pObject, &owner );
    }
}
Ejemplo n.º 3
0
static gboolean
owner_id_handler (xmlNodePtr node, gpointer owner_pdata)
{
    struct owner_pdata* pdata = static_cast<decltype (pdata)> (owner_pdata);
    GncGUID* guid;

    guid = dom_tree_to_guid (node);
    g_return_val_if_fail (guid, FALSE);

    switch (gncOwnerGetType (pdata->owner))
    {
    case GNC_OWNER_CUSTOMER:
    {
        GncCustomer* cust = gncCustomerLookup (pdata->book, guid);
        if (!cust)
        {
            cust = gncCustomerCreate (pdata->book);
            gncCustomerSetGUID (cust, guid);
        }
        gncOwnerInitCustomer (pdata->owner, cust);
        break;
    }
    case GNC_OWNER_JOB:
    {
        GncJob* job = gncJobLookup (pdata->book, guid);
        if (!job)
        {
            job = gncJobCreate (pdata->book);
            gncJobSetGUID (job, guid);
        }
        gncOwnerInitJob (pdata->owner, job);
        break;
    }
    case GNC_OWNER_VENDOR:
    {
        GncVendor* vendor = gncVendorLookup (pdata->book, guid);
        if (!vendor)
        {
            vendor = gncVendorCreate (pdata->book);
            gncVendorSetGUID (vendor, guid);
        }
        gncOwnerInitVendor (pdata->owner, vendor);
        break;
    }
    case GNC_OWNER_EMPLOYEE:
    {
        GncEmployee* employee = gncEmployeeLookup (pdata->book, guid);
        if (!employee)
        {
            employee = gncEmployeeCreate (pdata->book);
            gncEmployeeSetGUID (employee, guid);
        }
        gncOwnerInitEmployee (pdata->owner, employee);
        break;
    }
    default:
        PWARN ("Invalid owner type: %d\n", gncOwnerGetType (pdata->owner));
        g_free (guid);
        return FALSE;
    }

    g_free (guid);
    return TRUE;
}
Ejemplo n.º 4
0
static void
test_vendor (void)
{
    QofBook *book;
    GncVendor *vendor;

    book = qof_book_new();

    /* Test creation/destruction */
    {
        do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL");
        vendor = gncVendorCreate (book);
        do_test (vendor != NULL, "vendor create");
        do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book,
                 "getbook");

        gncVendorBeginEdit (vendor);
        gncVendorDestroy (vendor);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
        test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
        test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);

        //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);

        //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
        test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);

        do_test (gncVendorGetAddr (vendor) != NULL, "Addr");

        guid_new (&guid);
        vendor = gncVendorCreate (book);
        count++;
        gncVendorSetGUID (vendor, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;

        gncVendorSetName (vendor, str);
        res = qof_object_printable (GNC_ID_VENDOR, vendor);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    qof_book_destroy (book);
}