gnucash/src/engine/engine.i

296 lines
7.9 KiB
OpenEdge ABL
Raw Normal View History

%module sw_engine
%{
/* Includes the header in the wrapper code */
#include <config.h>
#include <glib.h>
#include <qof.h>
#include <Query.h>
#include <guile-mappings.h>
#include <gnc-budget.h>
#include <gnc-commodity.h>
#include <gnc-engine.h>
#include <gnc-filepath-utils.h>
#include <gnc-pricedb.h>
#include <gnc-lot.h>
#include <gnc-session-scm.h>
#include <gnc-hooks-scm.h>
#include <engine-helpers.h>
#include <SX-book.h>
#include <kvp-scm.h>
#include "glib-helpers.h"
SCM scm_init_sw_engine_module (void);
%}
%import "base-typemaps.i"
GLIST_HELPER_INOUT(SplitList, SWIGTYPE_p_Split);
GLIST_HELPER_INOUT(TransList, SWIGTYPE_p_Transaction);
GLIST_HELPER_INOUT(LotList, SWIGTYPE_p_GNCLot);
GLIST_HELPER_INOUT(AccountList, SWIGTYPE_p_Account);
GLIST_HELPER_INOUT(PriceList, SWIGTYPE_p_GNCPrice);
// TODO: free PriceList?
GLIST_HELPER_INOUT(CommodityList, SWIGTYPE_p_gnc_commodity);
%typemap(newfree) gchar * "g_free($1);"
/* These need to be here so that they are *before* the function
declarations in the header files, some of which are included by
engine-common.i */
%newobject gnc_account_get_full_name;
%include "engine-common.i"
%inline %{
static const GncGUID * gncPriceGetGUID(GNCPrice *x)
{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
static const GncGUID * gncBudgetGetGUID(GncBudget *x)
{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
%}
/* NB: The object ownership annotations should already cover all the
functions currently used in guile, but not all the functions that are
wrapped. So, we should contract the interface to wrap only the used
functions. */
%delobject gnc_price_list_destroy;
%newobject gnc_pricedb_lookup_latest_any_currency;
%newobject gnc_pricedb_lookup_nearest_in_time_any_currency;
%newobject gnc_pricedb_lookup_latest_before_any_currency;
%newobject gnc_pricedb_get_prices;
%newobject gnc_pricedb_lookup_at_time;
%newobject gnc_pricedb_lookup_day;
%newobject xaccQueryGetSplitsUniqueTrans;
%newobject xaccQueryGetTransactions;
%newobject xaccQueryGetLots;
%newobject xaccSplitGetCorrAccountFullName;
%newobject gnc_numeric_to_string;
%newobject gnc_build_dotgnucash_path;
%newobject gnc_build_book_path;
/* Parse the header file to generate wrappers */
%inline {
static QofIdType QOF_ID_BOOK_SCM (void) { return QOF_ID_BOOK; }
}
%include <engine-helpers.h>
%include <gnc-pricedb.h>
QofSession * qof_session_new (void);
QofBook * qof_session_get_book (QofSession *session);
// TODO: Maybe unroll
void qof_book_kvp_changed (QofBook *book);
// TODO: Unroll/remove
const char *qof_session_get_url (QofSession *session);
extern const char *gnc_default_strftime_date_format;
const char *gnc_print_date (Timespec ts);
GncGUID guid_new_return(void);
%inline {
static QofQuery * qof_query_create_for_splits(void) {
return qof_query_create_for(GNC_ID_SPLIT);
}
}
SplitList * qof_query_run (QofQuery *q);
SplitList * qof_query_last_run (QofQuery *q);
SplitList * qof_query_run_subquery (QofQuery *q, const QofQuery *q);
%typemap(in) QofQueryParamList * "$1 = gnc_query_scm2path($input);"
%include <Query.h>
%ignore qof_query_run;
%ignore qof_query_last_run;
%ignore qof_query_run_subquery;
%include <qofquery.h>
%include <qofquerycore.h>
%include <qofbookslots.h>
%include <qofbook.h>
KvpFrame* qof_book_get_slots(QofBook* book);
%include <gnc-numeric.h>
Timespec timespecCanonicalDayTime(Timespec t);
gchar * gnc_build_dotgnucash_path (const gchar *filename);
gchar * gnc_build_book_path (const gchar *filename);
%include <gnc-budget.h>
%typemap(in) GList * {
SCM path_scm = $input;
GList *path = NULL;
while (!scm_is_null (path_scm))
{
SCM key_scm = SCM_CAR (path_scm);
char *key;
if (!scm_is_string (key_scm))
break;
key = g_strdup (scm_to_locale_string (key_scm));
path = g_list_prepend (path, key);
path_scm = SCM_CDR (path_scm);
}
$1 = g_list_reverse (path);
}
void gnc_quote_source_set_fq_installed (GList *sources_list);
%clear GList *;
%ignore gnc_quote_source_set_fq_installed;
%include <gnc-commodity.h>
%include <gnc-session-scm.h>
void gnc_hook_add_scm_dangler (const gchar *name, SCM proc);
void gnc_hook_run (const gchar *name, gpointer data);
%include <gnc-hooks.h>
Account * gnc_book_get_template_root(QofBook *book);
// KVP stuff
%typemap(in) KvpValue * " $1 = gnc_scm_to_kvp_value_ptr($input); "
%typemap(out) KvpValue * " $result = gnc_kvp_value_ptr_to_scm($1); "
%typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);"
void gnc_kvp_frame_delete_at_path(KvpFrame *frame, GSList *key_path);
void kvp_frame_set_slot_path_gslist(
KvpFrame *frame, const KvpValue *new_value, GSList *key_path);
KvpValue * kvp_frame_get_slot_path_gslist (KvpFrame *frame, GSList *key_path);
%clear GSList *key_path;
%init {
{
char tmp[100];
#define SET_ENUM(e) snprintf(tmp, 100, "(set! %s (%s))", (e), (e)); \
scm_c_eval_string(tmp);
SET_ENUM("TXN-TYPE-NONE");
SET_ENUM("TXN-TYPE-INVOICE");
SET_ENUM("TXN-TYPE-PAYMENT");
SET_ENUM("ACCT-TYPE-INVALID");
SET_ENUM("ACCT-TYPE-NONE");
SET_ENUM("ACCT-TYPE-BANK");
SET_ENUM("ACCT-TYPE-CASH");
SET_ENUM("ACCT-TYPE-CREDIT");
SET_ENUM("ACCT-TYPE-ASSET");
SET_ENUM("ACCT-TYPE-LIABILITY");
SET_ENUM("ACCT-TYPE-STOCK");
SET_ENUM("ACCT-TYPE-MUTUAL");
SET_ENUM("ACCT-TYPE-CURRENCY");
SET_ENUM("ACCT-TYPE-INCOME");
SET_ENUM("ACCT-TYPE-EXPENSE");
SET_ENUM("ACCT-TYPE-EQUITY");
SET_ENUM("ACCT-TYPE-RECEIVABLE");
SET_ENUM("ACCT-TYPE-PAYABLE");
Bug #537476: Implement currency trading accounts optionally, to be enabled per-book. Patch by Mike Alexander: This patch implements trading accounts somewhat as described in Peter Selinger's document at <http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he describes it as a multiple currency problem, it really applies to any transactions involving multiple commodities (for example buying or selling a stock) Hence I've called the trading accounts "commodity exchange accounts" which seems more descriptive. In summary these patches add an option to use commodity exchange accounts and if it is on a transaction must be balanced both in value (in the transaction currency) and in each commodity or currency used in any split in the transaction. If a transaction only contains splits in the transaction currency then this is the same rule as Gnucash has always enforced. In this patch, the option to use trading accounts has been moved from Edit->Preferences to File->Properties and is now associated with the active book instead of being a global option. If you have set the global value on in a previous version you will need to set it on again in each file for which you want trading accounts, the previous global setting will be ignored. A more detailed list of changes follows: 1. Added a "Use commodity exchange accounts" per-book option. 2. Added gnc_monetary and MonetaryList data types. 3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new xaccTransGetImbalance that returns a MonetaryList. Also added xaccTransIsBalanced to see if the transaction is balanced without returning a GList that needs to be freed. It calls both xaccTransGetImbalance and xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to either without being unbalanced with regard to the other. 4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced. 5. Changed gnc_split_register_balance_trans to not offer to adjust an existing split if there imbalances in multiple currencies. Because of bugs in the register code this is rarely called. 6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance, assuming that they won't create multiple currency trasactions. 7. Changed xaccTransScrubImbalance to create a balancing split for each imbalanced commodity in the transaction. Also balances the transaction value. The commodity balancing splits go into accounts in the hierarchy Trading:NAMESPACE:COMMODITY. The value balancing splits go into Imbalance-CURRENCY as before. 8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of xaccTransGetImbalance. 9. Changed gnc_split_register_get_debcred_entry to sometimes use the split amount instead of value if using currency accounts. If the register is a stock register (i.e., shows shares and prices), it uses the value if the split is in the register commodity (i.e. is for the stock) and the amount otherwise. It shows the currency symbol unless the commodity is the default currency. If the register is not a stock register it always uses the amount and shows the currency symbol if the split is not in the register commodity. Also changed it to not return a value for a null split unless the transaction is unbalanced in exactly one currency. This is what goes in a blank split as the proposed value. 10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the imbalance, assuming that importers don't create transactions in multiple currencies. Also same change in gnc_import_process_trans_item, downloaded_transaction_append, and gnc_import_TransInfo_is_balanced. 11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use xaccTransGetImbalanceValue. As far as I can tell this is only used by the "pd-balance" query type in gnc_scm2query_term_query_v1() defined in engine-helpers.c. This query type only tests the result for zero/non-zero. 12. Changed xaccTransGetAccountConvRate to accept any split into the correct commodity instead of insisting on one into the provided account. Then can use it in xaccTransScrubImbalance to set the value of the imbalance split from its amount, however later changed xaccTransScrubImbalance to not use it. Instead it sets the value for the new split correctly to keep the value of the whole transaction balanced. 13. Changed the balance sheet report to include a new option to not compute unrealized gains and losses. 14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything if given a stock register where the value cell doesn't contain the value. 15. Also related to 9, changed gnc_split_register_save_amount_values to set the amount and value fields in the split correctly when using trading accounts. 16. Changed the new account and edit account dialogs to allow any commodity or currency for an income account if using trading accounts. It would be better to add a new account type for trading accounts, but that's a big deal and I'll leave that for later after we see whether this set of changes is going to be accepted or rejected. 17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value is really the split's amount if using trading accounts. 18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity exchange accounts. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 14:11:03 -06:00
SET_ENUM("ACCT-TYPE-ROOT");
SET_ENUM("ACCT-TYPE-TRADING");
SET_ENUM("NUM-ACCOUNT-TYPES");
SET_ENUM("ACCT-TYPE-CHECKING");
SET_ENUM("ACCT-TYPE-SAVINGS");
SET_ENUM("ACCT-TYPE-MONEYMRKT");
SET_ENUM("ACCT-TYPE-CREDITLINE");
SET_ENUM("QOF-QUERY-AND");
SET_ENUM("QOF-QUERY-OR");
SET_ENUM("QUERY-TXN-MATCH-ALL");
SET_ENUM("QUERY-TXN-MATCH-ANY");
SET_ENUM("QOF-GUID-MATCH-ALL");
SET_ENUM("QOF-GUID-MATCH-ANY");
SET_ENUM("QOF-GUID-MATCH-NULL");
SET_ENUM("QOF-GUID-MATCH-NONE");
SET_ENUM("QOF-GUID-MATCH-LIST-ANY");
SET_ENUM("QOF-COMPARE-LT");
SET_ENUM("QOF-COMPARE-LTE");
SET_ENUM("QOF-COMPARE-EQUAL");
SET_ENUM("QOF-COMPARE-GT");
SET_ENUM("QOF-COMPARE-GTE");
SET_ENUM("QOF-COMPARE-NEQ");
SET_ENUM("QOF-NUMERIC-MATCH-ANY");
SET_ENUM("QOF-NUMERIC-MATCH-CREDIT");
SET_ENUM("QOF-NUMERIC-MATCH-DEBIT");
SET_ENUM("QOF-PARAM-BOOK");
SET_ENUM("QOF-PARAM-GUID");
SET_ENUM("QOF-PARAM-KVP");
SET_ENUM("QOF-PARAM-ACTIVE");
SET_ENUM("QOF-PARAM-VERSION");
SET_ENUM("CLEARED-NO");
SET_ENUM("CLEARED-CLEARED");
SET_ENUM("CLEARED-FROZEN");
SET_ENUM("CLEARED-RECONCILED");
SET_ENUM("CLEARED-VOIDED");
SET_ENUM("HOOK-REPORT");
SET_ENUM("HOOK-SAVE-OPTIONS");
//SET_ENUM("GNC-ID-ACCOUNT");
SET_ENUM("QOF-ID-BOOK-SCM");
//SET_ENUM("GNC-ID-BUDGET");
//SET_ENUM("GNC-ID-LOT");
//SET_ENUM("GNC-ID-PRICE");
//SET_ENUM("GNC-ID-SPLIT");
//SET_ENUM("GNC-ID-SCHEDXACTION");
//SET_ENUM("QOF-ID-SESSION");
//SET_ENUM("GNC-ID-TRANS");
SET_ENUM("QUERY-DEFAULT-SORT");
SET_ENUM("SPLIT-LOT");
SET_ENUM("SPLIT-TRANS");
SET_ENUM("SPLIT-ACCOUNT");
SET_ENUM("SPLIT-VALUE");
SET_ENUM("SPLIT-MEMO");
SET_ENUM("SPLIT-DATE-RECONCILED");
SET_ENUM("SPLIT-ACCT-FULLNAME");
SET_ENUM("SPLIT-CORR-ACCT-NAME");
SET_ENUM("SPLIT-CORR-ACCT-CODE");
SET_ENUM("TRANS-DATE-POSTED");
SET_ENUM("TRANS-DESCRIPTION");
SET_ENUM("TRANS-NUM");
Bug #612212: Provide a method to set the default budget Patch by Jeff Kletsky. (Cstim: Accepted even though string freeze is in effect because it was submitted before the freeze. Also, the string additions are very minor.) Summary of Changes: * Initial story related to providing default budget control * Add a "Budgeting" tab to the book-level preferences dialog * Add a "Default Budget" selector to the "Budgeting" tab * Modify gnc_budget_get_default() to * Respect the new KVP, if present * Fall back to 2.2.x behavior, if not present * Modify gnc:make-budget-option * Reformatted for readability with additional comments * Default is now "#f" so that selected value is always saved Otherwise, if selection happened to be the current default and the default was later changed, the report would change * getter, setter, and generate-restore-form all now consistent * setter now always takes a budget object * generate-restore-form does not rely on "hack" in setter that previously allowed either a budget object or a GUID string This is a different fix for 603215 -- see Known Issues * Provide translation support for "Trading Acccounts" (and "Budgeting") * Refactor #define names for consistency and extensibility * KVP_OPTION_PATH for consistency with Guile usage * OPTION_SECTION_blahblah * OPTION_NAME_blahblah * Modify qofbookslots.h to be "SWIG-aware" * Pick up qofbookslots.h in make-gnucash-potfiles.in and po/POTFILES.in Known Issues: * There is no selection (yet) for "Use default budget" so changing the default budget and reloading a report does not change the budget used * setter is no more robust to "bad" values than in previous code * Budget reports created with 2.3.x after r18528 (between 2.3.8 and 2.3.9) may not load or re-render as they relied on the setter taking either a budget object or a GUID as a string This should not impact any 2.2.x users as nothing was saved under 2.2.x related to the default budget. This can be resolved through removing the option restore code in ~/.gnucash/saved-reports-2.4 and, if affected reports were open, in ~/.gnucash/books/<name_of_book> * Budget reports prior to r18528 did not save budget selection (603215) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19123 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-05-06 04:01:46 -05:00
SET_ENUM("KVP-OPTION-PATH");
SET_ENUM("OPTION-SECTION-ACCOUNTS");
SET_ENUM("OPTION-NAME-TRADING-ACCOUNTS");
SET_ENUM("OPTION-SECTION-BUDGETING");
SET_ENUM("OPTION-NAME-DEFAULT-BUDGET");
SET_ENUM("ACCOUNT-CODE-"); /* sic */
SET_ENUM("GNC-HOW-RND-CEIL");
SET_ENUM("GNC-HOW-RND-TRUNC");
SET_ENUM("GNC-HOW-RND-PROMOTE");
SET_ENUM("GNC-HOW-RND-ROUND-HALF-DOWN");
SET_ENUM("GNC-HOW-RND-ROUND-HALF-UP");
SET_ENUM("GNC-HOW-RND-ROUND");
SET_ENUM("GNC-HOW-RND-NEVER");
#undefine SET_ENUM
}
}