示例#1
0
static gboolean
vendor_addr_handler (xmlNodePtr node, gpointer vendor_pdata)
{
    struct vendor_pdata* pdata = static_cast<decltype (pdata)> (vendor_pdata);

    return gnc_dom_tree_to_address (node, gncVendorGetAddr (pdata->vendor));
}
示例#2
0
static xmlNodePtr
vendor_dom_tree_create (GncVendor* vendor)
{
    xmlNodePtr ret;
    GncBillTerm* term;
    GncTaxTable* taxtable;

    ret = xmlNewNode (NULL, BAD_CAST gnc_vendor_string);
    xmlSetProp (ret, BAD_CAST "version", BAD_CAST vendor_version_string);

    xmlAddChild (ret, guid_to_dom_tree (vendor_guid_string,
                                        qof_instance_get_guid (QOF_INSTANCE (vendor))));

    xmlAddChild (ret, text_to_dom_tree (vendor_name_string,
                                        gncVendorGetName (vendor)));

    xmlAddChild (ret, text_to_dom_tree (vendor_id_string,
                                        gncVendorGetID (vendor)));

    xmlAddChild (ret, gnc_address_to_dom_tree (vendor_addr_string,
                                               gncVendorGetAddr (vendor)));

    maybe_add_string (ret, vendor_notes_string, gncVendorGetNotes (vendor));

    term = gncVendorGetTerms (vendor);
    if (term)
        xmlAddChild (ret, guid_to_dom_tree (vendor_terms_string,
                                            qof_instance_get_guid (QOF_INSTANCE (term))));

    xmlAddChild (ret, text_to_dom_tree (vendor_taxincluded_string,
                                        gncTaxIncludedTypeToString (
                                            gncVendorGetTaxIncluded (vendor))));

    xmlAddChild (ret, int_to_dom_tree (vendor_active_string,
                                       gncVendorGetActive (vendor)));

    xmlAddChild
    (ret,
     commodity_ref_to_dom_tree (vendor_currency_string,
                                gncVendorGetCurrency (vendor)));

    xmlAddChild (ret, int_to_dom_tree (vendor_taxtableoverride_string,
                                       gncVendorGetTaxTableOverride (vendor)));
    taxtable = gncVendorGetTaxTable (vendor);
    if (taxtable)
        xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
                                            qof_instance_get_guid (QOF_INSTANCE (taxtable))));

    /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
    xmlAddChild (ret, qof_instance_slots_to_dom_tree (vendor_slots_string,
                                                      QOF_INSTANCE (vendor)));
    return ret;
}
示例#3
0
GncAddress * gncOwnerGetAddr (const GncOwner *owner)
{
    if (!owner) return NULL;
    switch (owner->type)
    {
    case GNC_OWNER_NONE:
    case GNC_OWNER_UNDEFINED:
    case GNC_OWNER_JOB:
    default:
        return NULL;
    case GNC_OWNER_CUSTOMER:
        return gncCustomerGetAddr (owner->owner.customer);
    case GNC_OWNER_VENDOR:
        return gncVendorGetAddr (owner->owner.vendor);
    case GNC_OWNER_EMPLOYEE:
        return gncEmployeeGetAddr (owner->owner.employee);
    }
}
示例#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);
}