mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add properties "invoice", "owner-type", and "owner-guid"
Replaces direct KVP access.
This commit is contained in:
parent
e3e21b602b
commit
f29ea9fbe9
@ -256,5 +256,10 @@ void gnc_engine_signal_commit_error( QofBackendError errcode );
|
|||||||
*/
|
*/
|
||||||
#define GNC_INVOICE_ID "gncInvoice"
|
#define GNC_INVOICE_ID "gncInvoice"
|
||||||
#define GNC_INVOICE_GUID "invoice-guid"
|
#define GNC_INVOICE_GUID "invoice-guid"
|
||||||
|
#define GNC_OWNER_ID "gncOwner"
|
||||||
|
#define GNC_OWNER_TYPE "owner-type"
|
||||||
|
#define GNC_OWNER_GUID "owner-guid"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -65,7 +65,11 @@ enum
|
|||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_IS_CLOSED,
|
PROP_IS_CLOSED,
|
||||||
PROP_MARKER
|
PROP_MARKER,
|
||||||
|
|
||||||
|
PROP_INVOICE,
|
||||||
|
PROP_OWNER_TYPE,
|
||||||
|
PROP_OWNER_GUID,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct LotPrivate
|
typedef struct LotPrivate
|
||||||
@ -94,6 +98,11 @@ typedef struct LotPrivate
|
|||||||
|
|
||||||
/* ============================================================= */
|
/* ============================================================= */
|
||||||
|
|
||||||
|
static void gnc_lot_set_invoice (GNCLot* lot, GncGUID *guid);
|
||||||
|
static GncGUID *gnc_lot_get_invoice (GNCLot* lot);
|
||||||
|
|
||||||
|
/* ============================================================= */
|
||||||
|
|
||||||
/* GObject Initialization */
|
/* GObject Initialization */
|
||||||
G_DEFINE_TYPE(GNCLot, gnc_lot, QOF_TYPE_INSTANCE)
|
G_DEFINE_TYPE(GNCLot, gnc_lot, QOF_TYPE_INSTANCE)
|
||||||
|
|
||||||
@ -126,6 +135,9 @@ gnc_lot_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec*
|
|||||||
{
|
{
|
||||||
GNCLot* lot;
|
GNCLot* lot;
|
||||||
LotPrivate* priv;
|
LotPrivate* priv;
|
||||||
|
KvpFrame *frame;
|
||||||
|
gchar *key;
|
||||||
|
GValue *temp;
|
||||||
|
|
||||||
g_return_if_fail(GNC_IS_LOT(object));
|
g_return_if_fail(GNC_IS_LOT(object));
|
||||||
|
|
||||||
@ -139,6 +151,21 @@ gnc_lot_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec*
|
|||||||
case PROP_MARKER:
|
case PROP_MARKER:
|
||||||
g_value_set_int(value, priv->marker);
|
g_value_set_int(value, priv->marker);
|
||||||
break;
|
break;
|
||||||
|
case PROP_INVOICE:
|
||||||
|
key = GNC_INVOICE_ID "/" GNC_INVOICE_GUID;
|
||||||
|
qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
|
||||||
|
break;
|
||||||
|
case PROP_OWNER_TYPE:
|
||||||
|
key = GNC_OWNER_ID"/" GNC_OWNER_TYPE;
|
||||||
|
qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
|
||||||
|
break;
|
||||||
|
case PROP_OWNER_GUID:
|
||||||
|
key = GNC_OWNER_ID "/" GNC_OWNER_GUID;
|
||||||
|
qof_instance_get_kvp (QOF_INSTANCE (lot), key, value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +174,8 @@ gnc_lot_set_property(GObject* object, guint prop_id, const GValue* value, GParam
|
|||||||
{
|
{
|
||||||
GNCLot* lot;
|
GNCLot* lot;
|
||||||
LotPrivate* priv;
|
LotPrivate* priv;
|
||||||
|
KvpFrame *frame;
|
||||||
|
gchar *key = NULL;
|
||||||
|
|
||||||
g_return_if_fail(GNC_IS_LOT(object));
|
g_return_if_fail(GNC_IS_LOT(object));
|
||||||
|
|
||||||
@ -160,7 +189,22 @@ gnc_lot_set_property(GObject* object, guint prop_id, const GValue* value, GParam
|
|||||||
case PROP_MARKER:
|
case PROP_MARKER:
|
||||||
priv->marker = g_value_get_int(value);
|
priv->marker = g_value_get_int(value);
|
||||||
break;
|
break;
|
||||||
}
|
case PROP_INVOICE:
|
||||||
|
key = GNC_INVOICE_ID"/" GNC_INVOICE_GUID;
|
||||||
|
qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
|
||||||
|
break;
|
||||||
|
case PROP_OWNER_TYPE:
|
||||||
|
key = GNC_OWNER_ID "/" GNC_OWNER_TYPE;
|
||||||
|
qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
|
||||||
|
break;
|
||||||
|
case PROP_OWNER_GUID:
|
||||||
|
key = GNC_OWNER_ID "/" GNC_OWNER_GUID;
|
||||||
|
qof_instance_set_kvp (QOF_INSTANCE (lot), key, value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -194,8 +238,32 @@ gnc_lot_class_init(GNCLotClass* klass)
|
|||||||
0, G_MAXINT8, 0,
|
0, G_MAXINT8, 0,
|
||||||
G_PARAM_READWRITE));
|
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));
|
||||||
|
|
||||||
|
g_object_class_install_property(
|
||||||
|
gobject_class,
|
||||||
|
PROP_OWNER_TYPE,
|
||||||
|
g_param_spec_int64("owner-type",
|
||||||
|
"Owning Entity Type of lot",
|
||||||
|
"Used by GncOwner",
|
||||||
|
0, G_MAXINT64, 0,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
|
g_object_class_install_property(
|
||||||
|
gobject_class,
|
||||||
|
PROP_OWNER_GUID,
|
||||||
|
g_param_spec_boxed("owner-guid",
|
||||||
|
"Owner attached to lot",
|
||||||
|
"Used by GncOwner",
|
||||||
|
GNC_TYPE_GUID,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
GNCLot *
|
GNCLot *
|
||||||
|
@ -82,8 +82,6 @@ static QofLogModule log_module = GNC_MOD_BUSINESS;
|
|||||||
|
|
||||||
#define _GNC_MOD_NAME GNC_ID_INVOICE
|
#define _GNC_MOD_NAME GNC_ID_INVOICE
|
||||||
|
|
||||||
#define GNC_INVOICE_ID "gncInvoice"
|
|
||||||
#define GNC_INVOICE_GUID "invoice-guid"
|
|
||||||
#define GNC_INVOICE_IS_CN "credit-note"
|
#define GNC_INVOICE_IS_CN "credit-note"
|
||||||
|
|
||||||
#define SET_STR(obj, member, str) { \
|
#define SET_STR(obj, member, str) { \
|
||||||
@ -1080,52 +1078,37 @@ qofInvoiceSetJob (GncInvoice *invoice, GncJob *job)
|
|||||||
static void
|
static void
|
||||||
gncInvoiceDetachFromLot (GNCLot *lot)
|
gncInvoiceDetachFromLot (GNCLot *lot)
|
||||||
{
|
{
|
||||||
KvpFrame *kvp;
|
|
||||||
|
|
||||||
if (!lot) return;
|
if (!lot) return;
|
||||||
|
|
||||||
gnc_lot_begin_edit (lot);
|
gnc_lot_begin_edit (lot);
|
||||||
kvp = gnc_lot_get_slots (lot);
|
qof_instance_set (QOF_INSTANCE (lot), "invoice", NULL, NULL);
|
||||||
kvp_frame_set_slot_path (kvp, NULL, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
|
|
||||||
qof_instance_set_dirty (QOF_INSTANCE (lot));
|
|
||||||
gnc_lot_commit_edit (lot);
|
gnc_lot_commit_edit (lot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
|
gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
|
||||||
{
|
{
|
||||||
KvpFrame *kvp;
|
GncGUID *guid;
|
||||||
KvpValue *value;
|
|
||||||
|
|
||||||
if (!invoice || !lot)
|
if (!invoice || !lot)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (invoice->posted_lot) return; /* Cannot reset invoice's lot */
|
if (invoice->posted_lot) return; /* Cannot reset invoice's lot */
|
||||||
|
guid = (GncGUID*)qof_instance_get_guid (QOF_INSTANCE (invoice));
|
||||||
gnc_lot_begin_edit (lot);
|
gnc_lot_begin_edit (lot);
|
||||||
kvp = gnc_lot_get_slots (lot);
|
qof_instance_set (QOF_INSTANCE (lot), "invoice", guid, NULL);
|
||||||
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);
|
|
||||||
qof_instance_set_dirty (QOF_INSTANCE (lot));
|
|
||||||
gnc_lot_commit_edit (lot);
|
gnc_lot_commit_edit (lot);
|
||||||
kvp_value_delete (value);
|
|
||||||
gncInvoiceSetPostedLot (invoice, lot);
|
gncInvoiceSetPostedLot (invoice, lot);
|
||||||
}
|
}
|
||||||
|
|
||||||
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
|
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
|
||||||
{
|
{
|
||||||
KvpFrame *kvp;
|
|
||||||
KvpValue *value;
|
|
||||||
GncGUID *guid;
|
GncGUID *guid;
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
|
|
||||||
if (!lot) return NULL;
|
if (!lot) return NULL;
|
||||||
|
|
||||||
book = gnc_lot_get_book (lot);
|
book = gnc_lot_get_book (lot);
|
||||||
kvp = gnc_lot_get_slots (lot);
|
qof_instance_get (QOF_INSTANCE (lot), "invoice", &guid, NULL);
|
||||||
value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
|
|
||||||
if (!value) return NULL;
|
|
||||||
|
|
||||||
guid = kvp_value_get_guid (value);
|
|
||||||
return gncInvoiceLookup(book, guid);
|
return gncInvoiceLookup(book, guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +251,7 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
|
|||||||
*/
|
*/
|
||||||
static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GncGUID *guid)
|
static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GncGUID *guid)
|
||||||
{
|
{
|
||||||
|
if (book == NULL || guid == NULL) return NULL;
|
||||||
QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_INVOICE, GncInvoice);
|
QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_INVOICE, GncInvoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +289,6 @@ QofBook *gncInvoiceGetBook(GncInvoice *x);
|
|||||||
/** deprecated functions */
|
/** deprecated functions */
|
||||||
#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
||||||
#define gncInvoiceRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
|
#define gncInvoiceRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
|
||||||
#define gncInvoiceLookupDirect(G,B) gncInvoiceLookup((B),&(G))
|
|
||||||
|
|
||||||
/** Test support function used by test-dbi-business-stuff.c */
|
/** Test support function used by test-dbi-business-stuff.c */
|
||||||
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b);
|
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b);
|
||||||
|
@ -51,8 +51,6 @@
|
|||||||
#define _GNC_MOD_NAME GNC_ID_OWNER
|
#define _GNC_MOD_NAME GNC_ID_OWNER
|
||||||
|
|
||||||
#define GNC_OWNER_ID "gncOwner"
|
#define GNC_OWNER_ID "gncOwner"
|
||||||
#define GNC_OWNER_TYPE "owner-type"
|
|
||||||
#define GNC_OWNER_GUID "owner-guid"
|
|
||||||
|
|
||||||
GncOwner * gncOwnerNew (void)
|
GncOwner * gncOwnerNew (void)
|
||||||
{
|
{
|
||||||
@ -568,31 +566,20 @@ const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner)
|
|||||||
|
|
||||||
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
|
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
|
||||||
{
|
{
|
||||||
KvpFrame *kvp;
|
if (!owner || !lot)
|
||||||
KvpValue *value;
|
|
||||||
|
|
||||||
if (!owner || !lot)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
kvp = gnc_lot_get_slots (lot);
|
|
||||||
gnc_lot_begin_edit (lot);
|
gnc_lot_begin_edit (lot);
|
||||||
|
|
||||||
value = kvp_value_new_gint64 (gncOwnerGetType (owner));
|
qof_instance_set (QOF_INSTANCE (lot),
|
||||||
kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
|
"owner-type", (gint64)gncOwnerGetType (owner),
|
||||||
kvp_value_delete (value);
|
"owner-guid", gncOwnerGetGUID (owner),
|
||||||
|
NULL);
|
||||||
value = kvp_value_new_guid (gncOwnerGetGUID (owner));
|
|
||||||
kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
|
|
||||||
qof_instance_set_dirty (QOF_INSTANCE (lot));
|
|
||||||
gnc_lot_commit_edit (lot);
|
gnc_lot_commit_edit (lot);
|
||||||
kvp_value_delete (value);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
||||||
{
|
{
|
||||||
KvpFrame *kvp;
|
|
||||||
KvpValue *value;
|
|
||||||
GncGUID *guid;
|
GncGUID *guid;
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
GncOwnerType type;
|
GncOwnerType type;
|
||||||
@ -600,20 +587,10 @@ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
|||||||
if (!lot || !owner) return FALSE;
|
if (!lot || !owner) return FALSE;
|
||||||
|
|
||||||
book = gnc_lot_get_book (lot);
|
book = gnc_lot_get_book (lot);
|
||||||
kvp = gnc_lot_get_slots (lot);
|
qof_instance_get (QOF_INSTANCE (lot),
|
||||||
|
"owner-type", &type,
|
||||||
value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
|
"owner-guid", &guid,
|
||||||
if (!value) return FALSE;
|
NULL);
|
||||||
|
|
||||||
type = kvp_value_get_gint64 (value);
|
|
||||||
|
|
||||||
value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
|
|
||||||
if (!value) return FALSE;
|
|
||||||
|
|
||||||
guid = kvp_value_get_guid (value);
|
|
||||||
if (!guid)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case GNC_OWNER_CUSTOMER:
|
case GNC_OWNER_CUSTOMER:
|
||||||
|
@ -47,6 +47,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
Account *acct;
|
Account *acct;
|
||||||
Transaction *trans;
|
Transaction *trans;
|
||||||
|
GNCLot *lot;
|
||||||
GncCustomer *cust;
|
GncCustomer *cust;
|
||||||
GncEmployee *emp;
|
GncEmployee *emp;
|
||||||
GncJob *job;
|
GncJob *job;
|
||||||
@ -77,6 +78,13 @@ setup_trans (Fixture *fixture, gconstpointer pData)
|
|||||||
fixture->trans = xaccMallocTransaction (book);
|
fixture->trans = xaccMallocTransaction (book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
setup_lot (Fixture *fixture, gconstpointer pData)
|
||||||
|
{
|
||||||
|
QofBook *book = qof_book_new ();
|
||||||
|
fixture->lot = gnc_lot_new (book);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
teardown (Fixture *fixture, gconstpointer pData)
|
teardown (Fixture *fixture, gconstpointer pData)
|
||||||
{
|
{
|
||||||
@ -130,8 +138,43 @@ test_trans_kvp_properties (Fixture *fixture, gconstpointer pData)
|
|||||||
guid_free (guid_r);
|
guid_free (guid_r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_lot_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||||
|
{
|
||||||
|
GncGUID *invoice = guid_malloc ();
|
||||||
|
GncGUID *invoice_r;
|
||||||
|
gint64 owner_type = 47;
|
||||||
|
gint64 owner_type_r;
|
||||||
|
GncGUID *owner = guid_malloc ();
|
||||||
|
GncGUID *owner_r;
|
||||||
|
|
||||||
|
qof_instance_set (QOF_INSTANCE (fixture->lot),
|
||||||
|
"invoice", invoice,
|
||||||
|
"owner-type", owner_type,
|
||||||
|
"owner-guid", owner,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->lot)));
|
||||||
|
qof_instance_mark_clean (QOF_INSTANCE (fixture->lot));
|
||||||
|
|
||||||
|
qof_instance_get (QOF_INSTANCE (fixture->lot),
|
||||||
|
"invoice", &invoice_r,
|
||||||
|
"owner-type", &owner_type_r,
|
||||||
|
"owner-guid", &owner_r,
|
||||||
|
NULL);
|
||||||
|
g_assert (guid_equal (invoice, invoice_r));
|
||||||
|
g_assert_cmpint (owner_type, ==, owner_type_r);
|
||||||
|
g_assert (guid_equal (owner, owner_r));
|
||||||
|
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->lot)));
|
||||||
|
guid_free (invoice);
|
||||||
|
guid_free (invoice_r);
|
||||||
|
guid_free (owner);
|
||||||
|
guid_free (owner_r);
|
||||||
|
}
|
||||||
|
|
||||||
void test_suite_engine_kvp_properties (void)
|
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, "Account", Fixture, NULL, setup_account, test_account_kvp_properties, teardown);
|
||||||
GNC_TEST_ADD (suitename, "Transaction", Fixture, NULL, setup_trans, test_trans_kvp_properties, teardown);
|
GNC_TEST_ADD (suitename, "Transaction", Fixture, NULL, setup_trans, test_trans_kvp_properties, teardown);
|
||||||
|
GNC_TEST_ADD (suitename, "Lot", Fixture, NULL, setup_lot, test_lot_kvp_properties, teardown);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user