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

@ -88,6 +88,10 @@ enum
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 */
@ -205,6 +209,22 @@ gnc_split_get_property(GObject *object,
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;
@ -283,6 +303,22 @@ gnc_split_set_property(GObject *object,
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;
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: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break; break;
@ -455,6 +491,47 @@ gnc_split_class_init(SplitClass* klass)
"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,20 +397,16 @@ 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,
*/
gnc_kvp_bag_add (split->inst.kvp_data, "lot-split", now,
"peer_guid", xaccSplitGetGUID (new_split), "peer_guid", xaccSplitGetGUID (new_split),
NULL); NULL);
gnc_kvp_bag_add (new_split->inst.kvp_data, "lot-split", now, qof_instance_set (QOF_INSTANCE (new_split),
"lot-split", now,
"peer_guid", xaccSplitGetGUID (split), "peer_guid", xaccSplitGetGUID (split),
NULL); NULL);
@ -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;