mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add Transaction property "invoice"
Replaces direct KVP access.
This commit is contained in:
parent
8d9d51a7f7
commit
e3e21b602b
@ -196,7 +196,8 @@ enum
|
||||
PROP_DESCRIPTION,
|
||||
PROP_CURRENCY,
|
||||
PROP_POST_DATE,
|
||||
PROP_ENTER_DATE
|
||||
PROP_ENTER_DATE,
|
||||
PROP_INVOICE,
|
||||
};
|
||||
|
||||
void
|
||||
@ -302,6 +303,9 @@ gnc_transaction_get_property(GObject* object,
|
||||
GParamSpec* pspec)
|
||||
{
|
||||
Transaction* tx;
|
||||
KvpFrame *frame;
|
||||
gchar *key;
|
||||
GValue *temp;
|
||||
|
||||
g_return_if_fail(GNC_IS_TRANSACTION(object));
|
||||
|
||||
@ -323,6 +327,10 @@ gnc_transaction_get_property(GObject* object,
|
||||
case PROP_ENTER_DATE:
|
||||
g_value_set_boxed(value, &tx->date_entered);
|
||||
break;
|
||||
case PROP_INVOICE:
|
||||
key = GNC_INVOICE_ID "/" GNC_INVOICE_GUID;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (tx), key, value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
@ -336,6 +344,8 @@ gnc_transaction_set_property(GObject* object,
|
||||
GParamSpec* pspec)
|
||||
{
|
||||
Transaction* tx;
|
||||
KvpFrame *frame;
|
||||
gchar *key;
|
||||
|
||||
g_return_if_fail(GNC_IS_TRANSACTION(object));
|
||||
|
||||
@ -357,6 +367,10 @@ gnc_transaction_set_property(GObject* object,
|
||||
case PROP_ENTER_DATE:
|
||||
xaccTransSetDateEnteredTS(tx, g_value_get_boxed(value));
|
||||
break;
|
||||
case PROP_INVOICE:
|
||||
key = GNC_INVOICE_ID "/" GNC_INVOICE_GUID;
|
||||
qof_instance_set_kvp (QOF_INSTANCE (tx), key, value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
@ -425,6 +439,15 @@ gnc_transaction_class_init(TransactionClass* klass)
|
||||
"The date the transaction was entered.",
|
||||
GNC_TYPE_TIMESPEC,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property(
|
||||
gobject_class,
|
||||
PROP_INVOICE,
|
||||
g_param_spec_boxed("invoice",
|
||||
"Invoice attached to lot",
|
||||
"Used by GncInvoice",
|
||||
GNC_TYPE_GUID,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
@ -2594,6 +2617,7 @@ xaccTransFindSplitByAccount(const Transaction *trans, const Account *acc)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
/* QofObject function implementation */
|
||||
|
@ -251,5 +251,10 @@ void gnc_engine_add_commit_error_callback( EngineCommitErrorCallback cb, gpointe
|
||||
|
||||
void gnc_engine_signal_commit_error( QofBackendError errcode );
|
||||
|
||||
/** STRING CONSTANTS **********************************************
|
||||
* Used to declare constant KVP keys used in more than one class
|
||||
*/
|
||||
#define GNC_INVOICE_ID "gncInvoice"
|
||||
#define GNC_INVOICE_GUID "invoice-guid"
|
||||
#endif
|
||||
/** @} */
|
||||
|
@ -1141,10 +1141,8 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
|
||||
if (invoice->posted_txn) return; /* Cannot reset invoice's txn */
|
||||
|
||||
xaccTransBeginEdit (txn);
|
||||
kvp = xaccTransGetSlots (txn);
|
||||
value = kvp_value_new_guid (qof_instance_get_guid(QOF_INSTANCE(invoice)));
|
||||
kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
|
||||
kvp_value_delete (value);
|
||||
qof_instance_set (QOF_INSTANCE (txn), "invoice",
|
||||
qof_instance_get_guid (QOF_INSTANCE (invoice)), NULL);
|
||||
xaccTransSetTxnType (txn, TXN_TYPE_INVOICE);
|
||||
xaccTransCommitEdit (txn);
|
||||
gncInvoiceSetPostedTxn (invoice, txn);
|
||||
@ -1153,19 +1151,13 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
|
||||
GncInvoice *
|
||||
gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
|
||||
{
|
||||
KvpFrame *kvp;
|
||||
KvpValue *value;
|
||||
GncGUID *guid;
|
||||
QofBook *book;
|
||||
|
||||
if (!txn) return NULL;
|
||||
|
||||
book = xaccTransGetBook (txn);
|
||||
kvp = xaccTransGetSlots (txn);
|
||||
value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
|
||||
if (!value) return NULL;
|
||||
|
||||
guid = kvp_value_get_guid (value);
|
||||
qof_instance_get (QOF_INSTANCE (txn), "invoice", &guid, NULL);
|
||||
return gncInvoiceLookup(book, guid);
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,13 @@ setup_account (Fixture *fixture, gconstpointer pData)
|
||||
fixture->acct = xaccMallocAccount (book);
|
||||
}
|
||||
|
||||
static void
|
||||
setup_trans (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
QofBook *book = qof_book_new ();
|
||||
fixture->trans = xaccMallocTransaction (book);
|
||||
}
|
||||
|
||||
static void
|
||||
teardown (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
@ -101,7 +108,30 @@ test_account_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->acct)));
|
||||
}
|
||||
|
||||
static void
|
||||
test_trans_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
GncGUID *guid = guid_malloc ();
|
||||
GncGUID *guid_r;
|
||||
|
||||
qof_instance_set (QOF_INSTANCE (fixture->trans),
|
||||
"invoice", guid,
|
||||
NULL);
|
||||
|
||||
g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->trans)));
|
||||
qof_instance_mark_clean (QOF_INSTANCE (fixture->trans));
|
||||
|
||||
qof_instance_get (QOF_INSTANCE (fixture->trans),
|
||||
"invoice", &guid_r,
|
||||
NULL);
|
||||
g_assert (guid_equal (guid, guid_r));
|
||||
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->trans)));
|
||||
guid_free (guid);
|
||||
guid_free (guid_r);
|
||||
}
|
||||
|
||||
void test_suite_engine_kvp_properties (void)
|
||||
{
|
||||
GNC_TEST_ADD (suitename, "Account", Fixture, NULL, setup_account, test_account_kvp_properties, teardown);
|
||||
GNC_TEST_ADD (suitename, "Transaction", Fixture, NULL, setup_trans, test_trans_kvp_properties, teardown);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user