diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index d2f64c2524..699a8eadf6 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -1478,9 +1478,11 @@ gnc_option_db_set_string_value(GncOptionDB*, const char*, } const QofInstance* -gnc_option_db_lookup_qofinstance_value(GncOptionDB*, const char*, const char*) +gnc_option_db_lookup_qofinstance_value(GncOptionDB* odb, const char* section, + const char* name) { - return nullptr; + auto option{odb->find_option(section, name)}; + return option->get_value(); } SCM diff --git a/libgnucash/app-utils/gnc-optiondb.i b/libgnucash/app-utils/gnc-optiondb.i index 95016fda8e..dcc8de6b72 100644 --- a/libgnucash/app-utils/gnc-optiondb.i +++ b/libgnucash/app-utils/gnc-optiondb.i @@ -116,10 +116,13 @@ scm_from_value(double value) template <> inline SCM scm_from_value(const QofInstance* value) { - auto guid = guid_to_string(qof_instance_get_guid(value)); - auto scm_guid = scm_from_utf8_string(guid); - g_free(guid); - return scm_guid; + if (!value) return SCM_BOOL_F; + auto type{qof_collection_get_type(qof_instance_get_collection(value))}; + auto guid_str{guid_to_string(qof_instance_get_guid(value))}; + auto scm_guid = scm_from_utf8_string(guid_str); + auto scm_type = scm_from_utf8_string(type); + free(guid_str); + return scm_cons(scm_type, scm_guid); } template inline ValueType @@ -157,6 +160,21 @@ scm_to_value(SCM new_value) return scm_to_double(new_value); } +template <> inline const QofInstance* +scm_to_value(SCM new_value) +{ + if (new_value == SCM_BOOL_F || !scm_is_pair(new_value)) + return nullptr; + auto guid_str{scm_to_utf8_stringn(scm_car(new_value), nullptr)}; + auto type{scm_to_utf8_stringn(scm_cdr(new_value), nullptr)}; + GncGUID new_guid; + string_to_guid(guid_str, &new_guid); + free(guid_str); + auto coll{qof_book_get_collection(qof_session_get_book(gnc_get_current_session()), type)}; + free(type); + return qof_collection_lookup_entity(coll, &new_guid); +} + template <>inline SCM scm_from_value(GncOptionAccountList value) {