GnuCash 2.4.99
gnucash_core.py
Go to the documentation of this file.
00001 # gnucash_core.py -- High level python wrapper classes for the core parts
00002 #                    of GnuCash
00003 #
00004 # Copyright (C) 2008 ParIT Worker Co-operative <paritinfo@parit.ca>
00005 # This program is free software; you can redistribute it and/or
00006 # modify it under the terms of the GNU General Public License as
00007 # published by the Free Software Foundation; either version 2 of
00008 # the License, or (at your option) any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 # GNU General Public License for more details.
00014 #
00015 # You should have received a copy of the GNU General Public License
00016 # along with this program; if not, contact:
00017 # Free Software Foundation           Voice:  +1-617-542-5942
00018 # 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
00019 # Boston, MA  02110-1301,  USA       gnu@gnu.org
00020 #
00021 # @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca>
00022 # @author Jeff Green,   ParIT Worker Co-operative <jeff@parit.ca>
00023 
00024 # The following is for doxygen
00025 ## @file
00026 #  @brief High level python wrapper classes for the core parts of GnuCash
00027 #  @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca>
00028 #  @author Jeff Green,   ParIT Worker Co-operative <jeff@parit.ca>
00029 #  @ingroup python_bindings
00030 
00031 import gnucash_core_c
00032 
00033 from function_class import \
00034      ClassFromFunctions, extract_attributes_with_prefix, \
00035      default_arguments_decorator, method_function_returns_instance, \
00036      methods_return_instance, process_list_convert_to_instance, \
00037      method_function_returns_instance_list, methods_return_instance_lists
00038 
00039 from gnucash_core_c import gncInvoiceLookup, gncInvoiceGetInvoiceFromTxn, \
00040     gncInvoiceGetInvoiceFromLot, gncEntryLookup, gncInvoiceLookup, \
00041     gncCustomerLookup, gncVendorLookup, gncJobLookup, gncEmployeeLookup, \
00042     gncTaxTableLookup, gncTaxTableLookupByName, gnc_search_invoice_on_id, \
00043     gnc_search_customer_on_id, gnc_search_bill_on_id , gnc_search_vendor_on_id, gncInvoiceNextID
00044 
00045 class GnuCashCoreClass(ClassFromFunctions):
00046     _module = gnucash_core_c
00047 
00048     def do_lookup_create_oo_instance(self, lookup_function, cls, *args):
00049         thing = lookup_function(self.get_instance(), *args)
00050         if thing != None:
00051             thing = cls(instance=thing)
00052         return thing
00053 
00054 
00055 class GnuCashBackendException(Exception):
00056     def __init__(self, msg, errors):
00057         Exception.__init__(self, msg)
00058         self.errors = errors
00059 
00060 class Session(GnuCashCoreClass):
00061     """A GnuCash book editing session
00062 
00063     To commit changes to the session you may need to call save,
00064     (this is always the case with the file backend).
00065 
00066     When you're down with a session you may need to call end()
00067 
00068     Every Session has a Book in the book attribute, which you'll definitely
00069     be interested in, as every GnuCash entity (Transaction, Split, Vendor,
00070     Invoice..) is associated with a particular book where it is stored.
00071     """
00072 
00073     def __init__(self, book_uri=None, ignore_lock=False, is_new=False,
00074                  force_new= False):
00075         """A convenient constructor that allows you to specify a book URI,
00076         begin the session, and load the book.
00077 
00078         This can give you the power of calling
00079         qof_session_new, qof_session_begin, and qof_session_load all in one!
00080 
00081         book_uri can be None to skip the calls to qof_session_begin and
00082         qof_session_load, or it can be a string like "file:/test.xac"
00083 
00084         qof_session_load is only called if is_new is set to False
00085 
00086         is_new is passed to qof_session_begin as the argument create,
00087         and force_new as the argument force. Is_new will create a new
00088         database or file; force will force creation even if it will
00089         destroy an existing dataset.
00090 
00091         ignore_lock is passed to qof_session_begin's argument of the
00092         same name and is used to break an existing lock on a dataset.
00093 
00094 
00095 
00096         This function can raise a GnuCashBackendException. If it does,
00097         you don't need to cleanup and call end() and destroy(), that is handled
00098         for you, and the exception is raised.
00099         """
00100         GnuCashCoreClass.__init__(self)
00101         if book_uri is not None:
00102             try:
00103                 self.begin(book_uri, ignore_lock, is_new, force_new)
00104                 if not is_new:
00105                     self.load()
00106             except GnuCashBackendException, backend_exception:
00107                 self.end()
00108                 self.destroy()
00109                 raise
00110 
00111     def raise_backend_errors(self, called_function="qof_session function"):
00112         """Raises a GnuCashBackendException if there are outstanding
00113         QOF_BACKEND errors.
00114 
00115         set called_function to name the function that was last called
00116         """
00117         errors = self.pop_all_errors()
00118         if errors != ():
00119             raise GnuCashBackendException(
00120                 "call to %s resulted in the "
00121                 "following errors, %s" % (called_function, backend_error_dict[errors[0]]),
00122                 errors )
00123 
00124     def generate_errors(self):
00125         """A generator that yields any outstanding QofBackend errors
00126         """
00127         while self.get_error() is not ERR_BACKEND_NO_ERR:
00128             error = self.pop_error()
00129             yield error
00130 
00131     def pop_all_errors(self):
00132         """Returns any accumulated qof backend errors as a tuple
00133         """
00134         return tuple( self.generate_errors() )
00135 
00136     # STATIC METHODS
00137     @staticmethod
00138     def raise_backend_errors_after_call(function):
00139         """A function decorator that results in a call to
00140         raise_backend_errors after execution.
00141         """
00142         def new_function(self, *args):
00143             return_value = function(self, *args)
00144             self.raise_backend_errors(function.__name__)
00145             return return_value
00146         return new_function
00147 
00148 class Book(GnuCashCoreClass):
00149     """A Book encapsulates all of the GnuCash data, it is the place where
00150     all GnuCash entities (Transaction, Split, Vendor, Invoice...), are
00151     stored. You'll notice that all of the constructors for those entities
00152     need a book to be associated with.
00153 
00154     The most common way to get a book is through the book property in the
00155     Session class, that is, create a session that connects to some storage,
00156     such as through 'my_session = Session('file:my_books.xac')', and access
00157     the book via the book property, 'my_session.book'
00158 
00159     If you would like to create a Book without any backing storage, call the
00160     Book constructor without any parameters, 'Book()'. You can later merge
00161     such a book into a book with actual store by using merge_init.
00162 
00163     Methods of interest
00164     get_root_account -- Returns the root level Account
00165     get_table -- Returns a commodity lookup table, of type GncCommodityTable
00166     """
00167     def InvoiceLookup(self, guid):
00168         from gnucash_business import Invoice
00169         return self.do_lookup_create_oo_instance(
00170             gncInvoiceLookup, Invoice, guid.get_instance() )
00171 
00172     def EntryLookup(self, guid):
00173         from gnucash_business import Entr
00174         return self.do_lookup_create_oo_instance(
00175             gncEntryLookup, Entry, guid.get_instance() )
00176 
00177     def CustomerLookup(self, guid):
00178         from gnucash_business import Customer
00179         return self.do_lookup_create_oo_instance(
00180             gncCustomerLookup, Customer, guid.get_instance())
00181 
00182     def JobLookup(self, guid):
00183         from gnucash_business import Job
00184         return self.do_lookup_create_oo_instance(
00185             gncJobLookup, Job, guid.get_instance() )
00186 
00187     def VendorLookup(self, guid):
00188         from gnucash_business import Vendor
00189         return self.do_lookup_create_oo_instance(
00190             gncVendorLookup, Vendor, guid.get_instance() )
00191 
00192     def EmployeeLookup(self, guid):
00193         from gnucash_business import Employee
00194         return self.do_lookup_create_oo_instance(
00195             gncEmployeeLookup, Employee, guid.get_instance() )
00196 
00197     def TaxTableLookup(self, guid):
00198         from gnucash_business import TaxTable
00199         return self.do_lookup_create_oo_instance(
00200             gncTaxTableLookup, TaxTable, guid.get_instance() )
00201 
00202     def TaxTableLookupByName(self, name):
00203         from gnucash_business import TaxTable
00204         return self.do_lookup_create_oo_instance(
00205             gncTaxTableLookupByName, TaxTable, name)
00206 
00207     def BillLoookupByID(self, id):
00208         from gnucash_business import Bill
00209         return self.do_lookup_create_oo_instance(
00210             gnc_search_bill_on_id, Bill, id)
00211 
00212     def InvoiceLookupByID(self, id):
00213         from gnucash_business import Invoice
00214         return self.do_lookup_create_oo_instance(
00215             gnc_search_invoice_on_id, Invoice, id)
00216 
00217     def CustomerLookupByID(self, id):
00218         from gnucash_business import Customer
00219         return self.do_lookup_create_oo_instance(
00220             gnc_search_customer_on_id, Customer, id)
00221 
00222     def VendorLookupByID(self, id):
00223         from gnucash_business import Vendor
00224         return self.do_lookup_create_oo_instance(
00225             gnc_search_vendor_on_id, Vendor, id)
00226             
00227     def InvoiceNextID(self, customer):
00228       ''' Return the next invoice ID. 
00229       This works but I'm not entirely happy with it.  FIX ME'''
00230       from gnucash.gnucash_core_c import gncInvoiceNextID
00231       return gncInvoiceNextID(self.get_instance(),customer.GetEndOwner().get_instance()[1])
00232       
00233     def BillNextID(self, vendor):
00234       ''' Return the next Bill ID. '''
00235       from gnucash.gnucash_core_c import gncInvoiceNextID
00236       return gncInvoiceNextID(self.get_instance(),vendor.GetEndOwner().get_instance()[1])
00237     
00238 
00239 class GncNumeric(GnuCashCoreClass):
00240     """Object used by GnuCash to store all numbers. Always consists of a
00241     numerator and denominator.
00242 
00243     The constants GNC_DENOM_AUTO,
00244     GNC_HOW_RND_FLOOR, GNC_HOW_RND_CEIL, GNC_HOW_RND_TRUNC,
00245     GNC_HOW_RND_PROMOTE, GNC_HOW_RND_ROUND_HALF_DOWN,
00246     GNC_HOW_RND_ROUND_HALF_UP, GNC_HOW_RND_ROUND, GNC_HOW_RND_NEVER,
00247     GNC_HOW_DENOM_EXACT, GNC_HOW_DENOM_REDUCE, GNC_HOW_DENOM_LCD,
00248     and GNC_HOW_DENOM_FIXED are available for arithmetic
00249     functions like GncNumeric.add
00250 
00251     Look at gnc-numeric.h to see how to use these
00252     """
00253 
00254     def __init__(self, num=0, denom=1, **kargs):
00255         """Constructor that allows you to set the numerator and denominator or
00256         leave them blank with a default value of 0 (not a good idea since there
00257         is currently no way to alter the value after instantiation)
00258         """
00259         GnuCashCoreClass.__init__(self, num, denom, **kargs)
00260         #if INSTANCE_ARG in kargs:
00261         #    GnuCashCoreClass.__init__(**kargs)
00262         #else:
00263         #    self.set_denom(denom) # currently undefined
00264         #    self.set_num(num)     # currently undefined
00265 
00266     def __unicode__(self):
00267         """Returns a human readable numeric value string as UTF8."""
00268         if self.denom() == 0:
00269             return "Division by zero"
00270         else:
00271             value_float = self.to_double() 
00272             value_str   = u"{0:.{1}f}".format(value_float,2) ## The second argument is the precision. It would be nice to be able to make it configurable.
00273             return value_str
00274 
00275     def __str__(self):
00276         """returns a human readable numeric value string as bytes."""
00277         return unicode(self).encode('utf-8')
00278 
00279 class GncPrice(GnuCashCoreClass):
00280     '''
00281     Each priceEach price in the database represents an "instantaneous"
00282     quote for a given commodity with respect to another commodity.
00283     For example, a given price might represent the value of LNUX in USD on 2001-02-03.
00284 
00285     Fields:
00286       * commodity: the item being priced.
00287       * currency: the denomination of the value of the item being priced.
00288       * value: the value of the item being priced.
00289       * time: the time the price was valid.
00290       * source: a string describing the source of the quote. These strings will be something like this:
00291       "Finance::Quote", "user:misc", "user:foo", etc. If the quote came from a user, as a matter of policy,
00292       you *must* prefix the string you give with "user:". For now, the only other reserved values are
00293       "Finance::Quote" and "old-file-import". Any string used must be added to the source_list array in
00294       dialog-price-edit-db.c so that it can be properly translated. (There are unfortunately many strings
00295       in users' databases, so this string must be translated on output instead of always being used in untranslated form).
00296       * type: the type of quote - types possible right now are bid, ask, last, nav, and
00297       unknown.Each price in the database represents an "instantaneous" quote for a given
00298       commodity with respect to another commodity.
00299       For example, a given price might represent the value of LNUX in USD on 2001-02-03.
00300 
00301       See also http://svn.gnucash.org/docs/head/group__Price.html
00302     '''
00303     pass
00304 GncPrice.add_methods_with_prefix('gnc_price_')
00305 
00306 
00307 class GncPriceDB(GnuCashCoreClass):
00308     '''
00309     a simple price database for gnucash.
00310     The PriceDB is intended to be a database of price quotes, or more specifically,
00311     a database of GNCPrices. For the time being, it is still a fairly simple
00312     database supporting only fairly simple queries. It is expected that new
00313     queries will be added as needed, and that there is some advantage to delaying
00314     complex queries for now in the hope that we get a real DB implementation
00315     before they're really needed.
00316 
00317     Every QofBook contains a GNCPriceDB, accessible via gnc_pricedb_get_db.
00318 
00319     Definition in file gnc-pricedb.h.
00320     See also http://svn.gnucash.org/docs/head/gnc-pricedb_8h.html
00321     '''
00322 
00323 GncPriceDB.add_methods_with_prefix('gnc_pricedb_')
00324 PriceDB_dict =  {
00325                 'lookup_latest' : GncPrice,
00326                 'lookup_nearest_in_time' : GncPrice,
00327                 'lookup_latest_before' : GncPrice,
00328                 'convert_balance_latest_price' : GncNumeric,
00329                 'convert_balance_nearest_price' : GncNumeric,
00330                 }
00331 methods_return_instance(GncPriceDB,PriceDB_dict)
00332 GncPriceDB.get_prices = method_function_returns_instance_list(
00333     GncPriceDB.get_prices, GncPrice )
00334 
00335 
00336 class GncCommodity(GnuCashCoreClass): pass
00337 
00338 class GncCommodityTable(GnuCashCoreClass):
00339     """A CommodityTable provides a way to store and lookup commodities.
00340     Commodities are primarily currencies, but other tradable things such as
00341     stocks, mutual funds, and material substances are possible.
00342 
00343     Users of this library should not create their own CommodityTable, instead
00344     the get_table method from the Book class should be used.
00345 
00346     This table is automatically populated with the GnuCash default commodity's
00347     which includes most of the world's currencies.
00348     """
00349 
00350     pass
00351 
00352 class GncCommodityNamespace(GnuCashCoreClass):
00353     pass
00354 
00355 class GncLot(GnuCashCoreClass):
00356     def GetInvoiceFromLot(self):
00357         from gnucash_business import Invoice
00358         return self.do_lookup_create_oo_instance(
00359             gncInvoiceGetInvoiceFromLot, Invoice )
00360 
00361 class Transaction(GnuCashCoreClass):
00362     """A GnuCash Transaction
00363 
00364     Consists of at least one (generally two) splits to represent a transaction
00365     between two accounts.
00366 
00367 
00368     Has a GetImbalance() method that returns a list of all the imbalanced
00369     currencies. Each list item is a two element tuple, the first element is
00370     the imbalanced commodity, the second element is the value.
00371 
00372     Warning, the commodity.get_instance() value can be None when there
00373     is no currency set for the transaction.
00374     """
00375     _new_instance = 'xaccMallocTransaction'
00376     def GetNthSplit(self, n):
00377         return self.GetSplitList().pop(n)
00378 
00379     def GetInvoiceFromTxn(self):
00380         from gnucash_business import Transaction
00381         return self.do_lookup_create_oo_instance(
00382             gncInvoiceGetInvoiceFromTxn, Transaction )
00383 
00384 def decorate_monetary_list_returning_function(orig_function):
00385     def new_function(self):
00386         # warning, item.commodity has been shown to be None
00387         # when the transaction doesn't have a currency
00388         return [(GncCommodity(instance=item.commodity),
00389                  GncNumeric(instance=item.value))
00390                 for item in orig_function(self) ]
00391     return new_function
00392 
00393 class Split(GnuCashCoreClass):
00394     """A GnuCash Split
00395 
00396     The most basic representation of a movement of currency from one account to
00397     another.
00398     """
00399     _new_instance = 'xaccMallocSplit'
00400 
00401 class Account(GnuCashCoreClass):
00402     """A GnuCash Account.
00403 
00404     A fundamental entity in accounting, an Account provides representation
00405     for a financial object, such as a ACCT_TYPE_BANK account, an
00406     ACCT_TYPE_ASSET (like a building),
00407     a ACCT_TYPE_LIABILITY (such as a bank loan), a summary of some type of
00408     ACCT_TYPE_EXPENSE, or a summary of some source of ACCT_TYPE_INCOME .
00409 
00410     The words in upper case are the constants that GnuCash and this library uses
00411     to describe account type. Here is the full list:
00412     ACCT_TYPE_ASSET, ACCT_TYPE_BANK, ACCT_TYPE_CASH, ACCT_TYPE_CHECKING, \
00413     ACCT_TYPE_CREDIT, ACCT_TYPE_EQUITY, ACCT_TYPE_EXPENSE, ACCT_TYPE_INCOME, \
00414     ACCT_TYPE_LIABILITY, ACCT_TYPE_MUTUAL, ACCT_TYPE_PAYABLE, \
00415     ACCT_TYPE_RECEIVABLE, ACCT_TYPE_STOCK, ACCT_TYPE_ROOT, ACCT_TYPE_TRADING
00416 
00417     These are not strings, they are attributes you can import from this
00418     module
00419     """
00420     _new_instance = 'xaccMallocAccount'
00421 
00422 class GUID(GnuCashCoreClass):
00423     _new_instance = 'guid_new_return'
00424 
00425 # Session
00426 Session.add_constructor_and_methods_with_prefix('qof_session_', 'new')
00427 
00428 def one_arg_default_none(function):
00429     return default_arguments_decorator(function, None, None)
00430 Session.decorate_functions(one_arg_default_none, "load", "save")
00431 
00432 Session.decorate_functions( Session.raise_backend_errors_after_call,
00433                             "begin", "load", "save", "end")
00434 Session.get_book = method_function_returns_instance(
00435     Session.get_book, Book )
00436 
00437 Session.book = property( Session.get_book )
00438 
00439 # import all of the session backend error codes into this module
00440 this_module_dict = globals()
00441 for error_name, error_value, error_name_after_prefix in \
00442     extract_attributes_with_prefix(gnucash_core_c, 'ERR_'):
00443     this_module_dict[ error_name ] = error_value
00444 
00445 #backend error codes used for reverse lookup
00446 backend_error_dict = {}
00447 for error_name, error_value, error_name_after_prefix in \
00448     extract_attributes_with_prefix(gnucash_core_c, 'ERR_'):
00449     backend_error_dict[ error_value ] = error_name
00450 
00451 # GncNumeric denominator computation schemes
00452 # Used for the denom argument in arithmetic functions like GncNumeric.add
00453 from gnucash.gnucash_core_c import GNC_DENOM_AUTO
00454 
00455 # GncNumeric rounding instructions
00456 # used for the how argument in arithmetic functions like GncNumeric.add
00457 from gnucash.gnucash_core_c import \
00458     GNC_HOW_RND_FLOOR, GNC_HOW_RND_CEIL, GNC_HOW_RND_TRUNC, \
00459     GNC_HOW_RND_PROMOTE, GNC_HOW_RND_ROUND_HALF_DOWN, \
00460     GNC_HOW_RND_ROUND_HALF_UP, GNC_HOW_RND_ROUND, GNC_HOW_RND_NEVER
00461 
00462 # GncNumeric denominator types
00463 # used for the how argument in arithmetic functions like GncNumeric.add
00464 from gnucash.gnucash_core_c import \
00465     GNC_HOW_DENOM_EXACT, GNC_HOW_DENOM_REDUCE, GNC_HOW_DENOM_LCD, \
00466     GNC_HOW_DENOM_FIXED
00467 
00468 # import account types
00469 from gnucash.gnucash_core_c import \
00470     ACCT_TYPE_ASSET, ACCT_TYPE_BANK, ACCT_TYPE_CASH, ACCT_TYPE_CHECKING, \
00471     ACCT_TYPE_CREDIT, ACCT_TYPE_EQUITY, ACCT_TYPE_EXPENSE, ACCT_TYPE_INCOME, \
00472     ACCT_TYPE_LIABILITY, ACCT_TYPE_MUTUAL, ACCT_TYPE_PAYABLE, \
00473     ACCT_TYPE_RECEIVABLE, ACCT_TYPE_STOCK, ACCT_TYPE_ROOT, ACCT_TYPE_TRADING
00474 
00475 #Book
00476 Book.add_constructor_and_methods_with_prefix('qof_book_', 'new')
00477 Book.add_method('gnc_book_get_root_account', 'get_root_account')
00478 Book.add_method('gnc_book_set_root_account', 'set_root_account')
00479 Book.add_method('gnc_commodity_table_get_table', 'get_table')
00480 Book.add_method('gnc_pricedb_get_db', 'get_price_db')
00481 Book.add_method('qof_book_increment_and_format_counter', 'increment_and_format_counter')
00482 
00483 #Functions that return Account
00484 Book.get_root_account = method_function_returns_instance(
00485     Book.get_root_account, Account )
00486 #Functions that return GncCommodityTable
00487 Book.get_table = method_function_returns_instance(
00488     Book.get_table, GncCommodityTable )
00489 #Functions that return GNCPriceDB
00490 Book.get_price_db = method_function_returns_instance(
00491     Book.get_price_db, GncPriceDB)
00492 
00493 # GncNumeric
00494 GncNumeric.add_constructor_and_methods_with_prefix('gnc_numeric_', 'create')
00495 
00496 gncnumeric_dict =   {
00497                         'same' : GncNumeric,
00498                         'add' : GncNumeric,
00499                         'sub' : GncNumeric,
00500                         'mul' : GncNumeric,
00501                         'div' : GncNumeric,
00502                         'neg' : GncNumeric,
00503                         'abs' : GncNumeric,
00504                         'add_fixed' : GncNumeric,
00505                         'sub_fixed' : GncNumeric,
00506                         'add_with_error' : GncNumeric,
00507                         'sub_with_error' : GncNumeric,
00508                         'mul_with_error' : GncNumeric,
00509                         'div_with_error' : GncNumeric,
00510                         'convert' : GncNumeric,
00511                         'reduce' : GncNumeric
00512                     }
00513 methods_return_instance(GncNumeric, gncnumeric_dict)
00514 
00515 # GncCommodity
00516 GncCommodity.add_constructor_and_methods_with_prefix('gnc_commodity_', 'new')
00517 #Functions that return GncCommodity
00518 GncCommodity.clone = method_function_returns_instance(
00519     GncCommodity.clone, GncCommodity )
00520 
00521 # GncCommodityTable
00522 GncCommodityTable.add_methods_with_prefix('gnc_commodity_table_')
00523 commoditytable_dict =   {
00524                             'lookup' : GncCommodity,
00525                             'lookup_unique' : GncCommodity,
00526                             'find_full' : GncCommodity,
00527                             'insert' : GncCommodity,
00528                             'add_namespace': GncCommodityNamespace,
00529                             'find_namespace': GncCommodityNamespace,
00530                         }
00531 methods_return_instance(GncCommodityTable, commoditytable_dict)
00532 
00533 methods_return_instance_lists(
00534     GncCommodityTable, { 'get_namespaces': GncCommodityNamespace,
00535                          'get_namespaces_list': GncCommodityNamespace,
00536                          'get_commodities': GncCommodity,
00537                          'get_quotable_commodities': GncCommodity,
00538                          
00539                        } )
00540 
00541 # GncCommodityNamespace
00542 GncCommodityNamespace.add_methods_with_prefix('gnc_commodity_namespace_')
00543 GncCommodityNamespace.get_commodity_list = \
00544     method_function_returns_instance_list(
00545     GncCommodityNamespace.get_commodity_list, GncCommodity )
00546 
00547 # GncLot
00548 GncLot.add_constructor_and_methods_with_prefix('gnc_lot_', 'new')
00549 
00550 gnclot_dict =   {
00551                     'get_account' : Account,
00552                     'get_book' : Book,
00553                     'get_earliest_split' : Split,
00554                     'get_latest_split' : Split,
00555                     'get_balance' : GncNumeric,
00556                     'lookup' : GncLot,
00557                     'make_default' : GncLot
00558                 }
00559 methods_return_instance(GncLot, gnclot_dict)
00560 
00561 # Transaction
00562 Transaction.add_methods_with_prefix('xaccTrans')
00563 Transaction.add_method('gncTransGetGUID', 'GetGUID');
00564 
00565 trans_dict =    {
00566                     'GetSplit': Split,
00567                     'FindSplitByAccount': Split,
00568                     'Clone': Transaction,
00569                     'Reverse': Transaction,
00570                     'GetReversedBy': Transaction,
00571                     'GetImbalanceValue': GncNumeric,
00572                     'GetAccountValue': GncNumeric,
00573                     'GetAccountAmount': GncNumeric,
00574                     'GetAccountConvRate': GncNumeric,
00575                     'GetAccountBalance': GncNumeric,
00576                     'GetCurrency': GncCommodity,
00577                     'GetGUID': GUID
00578                 }
00579  
00580 methods_return_instance(Transaction, trans_dict)
00581 methods_return_instance_lists(
00582     Transaction, { 'GetSplitList': Split,
00583                        })
00584 Transaction.decorate_functions(
00585     decorate_monetary_list_returning_function, 'GetImbalance')
00586 
00587 # Split
00588 Split.add_methods_with_prefix('xaccSplit')
00589 Split.add_method('gncSplitGetGUID', 'GetGUID');
00590 
00591 split_dict =    {
00592                     'GetBook': Book,
00593                     'GetAccount': Account,
00594                     'GetParent': Transaction,
00595                     'Lookup': Split,
00596                     'GetOtherSplit': Split,
00597                     'GetAmount': GncNumeric,
00598                     'GetValue': GncNumeric,
00599                     'GetSharePrice': GncNumeric,
00600                     'ConvertAmount': GncNumeric,
00601                     'GetBaseValue': GncNumeric,
00602                     'GetBalance': GncNumeric,
00603                     'GetClearedBalance': GncNumeric,
00604                     'GetReconciledBalance': GncNumeric,
00605                     'VoidFormerAmount': GncNumeric,
00606                     'VoidFormerValue': GncNumeric,
00607                     'GetGUID': GUID
00608                 }
00609 methods_return_instance(Split, split_dict)
00610 
00611 Split.account = property( Split.GetAccount, Split.SetAccount )
00612 Split.parent = property( Split.GetParent, Split.SetParent )
00613 
00614 # Account
00615 Account.add_methods_with_prefix('xaccAccount')
00616 Account.add_methods_with_prefix('gnc_account_')
00617 Account.add_method('gncAccountGetGUID', 'GetGUID');
00618 
00619 account_dict =  {
00620                     'get_book' : Book,
00621                     'Lookup' : Account,
00622                     'get_parent' : Account,
00623                     'get_root' : Account,
00624                     'nth_child' : Account,
00625                     'lookup_by_code' : Account,
00626                     'lookup_by_name' : Account,
00627                     'lookup_by_full_name' : Account,
00628                     'FindTransByDesc' : Transaction,
00629                     'FindSplitByDesc' : Split,
00630                     'GetBalance' : GncNumeric,
00631                     'GetClearedBalance' : GncNumeric,
00632                     'GetReconciledBalance' : GncNumeric,
00633                     'GetPresentBalance' : GncNumeric,
00634                     'GetProjectedMinimumBalance' : GncNumeric,
00635                     'GetBalanceAsOfDate' : GncNumeric,
00636                     'ConvertBalanceToCurrency' : GncNumeric,
00637                     'ConvertBalanceToCurrencyAsOfDate' : GncNumeric,
00638                     'GetBalanceInCurrency' : GncNumeric,
00639                     'GetClearedBalanceInCurrency' : GncNumeric,
00640                     'GetReconciledBalanceInCurrency' : GncNumeric,
00641                     'GetPresentBalanceInCurrency' : GncNumeric,
00642                     'GetProjectedMinimumBalanceInCurrency' : GncNumeric,
00643                     'GetBalanceAsOfDateInCurrency' : GncNumeric,
00644                     'GetBalanceChangeForPeriod' : GncNumeric,
00645                     'GetCommodity' : GncCommodity,
00646                     'GetGUID': GUID
00647                 }
00648 methods_return_instance(Account, account_dict)
00649 methods_return_instance_lists(
00650     Account, { 'GetSplitList': Split,
00651                        })
00652 Account.name = property( Account.GetName, Account.SetName )
00653 
00654 #GUID
00655 GUID.add_methods_with_prefix('guid_')
00656 GUID.add_method('xaccAccountLookup', 'AccountLookup')
00657 GUID.add_method('xaccTransLookup', 'TransLookup')
00658 GUID.add_method('xaccSplitLookup', 'SplitLookup')
00659 
00660 guid_dict = {
00661                 'copy' : GUID,
00662                 'TransLookup': Transaction,
00663                 'AccountLookup': Account,
00664                 'SplitLookup': Split
00665             }
00666 methods_return_instance(GUID, guid_dict)
00667 
00668 #Query
00669 from gnucash_core_c import \
00670     QOF_QUERY_AND, \
00671     QOF_QUERY_OR, \
00672     QOF_QUERY_NAND, \
00673     QOF_QUERY_NOR, \
00674     QOF_QUERY_XOR
00675 
00676 class Query(GnuCashCoreClass):
00677     pass
00678 
00679 Query.add_constructor_and_methods_with_prefix('qof_query_', 'create')
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines