Convert capital gains kvp access to properties on Split.

This commit is contained in:
John Ralls 2014-05-01 12:41:06 -07:00
parent 44ca77766a
commit 6dfb7febf2
2 changed files with 173 additions and 98 deletions

View File

@ -73,23 +73,27 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
enum enum
{ {
PROP_0, PROP_0,
PROP_TX, /* Table */ PROP_TX, /* Table */
PROP_ACCOUNT, /* Table */ PROP_ACCOUNT, /* Table */
PROP_MEMO, /* Table */ PROP_MEMO, /* Table */
PROP_ACTION, /* Table */ PROP_ACTION, /* Table */
// PROP_RECONCILE_STATE, /* Table */ // PROP_RECONCILE_STATE, /* Table */
PROP_RECONCILE_DATE, /* Table */ PROP_RECONCILE_DATE, /* Table */
PROP_VALUE, /* Table, in 2 fields */ PROP_VALUE, /* Table, in 2 fields */
PROP_SX_ACCOUNT, /* KVP */ PROP_SX_ACCOUNT, /* KVP */
PROP_SX_CREDIT_FORMULA, /* KVP */ PROP_SX_CREDIT_FORMULA, /* KVP */
PROP_SX_CREDIT_NUMERIC, /* KVP */ PROP_SX_CREDIT_NUMERIC, /* KVP */
PROP_SX_DEBIT_FORMULA, /* KVP */ PROP_SX_DEBIT_FORMULA, /* KVP */
PROP_SX_DEBIT_NUMERIC, /* KVP */ PROP_SX_DEBIT_NUMERIC, /* KVP */
PROP_SX_SHARES, /* KVP */ PROP_SX_SHARES, /* KVP */
PROP_LOT, /* KVP */ PROP_LOT, /* KVP */
PROP_ONLINE_ACCOUNT, /* KVP */ PROP_ONLINE_ACCOUNT, /* KVP */
PROP_LOT_SPLIT, /* KVP */
PROP_PEER_GUID, /* KVP */
PROP_GAINS_SPLIT, /* KVP */
PROP_GAINS_SOURCE, /* KVP */
PROP_RUNTIME_0, PROP_RUNTIME_0,
PROP_AMOUNT, /* Runtime */ PROP_AMOUNT, /* Runtime */
}; };
@ -178,33 +182,49 @@ gnc_split_get_property(GObject *object,
g_value_take_object(value, split->lot); g_value_take_object(value, split->lot);
break; break;
case PROP_SX_CREDIT_FORMULA: case PROP_SX_CREDIT_FORMULA:
key = GNC_SX_ID "/" GNC_SX_CREDIT_FORMULA; key = GNC_SX_ID "/" GNC_SX_CREDIT_FORMULA;
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_CREDIT_NUMERIC: case PROP_SX_CREDIT_NUMERIC:
key = GNC_SX_ID "/" GNC_SX_CREDIT_NUMERIC; key = GNC_SX_ID "/" GNC_SX_CREDIT_NUMERIC;
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_DEBIT_FORMULA: case PROP_SX_DEBIT_FORMULA:
key = GNC_SX_ID "/" GNC_SX_DEBIT_FORMULA; key = GNC_SX_ID "/" GNC_SX_DEBIT_FORMULA;
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_DEBIT_NUMERIC: case PROP_SX_DEBIT_NUMERIC:
key = GNC_SX_ID "/" GNC_SX_DEBIT_NUMERIC; key = GNC_SX_ID "/" GNC_SX_DEBIT_NUMERIC;
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_ACCOUNT: case PROP_SX_ACCOUNT:
key = GNC_SX_ID "/" GNC_SX_ACCOUNT; key = GNC_SX_ID "/" GNC_SX_ACCOUNT;
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_SHARES: case PROP_SX_SHARES:
key = GNC_SX_ID "/" GNC_SX_SHARES; key = GNC_SX_ID "/" GNC_SX_SHARES;
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_ONLINE_ACCOUNT: case PROP_ONLINE_ACCOUNT:
key = "online_id"; key = "online_id";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value); qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_LOT_SPLIT:
key = "lot-split";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_PEER_GUID:
key = "peer_guid";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_GAINS_SPLIT:
key = "gains-split";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_GAINS_SOURCE:
key = "gains-source";
qof_instance_get_kvp (QOF_INSTANCE (split), key, value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -225,7 +245,7 @@ gnc_split_set_property(GObject *object,
split = GNC_SPLIT(object); split = GNC_SPLIT(object);
if (prop_id < PROP_RUNTIME_0 && split->parent != NULL) if (prop_id < PROP_RUNTIME_0 && split->parent != NULL)
g_assert (qof_instance_get_editlevel(split->parent)); g_assert (qof_instance_get_editlevel(split->parent));
switch (prop_id) switch (prop_id)
{ {
@ -256,34 +276,50 @@ gnc_split_set_property(GObject *object,
xaccSplitSetLot(split, g_value_get_object(value)); xaccSplitSetLot(split, g_value_get_object(value));
break; break;
case PROP_SX_CREDIT_FORMULA: case PROP_SX_CREDIT_FORMULA:
key = GNC_SX_ID "/" GNC_SX_CREDIT_FORMULA; key = GNC_SX_ID "/" GNC_SX_CREDIT_FORMULA;
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_CREDIT_NUMERIC: case PROP_SX_CREDIT_NUMERIC:
key = GNC_SX_ID "/" GNC_SX_CREDIT_NUMERIC; key = GNC_SX_ID "/" GNC_SX_CREDIT_NUMERIC;
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_DEBIT_FORMULA: case PROP_SX_DEBIT_FORMULA:
key = GNC_SX_ID "/" GNC_SX_DEBIT_FORMULA; key = GNC_SX_ID "/" GNC_SX_DEBIT_FORMULA;
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_DEBIT_NUMERIC: case PROP_SX_DEBIT_NUMERIC:
key = GNC_SX_ID "/" GNC_SX_DEBIT_NUMERIC; key = GNC_SX_ID "/" GNC_SX_DEBIT_NUMERIC;
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_ACCOUNT: case PROP_SX_ACCOUNT:
key = GNC_SX_ID "/" GNC_SX_ACCOUNT; key = GNC_SX_ID "/" GNC_SX_ACCOUNT;
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_SX_SHARES: case PROP_SX_SHARES:
key = GNC_SX_ID "/" GNC_SX_SHARES; key = GNC_SX_ID "/" GNC_SX_SHARES;
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
case PROP_ONLINE_ACCOUNT: case PROP_ONLINE_ACCOUNT:
key = "online_id"; key = "online_id";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value); qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break; break;
default: case PROP_LOT_SPLIT:
key = "lot-split";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_PEER_GUID:
key = "peer_guid";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_GAINS_SPLIT:
key = "gains-split";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
case PROP_GAINS_SOURCE:
key = "gains-source";
qof_instance_set_kvp (QOF_INSTANCE (split), key, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
} }
@ -386,9 +422,9 @@ gnc_split_class_init(SplitClass* klass)
PROP_SX_DEBIT_FORMULA, PROP_SX_DEBIT_FORMULA,
g_param_spec_string("sx-debit-formula", g_param_spec_string("sx-debit-formula",
"Schedule Transaction Debit Formula", "Schedule Transaction Debit Formula",
"The formula used to calculate the actual debit " "The formula used to calculate the actual debit "
"amount when a real split is generated from this " "amount when a real split is generated from this "
"SX split.", "SX split.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
@ -398,7 +434,7 @@ gnc_split_class_init(SplitClass* klass)
g_param_spec_boxed("sx-debit-numeric", g_param_spec_boxed("sx-debit-numeric",
"Scheduled Transaction Debit Numeric", "Scheduled Transaction Debit Numeric",
"Numeric value to plug into the Debit Formula when a " "Numeric value to plug into the Debit Formula when a "
"real split is generated from this SX split.", "real split is generated from this SX split.",
GNC_TYPE_NUMERIC, GNC_TYPE_NUMERIC,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
@ -407,9 +443,9 @@ gnc_split_class_init(SplitClass* klass)
PROP_SX_CREDIT_FORMULA, PROP_SX_CREDIT_FORMULA,
g_param_spec_string("sx-credit-formula", g_param_spec_string("sx-credit-formula",
"Schedule Transaction Credit Formula", "Schedule Transaction Credit Formula",
"The formula used to calculate the actual credit " "The formula used to calculate the actual credit "
"amount when a real split is generated from this " "amount when a real split is generated from this "
"SX split.", "SX split.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
@ -419,7 +455,7 @@ gnc_split_class_init(SplitClass* klass)
g_param_spec_boxed("sx-credit-numeric", g_param_spec_boxed("sx-credit-numeric",
"Scheduled Transaction Credit Numeric", "Scheduled Transaction Credit Numeric",
"Numeric value to plug into the Credit Formula when a " "Numeric value to plug into the Credit Formula when a "
"real split is generated from this SX split.", "real split is generated from this SX split.",
GNC_TYPE_NUMERIC, GNC_TYPE_NUMERIC,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/* FIXME: PROP_SX_SHARES should be stored as a gnc_numeric, but the function /* FIXME: PROP_SX_SHARES should be stored as a gnc_numeric, but the function
@ -433,7 +469,7 @@ gnc_split_class_init(SplitClass* klass)
g_param_spec_string("sx-shares", g_param_spec_string("sx-shares",
"Scheduled Transaction Shares", "Scheduled Transaction Shares",
"Numeric value of shares to insert in a new split when " "Numeric value of shares to insert in a new split when "
"it's generated from this SX split.", "it's generated from this SX split.",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
@ -452,9 +488,50 @@ gnc_split_class_init(SplitClass* klass)
g_param_spec_string ("online-id", g_param_spec_string ("online-id",
"Online Account ID", "Online Account ID",
"The online account which corresponds to this " "The online account which corresponds to this "
"account for OFX/HCBI import", "account for OFX/HCBI import",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_LOT_SPLIT,
g_param_spec_int64 ("lot-split",
"Lot Split",
"Indicates that the split was divided into two "
"splits in order to balance a lot capital gains "
"transaction. Contains a timestamp of the action.",
G_MININT64, G_MAXINT64, 0,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_PEER_GUID,
g_param_spec_boxed ("peer-guid",
"Peer GUID",
"The other split in the division.",
GNC_TYPE_GUID,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_GAINS_SPLIT,
g_param_spec_boxed ("gains-split",
"Gains Split",
"The capital gains split associated with this "
"split when this split represents the proceeds "
"from the sale of a commodity inside a Lot.",
GNC_TYPE_GUID,
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_GAINS_SOURCE,
g_param_spec_boxed ("gains-source",
"Gains Source",
"The source split for which this split this is "
"the gains split. ",
GNC_TYPE_GUID,
G_PARAM_READWRITE));
} }
/********************************************************************\ /********************************************************************\

View File

@ -397,22 +397,18 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
ts = xaccSplitRetDateReconciledTS (split); ts = xaccSplitRetDateReconciledTS (split);
xaccSplitSetDateReconciledTS (new_split, &ts); xaccSplitSetDateReconciledTS (new_split, &ts);
/* We do not copy the KVP tree, as it seems like a dangerous /* Set the lot-split and peer_guid properties on the two
* thing to do. If the user wants to access stuff in the 'old' * splits to indicate that they're linked.
* kvp tree from the 'new' split, they shoudl follow the
* 'split-lot' pointers. Yes, this is complicated, but what
* else can one do ??
*/ */
/* Add kvp markup to indicate that these two splits used qof_instance_set (QOF_INSTANCE (split),
* to be one before being 'split' "lot-split", now,
*/ "peer_guid", xaccSplitGetGUID (new_split),
gnc_kvp_bag_add (split->inst.kvp_data, "lot-split", now, NULL);
"peer_guid", xaccSplitGetGUID (new_split),
NULL);
gnc_kvp_bag_add (new_split->inst.kvp_data, "lot-split", now, qof_instance_set (QOF_INSTANCE (new_split),
"peer_guid", xaccSplitGetGUID (split), "lot-split", now,
NULL); "peer_guid", xaccSplitGetGUID (split),
NULL);
xaccAccountInsertSplit (acc, new_split); xaccAccountInsertSplit (acc, new_split);
xaccTransAppendSplit (trans, new_split); xaccTransAppendSplit (trans, new_split);
@ -489,15 +485,14 @@ xaccSplitAssign (Split *split)
Split * Split *
xaccSplitGetCapGainsSplit (const Split *split) xaccSplitGetCapGainsSplit (const Split *split)
{ {
KvpValue *val;
GncGUID *gains_guid; GncGUID *gains_guid;
Split *gains_split; Split *gains_split;
if (!split) return NULL; if (!split) return NULL;
val = kvp_frame_get_slot (split->inst.kvp_data, "gains-split"); qof_instance_get (QOF_INSTANCE (split),
if (!val) return NULL; "gains-split", &gains_guid,
gains_guid = kvp_value_get_guid (val); NULL);
if (!gains_guid) return NULL; if (!gains_guid) return NULL;
/* Both splits will be in the same collection, so search there. */ /* Both splits will be in the same collection, so search there. */
@ -512,15 +507,14 @@ xaccSplitGetCapGainsSplit (const Split *split)
Split * Split *
xaccSplitGetGainsSourceSplit (const Split *split) xaccSplitGetGainsSourceSplit (const Split *split)
{ {
KvpValue *val;
GncGUID *source_guid; GncGUID *source_guid;
Split *source_split; Split *source_split;
if (!split) return NULL; if (!split) return NULL;
val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source"); qof_instance_get (QOF_INSTANCE (split),
if (!val) return NULL; "gains-source", &source_guid,
source_guid = kvp_value_get_guid (val); NULL);
if (!source_guid) return NULL; if (!source_guid) return NULL;
/* Both splits will be in the same collection, so search there. */ /* Both splits will be in the same collection, so search there. */
@ -819,14 +813,18 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
xaccSplitSetMemo (lot_split, _("Realized Gain/Loss")); xaccSplitSetMemo (lot_split, _("Realized Gain/Loss"));
xaccSplitSetMemo (gain_split, _("Realized Gain/Loss")); xaccSplitSetMemo (gain_split, _("Realized Gain/Loss"));
/* For the new transaction, install KVP markup indicating /* For the new transaction, set the split properties indicating
* that this is the gains transaction that corresponds * that this is the gains transaction that corresponds
* to the gains source. * to the gains source.
*/ */
kvp_frame_set_guid (split->inst.kvp_data, "gains-split", xaccTransBeginEdit (base_txn);
xaccSplitGetGUID (lot_split)); qof_instance_set (QOF_INSTANCE (split),
kvp_frame_set_guid (lot_split->inst.kvp_data, "gains-source", "gains-split", xaccSplitGetGUID (lot_split),
xaccSplitGetGUID (split)); NULL);
xaccTransCommitEdit (base_txn);
qof_instance_set (QOF_INSTANCE (lot_split),
"gains-source", xaccSplitGetGUID (split),
NULL);
} }
else else
@ -882,7 +880,7 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
xaccSplitSetAmount (gain_split, negvalue); xaccSplitSetAmount (gain_split, negvalue);
xaccSplitSetValue (gain_split, negvalue); xaccSplitSetValue (gain_split, negvalue);
/* Some short-cuts to help avoid the above kvp lookup. */ /* Some short-cuts to help avoid the above property lookup. */
split->gains = GAINS_STATUS_CLEAN; split->gains = GAINS_STATUS_CLEAN;
split->gains_split = lot_split; split->gains_split = lot_split;
lot_split->gains = GAINS_STATUS_GAINS; lot_split->gains = GAINS_STATUS_GAINS;