[Transaction.cpp] use qof_instance kvp API for Time64, with bugfix

fixes bug whereby xaccTransRetDateDue returns 0 if the kvp time64
stored is 0.
pull/2107/head
Christopher Lam 11 months ago
parent 985f591830
commit ab04715c91

@ -1988,14 +1988,10 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year)
void
xaccTransSetDateDue (Transaction * trans, time64 time)
{
GValue v = G_VALUE_INIT;
if (!trans) return;
g_value_init (&v, GNC_TYPE_TIME64);
g_value_set_static_boxed (&v, &time);
xaccTransBeginEdit(trans);
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
qof_instance_set_path_kvp<Time64> (QOF_INSTANCE (trans), Time64{time}, {TRANS_DATE_DUE_KVP});
qof_instance_set_dirty(QOF_INSTANCE(trans));
g_value_unset (&v);
xaccTransCommitEdit(trans);
}
@ -2339,18 +2335,9 @@ xaccTransRetDateEntered (const Transaction *trans)
time64
xaccTransRetDateDue(const Transaction *trans)
{
time64 ret = 0;
GValue v = G_VALUE_INIT;
if (!trans) return 0;
qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
if (G_VALUE_HOLDS_BOXED (&v))
{
ret = ((Time64*)g_value_get_boxed (&v))->t;
g_value_unset (&v);
}
if (!ret)
return xaccTransRetDatePosted (trans);
return ret;
auto res = qof_instance_get_path_kvp<Time64> (QOF_INSTANCE (trans), {TRANS_DATE_DUE_KVP});
return res ? res->t : xaccTransRetDatePosted (trans);
}
char

@ -1080,11 +1080,13 @@ qof_instance_set_path_kvp (QofInstance* inst, std::optional<T> value, const Path
qof_instance_set_dirty (inst);
}
template std::optional<Time64> qof_instance_get_path_kvp <Time64> (QofInstance*, const Path&);
template std::optional<const char*> qof_instance_get_path_kvp <const char*> (QofInstance*, const Path&);
template std::optional<gnc_numeric> qof_instance_get_path_kvp <gnc_numeric> (QofInstance*, const Path&);
template std::optional<GncGUID*> qof_instance_get_path_kvp <GncGUID*> (QofInstance*, const Path&);
template std::optional<int64_t> qof_instance_get_path_kvp <int64_t> (QofInstance*, const Path&);
template void qof_instance_set_path_kvp <Time64> (QofInstance*, std::optional<Time64>, const Path& path);
template void qof_instance_set_path_kvp <const char*> (QofInstance*, std::optional<const char*>, const Path& path);
template void qof_instance_set_path_kvp <gnc_numeric> (QofInstance*, std::optional<gnc_numeric>, const Path& path);
template void qof_instance_set_path_kvp <GncGUID*> (QofInstance*, std::optional<GncGUID*>, const Path& path);

@ -1833,8 +1833,7 @@ test_xaccTransGetDateDue (Fixture *fixture, gconstpointer pData)
xaccTransSetDateDue (txn, 0);
g_assert_cmpint (frame->get_slot({TRANS_DATE_DUE_KVP})->get_ptr<Time64>()->t, ==, 0);
// the next line is arguably buggy; shouldn't it return 0 as per kvp value?
g_assert_cmpint (xaccTransRetDateDue(txn), ==, xaccTransRetDatePosted(txn));
g_assert_cmpint (xaccTransRetDateDue(txn), ==, 0);
}
/* xaccTransGetReadOnly C: 7 in 5 Local: 1:0:0

Loading…
Cancel
Save