Example #1
0
GncEmployee *
gncCloneEmployee (GncEmployee *from, QofBook *book)
{
    GncEmployee *employee;
    if (!book || !from) return NULL;

    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
    qof_instance_init_data(&employee->inst, _GNC_MOD_NAME, book);
    qof_instance_gemini (&employee->inst, &from->inst);

    employee->id = CACHE_INSERT (from->id);
    employee->username = CACHE_INSERT (from->username);
    employee->language = CACHE_INSERT (from->language);
    employee->acl = CACHE_INSERT (from->acl);
    employee->addr = gncCloneAddress (from->addr, &employee->inst, book);
    employee->workday = from->workday;
    employee->rate = from->rate;
    employee->active = from->active;
    employee->currency = gnc_commodity_obtain_twin(from->currency, book);
    employee->ccard_acc =
        GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));

    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);

    return employee;
}
Example #2
0
/** Create a copy of a customer, placing the copy into a new book. */
GncCustomer *
gncCloneCustomer (GncCustomer *from, QofBook *book)
{
    GList *node;
    GncCustomer *cust;

    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);

    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
    qof_instance_gemini (&cust->inst, &from->inst);

    cust->id = CACHE_INSERT (from->id);
    cust->name = CACHE_INSERT (from->name);
    cust->notes = CACHE_INSERT (from->notes);
    cust->discount = from->discount;
    cust->credit = from->credit;
    cust->taxincluded = from->taxincluded;
    cust->active = from->active;
    cust->taxtable_override = from->taxtable_override;

    cust->addr = gncCloneAddress (from->addr, &cust->inst, book);
    cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst, book);

    /* Find the matching currency in the new book, assumes
     * currency has already been copied into new book. */
    cust->currency = gnc_commodity_obtain_twin (from->currency, book);

    /* Find the matching bill term, tax table in the new book */
    cust->terms = gncBillTermObtainTwin(from->terms, book);
    cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);

    for (node = g_list_last(cust->jobs); node; node = node->next)
    {
        GncJob *job = node->data;
        job = gncJobObtainTwin (job, book);
        cust->jobs = g_list_prepend(cust->jobs, job);
    }

    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);

    return cust;
}