mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
New Split properties sx-account, sx-credit-formula, sx-debit-formula
This commit is contained in:
parent
dc8e9c0b00
commit
48df2d3569
@ -375,9 +375,9 @@ gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct)
|
||||
for (; splits != NULL; splits = splits->next)
|
||||
{
|
||||
Split *s = (Split*)splits->data;
|
||||
KvpFrame *frame = kvp_frame_get_frame(xaccSplitGetSlots(s), GNC_SX_ID);
|
||||
GncGUID *sx_split_acct_guid = kvp_frame_get_guid(frame, GNC_SX_ACCOUNT);
|
||||
if (guid_equal(acct_guid, sx_split_acct_guid))
|
||||
GncGUID *guid;
|
||||
qof_instance_get (QOF_INSTANCE (s), "sx-account", &guid, NULL);
|
||||
if (guid_equal(acct_guid, guid))
|
||||
{
|
||||
rtn = g_list_append(rtn, sx);
|
||||
}
|
||||
|
@ -1041,8 +1041,8 @@ pack_split_info (TTSplitInfo *s_info, Account *parent_acct,
|
||||
Transaction *parent_trans, QofBook *book)
|
||||
{
|
||||
Split *split;
|
||||
KvpFrame *split_frame;
|
||||
KvpValue *tmp_value;
|
||||
const gchar *credit_formula;
|
||||
const gchar *debit_formula;
|
||||
const GncGUID *acc_guid;
|
||||
|
||||
split = xaccMallocSplit(book);
|
||||
@ -1058,40 +1058,14 @@ pack_split_info (TTSplitInfo *s_info, Account *parent_acct,
|
||||
xaccAccountInsertSplit(parent_acct,
|
||||
split);
|
||||
|
||||
split_frame = xaccSplitGetSlots(split);
|
||||
|
||||
tmp_value
|
||||
= kvp_value_new_string(gnc_ttsplitinfo_get_credit_formula(s_info));
|
||||
|
||||
kvp_frame_set_slot_path(split_frame,
|
||||
tmp_value,
|
||||
GNC_SX_ID,
|
||||
GNC_SX_CREDIT_FORMULA,
|
||||
NULL);
|
||||
kvp_value_delete(tmp_value);
|
||||
|
||||
tmp_value
|
||||
= kvp_value_new_string(gnc_ttsplitinfo_get_debit_formula(s_info));
|
||||
|
||||
kvp_frame_set_slot_path(split_frame,
|
||||
tmp_value,
|
||||
GNC_SX_ID,
|
||||
GNC_SX_DEBIT_FORMULA,
|
||||
NULL);
|
||||
|
||||
kvp_value_delete(tmp_value);
|
||||
|
||||
credit_formula = gnc_ttsplitinfo_get_credit_formula(s_info);
|
||||
debit_formula = gnc_ttsplitinfo_get_debit_formula(s_info);
|
||||
acc_guid = qof_entity_get_guid(QOF_INSTANCE(gnc_ttsplitinfo_get_account(s_info)));
|
||||
|
||||
tmp_value = kvp_value_new_guid(acc_guid);
|
||||
|
||||
kvp_frame_set_slot_path(split_frame,
|
||||
tmp_value,
|
||||
GNC_SX_ID,
|
||||
GNC_SX_ACCOUNT,
|
||||
NULL);
|
||||
|
||||
kvp_value_delete(tmp_value);
|
||||
qof_instance_set (QOF_INSTANCE (split),
|
||||
"sx-credit-formula", credit_formula,
|
||||
"sx-debit-formula", debit_formula,
|
||||
"sx-account", acc_guid,
|
||||
NULL);
|
||||
|
||||
return split;
|
||||
}
|
||||
|
@ -305,9 +305,6 @@ GList *gnc_sx_get_defer_instances( SchedXaction *sx );
|
||||
|
||||
/* #defines for KvpFrame strings and QOF */
|
||||
#define GNC_SX_ID "sched-xaction"
|
||||
#define GNC_SX_ACCOUNT "account"
|
||||
#define GNC_SX_CREDIT_FORMULA "credit-formula"
|
||||
#define GNC_SX_DEBIT_FORMULA "debit-formula"
|
||||
#define GNC_SX_CREDIT_NUMERIC "credit-numeric"
|
||||
#define GNC_SX_DEBIT_NUMERIC "debit-numeric"
|
||||
#define GNC_SX_SHARES "shares"
|
||||
|
@ -61,6 +61,12 @@ const char *void_former_val_str = "void-former-value";
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
static QofLogModule log_module = GNC_MOD_ENGINE;
|
||||
|
||||
/* KVP key values used for SX info stored Split's slots. */
|
||||
#define GNC_SX_ID "sched-xaction"
|
||||
#define GNC_SX_ACCOUNT "account"
|
||||
#define GNC_SX_CREDIT_FORMULA "credit-formula"
|
||||
#define GNC_SX_DEBIT_FORMULA "debit-formula"
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
@ -71,7 +77,10 @@ enum
|
||||
PROP_RECONCILE_DATE,
|
||||
PROP_TX,
|
||||
PROP_ACCOUNT,
|
||||
PROP_LOT
|
||||
PROP_SX_CREDIT_FORMULA,
|
||||
PROP_SX_DEBIT_FORMULA,
|
||||
PROP_SX_ACCOUNT,
|
||||
PROP_LOT,
|
||||
};
|
||||
|
||||
/* GObject Initialization */
|
||||
@ -127,6 +136,7 @@ gnc_split_get_property(GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
Split *split;
|
||||
gchar *key;
|
||||
|
||||
g_return_if_fail(GNC_IS_SPLIT(object));
|
||||
|
||||
@ -157,6 +167,18 @@ gnc_split_get_property(GObject *object,
|
||||
case PROP_LOT:
|
||||
g_value_take_object(value, split->lot);
|
||||
break;
|
||||
case PROP_SX_CREDIT_FORMULA:
|
||||
key = GNC_SX_ID "/" GNC_SX_CREDIT_FORMULA;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
|
||||
break;
|
||||
case PROP_SX_DEBIT_FORMULA:
|
||||
key = GNC_SX_ID "/" GNC_SX_DEBIT_FORMULA;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
|
||||
break;
|
||||
case PROP_SX_ACCOUNT:
|
||||
key = GNC_SX_ID "/" GNC_SX_ACCOUNT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
@ -171,6 +193,7 @@ gnc_split_set_property(GObject *object,
|
||||
{
|
||||
Split *split;
|
||||
gnc_numeric* number;
|
||||
gchar *key;
|
||||
|
||||
g_return_if_fail(GNC_IS_SPLIT(object));
|
||||
|
||||
@ -203,7 +226,19 @@ gnc_split_set_property(GObject *object,
|
||||
case PROP_LOT:
|
||||
xaccSplitSetLot(split, g_value_get_object(value));
|
||||
break;
|
||||
default:
|
||||
case PROP_SX_CREDIT_FORMULA:
|
||||
key = GNC_SX_ID "/" GNC_SX_CREDIT_FORMULA;
|
||||
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
|
||||
break;
|
||||
case PROP_SX_DEBIT_FORMULA:
|
||||
key = GNC_SX_ID "/" GNC_SX_DEBIT_FORMULA;
|
||||
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
|
||||
break;
|
||||
case PROP_SX_ACCOUNT:
|
||||
key = GNC_SX_ID "/" GNC_SX_ACCOUNT;
|
||||
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
@ -300,6 +335,37 @@ gnc_split_class_init(SplitClass* klass)
|
||||
"The lot that this split belongs to.",
|
||||
GNC_TYPE_LOT,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_MEMO,
|
||||
g_param_spec_string("sx-debit-formula",
|
||||
"Schedule Transaction Debit Formula",
|
||||
"The formula used to calculate the actual debit "
|
||||
"amount when a real split is generated from this "
|
||||
"SX split.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_MEMO,
|
||||
g_param_spec_string("sx-credit-formula",
|
||||
"Schedule Transaction Credit Formula",
|
||||
"The formula used to calculate the actual credit "
|
||||
"amount when a real split is generated from this "
|
||||
"SX split.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_SX_ACCOUNT,
|
||||
g_param_spec_boxed("sx-account",
|
||||
"Scheduled Transaction Account",
|
||||
"The target account for a scheduled transaction split.",
|
||||
GNC_TYPE_GUID,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
|
@ -47,13 +47,14 @@ typedef struct
|
||||
{
|
||||
Account *acct;
|
||||
Transaction *trans;
|
||||
Split *split;
|
||||
GNCLot *lot;
|
||||
GncCustomer *cust;
|
||||
GncEmployee *emp;
|
||||
GncJob *job;
|
||||
GncVendor *vend;
|
||||
};
|
||||
GSList *split;
|
||||
GSList *hdlrs;
|
||||
} Fixture;
|
||||
|
||||
/* Prototype to shut clang up */
|
||||
@ -78,6 +79,13 @@ setup_trans (Fixture *fixture, gconstpointer pData)
|
||||
fixture->trans = xaccMallocTransaction (book);
|
||||
}
|
||||
|
||||
static void
|
||||
setup_split (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
QofBook *book = qof_book_new ();
|
||||
fixture->split = xaccMallocSplit (book);
|
||||
}
|
||||
|
||||
static void
|
||||
setup_lot (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
@ -138,6 +146,39 @@ test_trans_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||
guid_free (guid_r);
|
||||
}
|
||||
|
||||
static void
|
||||
test_split_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
gchar *debit_formula = "e^xdydx";
|
||||
gchar *credit_formula = "seccostansin";
|
||||
gchar *debit_formula_r, *credit_formula_r;
|
||||
GncGUID *sx_account = guid_malloc ();
|
||||
GncGUID *sx_account_r;
|
||||
|
||||
qof_instance_set (QOF_INSTANCE (fixture->split),
|
||||
"sx-debit-formula", debit_formula,
|
||||
"sx-credit-formula", credit_formula,
|
||||
"sx-account", sx_account,
|
||||
NULL);
|
||||
|
||||
g_assert (qof_instance_is_dirty (QOF_INSTANCE (fixture->split)));
|
||||
qof_instance_mark_clean (QOF_INSTANCE (fixture->split));
|
||||
|
||||
qof_instance_get (QOF_INSTANCE (fixture->split),
|
||||
"sx-debit-formula", &debit_formula_r,
|
||||
"sx-credit-formula", &credit_formula_r,
|
||||
"sx-account", &sx_account_r,
|
||||
NULL);
|
||||
g_assert_cmpstr (debit_formula, ==, debit_formula_r);
|
||||
g_assert_cmpstr (credit_formula, ==, credit_formula_r);
|
||||
g_assert (guid_equal (sx_account, sx_account_r));
|
||||
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->split)));
|
||||
g_free (debit_formula_r);
|
||||
g_free (credit_formula_r);
|
||||
guid_free (sx_account);
|
||||
guid_free (sx_account_r);
|
||||
}
|
||||
|
||||
static void
|
||||
test_lot_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
@ -176,5 +217,6 @@ 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);
|
||||
GNC_TEST_ADD (suitename, "Split", Fixture, NULL, setup_split, test_split_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