GnuCash  5.6-150-g038405b370+
gnucash_core.py
Go to the documentation of this file.
1 # gnucash_core.py -- High level python wrapper classes for the core parts
2 # of GnuCash
3 #
4 # Copyright (C) 2008 ParIT Worker Co-operative <paritinfo@parit.ca>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of
8 # the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, contact:
17 # Free Software Foundation Voice: +1-617-542-5942
18 # 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
19 # Boston, MA 02110-1301, USA gnu@gnu.org
20 #
21 # @author Mark Jenkins, ParIT Worker Co-operative <mark@parit.ca>
22 # @author Jeff Green, ParIT Worker Co-operative <jeff@parit.ca>
23 
24 # The following is for doxygen
25 
26 
28 
29 
32 
33 
152 
153 
154 
159 
160 import operator
161 
162 from enum import IntEnum
163 from urllib.parse import urlparse
164 
165 from gnucash import gnucash_core_c
166 from gnucash import _sw_core_utils
167 
168 from gnucash.function_class import \
169  ClassFromFunctions, extract_attributes_with_prefix, \
170  default_arguments_decorator, method_function_returns_instance, \
171  methods_return_instance, process_list_convert_to_instance, \
172  method_function_returns_instance_list, methods_return_instance_lists
173 
174 from gnucash.gnucash_core_c import gncInvoiceLookup, gncInvoiceGetInvoiceFromTxn, \
175  gncInvoiceGetInvoiceFromLot, gncEntryLookup, gncInvoiceLookup, \
176  gncCustomerLookup, gncVendorLookup, gncJobLookup, gncEmployeeLookup, \
177  gncTaxTableLookup, gncTaxTableLookupByName, gnc_search_invoice_on_id, \
178  gnc_search_customer_on_id, gnc_search_bill_on_id , \
179  gnc_search_vendor_on_id, gncInvoiceNextID, gncCustomerNextID, \
180  gncVendorNextID, gncTaxTableGetTables, gnc_numeric_zero, \
181  gnc_numeric_create, double_to_gnc_numeric, gnc_numeric_from_string, \
182  gnc_numeric_to_string, gnc_numeric_check
183 
184 from gnucash.deprecation import (
185  deprecated_args_session,
186  deprecated_args_session_init,
187  deprecated_args_session_begin,
188  deprecated
189 )
190 
191 try:
192  import gettext
193 
194  _localedir = _sw_core_utils.gnc_path_get_localedir()
195  gettext.install(_sw_core_utils.GETTEXT_PACKAGE, _localedir)
196 except:
197  print()
198  print("Problem importing gettext!")
199  import traceback
200  import sys
201  exc_type, exc_value, exc_traceback = sys.exc_info()
202  traceback.print_exception(exc_type, exc_value, exc_traceback)
203  print()
204 
205  def _(s):
206  """Null translator function, gettext not available"""
207  return s
208 
209  import builtins
210  builtins.__dict__['_'] = _
211 
212 class GnuCashCoreClass(ClassFromFunctions):
213  _module = gnucash_core_c
214 
215  def do_lookup_create_oo_instance(self, lookup_function, cls, *args):
216  thing = lookup_function(self.get_instance(), *args)
217  if thing != None:
218  thing = cls(instance=thing)
219  return thing
220 
221 
222 class GnuCashBackendException(Exception):
223  def __init__(self, msg, errors):
224  Exception.__init__(self, msg)
225  self.errors = errors
226 
227 
228 class SessionOpenMode(IntEnum):
229  """Mode for opening sessions.
230 
231  This replaces three booleans that were passed in order: ignore_lock, create,
232  and force. It's structured so that one can use it as a bit field with the
233  values in the same order, i.e. ignore_lock = 1 << 2, create_new = 1 << 1, and
234  force_new = 1.
235 
236  enumeration members
237  -------------------
238 
239  SESSION_NORMAL_OPEN = 0 (All False)
240  Open will fail if the URI doesn't exist or is locked.
241 
242  SESSION_NEW_STORE = 2 (False, True, False (create))
243  Create a new store at the URI. It will fail if the store already exists and is found to contain data that would be overwritten.
244 
245  SESSION_NEW_OVERWRITE = 3 (False, True, True (create | force))
246  Create a new store at the URI even if a store already exists there.
247 
248  SESSION_READ_ONLY = 4, (True, False, False (ignore_lock))
249  Open the session read-only, ignoring any existing lock and not creating one if the URI isn't locked.
250 
251  SESSION_BREAK_LOCK = 5 (True, False, True (ignore_lock | force))
252  Open the session, taking over any existing lock.
253 
254  source: lignucash/engine/qofsession.h
255  """
256 
257  SESSION_NORMAL_OPEN = gnucash_core_c.SESSION_NORMAL_OPEN
258  """All False
259  Open will fail if the URI doesn't exist or is locked."""
260 
261  SESSION_NEW_STORE = gnucash_core_c.SESSION_NEW_STORE
262  """False, True, False (create)
263  Create a new store at the URI. It will fail if the store already exists and is found to contain data that would be overwritten."""
264 
265  SESSION_NEW_OVERWRITE = gnucash_core_c.SESSION_NEW_OVERWRITE
266  """False, True, True (create | force)
267  Create a new store at the URI even if a store already exists there."""
268 
269  SESSION_READ_ONLY = gnucash_core_c.SESSION_READ_ONLY
270  """True, False, False (ignore_lock)
271  Open the session read-only, ignoring any existing lock and not creating one if the URI isn't locked."""
272 
273  SESSION_BREAK_LOCK = gnucash_core_c.SESSION_BREAK_LOCK
274  """True, False, True (ignore_lock | force)
275  Open the session, taking over any existing lock."""
276 
277 
278 class PriceSource(IntEnum):
279  """Price source, mirroring the C PriceSource enum in gnc-pricedb.h.
280 
281  Pass a member to GncPrice.set_source().
282  """
283 
284  EDIT_DLG = gnucash_core_c.PRICE_SOURCE_EDIT_DLG
285  FINANCE_QUOTE = gnucash_core_c.PRICE_SOURCE_FQ
286  USER_PRICE = gnucash_core_c.PRICE_SOURCE_USER_PRICE
287  XFER_DLG_VAL = gnucash_core_c.PRICE_SOURCE_XFER_DLG_VAL
288  SPLIT_REG = gnucash_core_c.PRICE_SOURCE_SPLIT_REG
289  SPLIT_IMPORT = gnucash_core_c.PRICE_SOURCE_SPLIT_IMPORT
290  STOCK_SPLIT = gnucash_core_c.PRICE_SOURCE_STOCK_SPLIT
291  STOCK_TRANSACTION = gnucash_core_c.PRICE_SOURCE_STOCK_TRANSACTION
292  INVOICE = gnucash_core_c.PRICE_SOURCE_INVOICE
293  TEMP = gnucash_core_c.PRICE_SOURCE_TEMP
294  INVALID = gnucash_core_c.PRICE_SOURCE_INVALID
295 
296 
298  """A GnuCash book editing session
299 
300  To commit changes to the session you may need to call save,
301  (this is always the case with the file backend).
302 
303  When you're down with a session you may need to call end()
304 
305  Every Session has a Book in the book attribute, which you'll definitely
306  be interested in, as every GnuCash entity (Transaction, Split, Vendor,
307  Invoice..) is associated with a particular book where it is stored.
308  """
309 
310  @deprecated_args_session_init
311  def __init__(self, book_uri=None, mode=None, instance=None, book=None):
312  """!
313  A convenient constructor that allows you to specify a book URI,
314  begin the session, and load the book.
315 
316  This can give you the power of calling
317  qof_session_new, qof_session_begin, and qof_session_load all in one!
318 
319  qof_session_load is only called if url scheme is "xml" and
320  mode is SESSION_NEW_STORE or SESSION_NEW_OVERWRITE
321 
322  @param book_uri must be a string in the form of a URI/URL. The access
323  method specified depends on the loaded backends. Paths may be relative
324  or absolute. If the path is relative, that is if the argument is
325  "file://somefile.xml", then the current working directory is
326  assumed. Customized backends can choose to search other
327  application-specific directories or URI schemes as well.
328  It be None to skip the calls to qof_session_begin and
329  qof_session_load.
330 
331  @param instance argument can be passed if new Session is used as a
332  wrapper for an existing session instance
333 
334  @param mode The SessionOpenMode.
335  @note SessionOpenMode replaces deprecated ignore_lock, is_new and force_new.
336 
337  @par SessionOpenMode
338  `SESSION_NORMAL_OPEN`: Find an existing file or database at the provided uri and
339  open it if it is unlocked. If it is locked post a QOF_BACKEND_LOCKED error.
340  @par
341  `SESSION_NEW_STORE`: Check for an existing file or database at the provided
342  uri and if none is found, create it. If the file or database exists post a
343  QOF_BACKED_STORE_EXISTS and return.
344  @par
345  `SESSION_NEW_OVERWRITE`: Create a new file or database at the provided uri,
346  deleting any existing file or database.
347  @par
348  `SESSION_READ_ONLY`: Find an existing file or database and open it without
349  disturbing the lock if it exists or setting one if not. This will also set a
350  flag on the book that will prevent many elements from being edited and will
351  prevent the backend from saving any edits.
352  @par
353  `SESSION_BREAK_LOCK`: Find an existing file or database, lock it, and open
354  it. If there is already a lock replace it with a new one for this session.
355 
356  @par Errors
357  qof_session_begin() signals failure by queuing errors. After it completes use
358  qof_session_get_error() and test that the value is `ERROR_BACKEND_NONE` to
359  determine that the session began successfully.
360 
361  @exception as begin() and load() are wrapped with raise_backend_errors_after_call()
362  this function can raise a GnuCashBackendException. If it does,
363  you don't need to cleanup and call end() and destroy(), that is handled
364  for you, and the exception is raised.
365  """
366  if instance is not None:
367  GnuCashCoreClass.__init__(self, instance=instance)
368  else:
369  if book is None:
370  book = Book()
371  GnuCashCoreClass.__init__(self, book)
372 
373  if book_uri is not None:
374  try:
375  if mode is None:
376  mode = SessionOpenMode.SESSION_NORMAL_OPEN
377  self.begin(book_uri, mode)
378  is_new = mode in (SessionOpenMode.SESSION_NEW_STORE, SessionOpenMode.SESSION_NEW_OVERWRITE)
379  if not is_new:
380  self.load()
381  except GnuCashBackendException as backend_exception:
382  self.end()
383  self.destroy()
384  raise
385 
386  def __enter__(self):
387  return self
388 
389  def __exit__(self, exc_type, exc_value, traceback):
390  # Roll back changes on exception by not calling save. Only works for XMl backend.
391  if not exc_type:
392  self.save()
393  self.end()
394  self.destroy()
395 
396  def raise_backend_errors(self, called_function="qof_session function"):
397  """Raises a GnuCashBackendException if there are outstanding
398  QOF_BACKEND errors.
399 
400  set called_function to name the function that was last called
401  """
402  errors = self.pop_all_errors()
403  if errors != ():
405  "call to %s resulted in the "
406  "following errors, %s" % (called_function, backend_error_dict[errors[0]]),
407  errors )
408 
409  def generate_errors(self):
410  """A generator that yields any outstanding QofBackend errors
411  """
412  while self.get_error() is not ERR_BACKEND_NO_ERR:
413  error = self.pop_error()
414  yield error
415 
416  def pop_all_errors(self):
417  """Returns any accumulated qof backend errors as a tuple
418  """
419  return tuple( self.generate_errors() )
420 
421  # STATIC METHODS
422  @staticmethod
423  def raise_backend_errors_after_call(function, *args, **kwargs):
424  """A function decorator that results in a call to
425  raise_backend_errors after execution.
426  """
427  def new_function(self, *args, **kwargs):
428  return_value = function(self, *args, **kwargs)
429  self.raise_backend_errors(function.__name__)
430  return return_value
431  return new_function
432 
434  """A Book encapsulates all of the GnuCash data, it is the place where
435  all GnuCash entities (Transaction, Split, Vendor, Invoice...), are
436  stored. You'll notice that all of the constructors for those entities
437  need a book to be associated with.
438 
439  The most common way to get a book is through the book property in the
440  Session class, that is, create a session that connects to some storage,
441  such as through 'my_session = Session('file:my_books.xac')', and access
442  the book via the book property, 'my_session.book'
443 
444  If you would like to create a Book without any backing storage, call the
445  Book constructor without any parameters, 'Book()'. You can later merge
446  such a book into a book with actual store by using merge_init.
447 
448  Methods of interest
449  get_root_account -- Returns the root level Account
450  get_table -- Returns a commodity lookup table, of type GncCommodityTable
451  """
452  def InvoiceLookup(self, guid):
453  from gnucash.gnucash_business import Invoice
454  return self.do_lookup_create_oo_instance(
455  gncInvoiceLookup, Invoice, guid.get_instance() )
456 
457  def EntryLookup(self, guid):
458  from gnucash.gnucash_business import Entry
459  return self.do_lookup_create_oo_instance(
460  gncEntryLookup, Entry, guid.get_instance() )
461 
462  def CustomerLookup(self, guid):
463  from gnucash.gnucash_business import Customer
464  return self.do_lookup_create_oo_instance(
465  gncCustomerLookup, Customer, guid.get_instance())
466 
467  def JobLookup(self, guid):
468  from gnucash.gnucash_business import Job
469  return self.do_lookup_create_oo_instance(
470  gncJobLookup, Job, guid.get_instance() )
471 
472  def VendorLookup(self, guid):
473  from gnucash.gnucash_business import Vendor
474  return self.do_lookup_create_oo_instance(
475  gncVendorLookup, Vendor, guid.get_instance() )
476 
477  def EmployeeLookup(self, guid):
478  from gnucash.gnucash_business import Employee
479  return self.do_lookup_create_oo_instance(
480  gncEmployeeLookup, Employee, guid.get_instance() )
481 
482  def TaxTableLookup(self, guid):
483  from gnucash.gnucash_business import TaxTable
484  return self.do_lookup_create_oo_instance(
485  gncTaxTableLookup, TaxTable, guid.get_instance() )
486 
487  def TaxTableLookupByName(self, name):
488  from gnucash.gnucash_business import TaxTable
489  return self.do_lookup_create_oo_instance(
490  gncTaxTableLookupByName, TaxTable, name)
491 
492  def TaxTableGetTables(self):
493  from gnucash.gnucash_business import TaxTable
494  return [ TaxTable(instance=item) for item in gncTaxTableGetTables(self.instance) ]
495 
496  def BillLookupByID(self, id):
497  from gnucash.gnucash_business import Bill
498  return self.do_lookup_create_oo_instance(
499  gnc_search_bill_on_id, Bill, id)
500 
501  def InvoiceLookupByID(self, id):
502  from gnucash.gnucash_business import Invoice
503  return self.do_lookup_create_oo_instance(
504  gnc_search_invoice_on_id, Invoice, id)
505 
506  def CustomerLookupByID(self, id):
507  from gnucash.gnucash_business import Customer
508  return self.do_lookup_create_oo_instance(
509  gnc_search_customer_on_id, Customer, id)
510 
511  def VendorLookupByID(self, id):
512  from gnucash.gnucash_business import Vendor
513  return self.do_lookup_create_oo_instance(
514  gnc_search_vendor_on_id, Vendor, id)
515 
516  def InvoiceNextID(self, customer):
517  ''' Return the next invoice ID.
518  '''
519  from gnucash.gnucash_core_c import gncInvoiceNextID
520  return gncInvoiceNextID(self.get_instance(),customer.GetEndOwner().get_instance()[1])
521 
522  def BillNextID(self, vendor):
523  ''' Return the next Bill ID. '''
524  from gnucash.gnucash_core_c import gncInvoiceNextID
525  return gncInvoiceNextID(self.get_instance(),vendor.GetEndOwner().get_instance()[1])
526 
527  def CustomerNextID(self):
528  ''' Return the next Customer ID. '''
529  from gnucash.gnucash_core_c import gncCustomerNextID
530  return gncCustomerNextID(self.get_instance())
531 
532  def VendorNextID(self):
533  ''' Return the next Vendor ID. '''
534  from gnucash.gnucash_core_c import gncVendorNextID
535  return gncVendorNextID(self.get_instance())
536 
538  """Object used by GnuCash to store all numbers. Always consists of a
539  numerator and denominator.
540 
541  The constants GNC_DENOM_AUTO,
542  GNC_HOW_RND_FLOOR, GNC_HOW_RND_CEIL, GNC_HOW_RND_TRUNC,
543  GNC_HOW_RND_PROMOTE, GNC_HOW_RND_ROUND_HALF_DOWN,
544  GNC_HOW_RND_ROUND_HALF_UP, GNC_HOW_RND_ROUND, GNC_HOW_RND_NEVER,
545  GNC_HOW_DENOM_EXACT, GNC_HOW_DENOM_REDUCE, GNC_HOW_DENOM_LCD,
546  and GNC_HOW_DENOM_FIXED are available for arithmetic
547  functions like GncNumeric.add
548 
549  Look at gnc-numeric.h to see how to use these
550  """
551 
552  def __init__(self, *args, **kargs):
553  """Constructor that supports the following formats:
554  * No arguments defaulting to zero: eg. GncNumeric() == 0/1
555  * A integer: e.g. GncNumeric(1) == 1/1
556  * Numerator and denominator intager pair: eg. GncNumeric(1, 2) == 1/2
557  * A floating point number: e.g. GncNumeric(0.5) == 1/2
558  * A floating point number with defined conversion: e.g.
559  GncNumeric(0.5, GNC_DENOM_AUTO,
560  GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER) == 1/2
561  * A string: e.g. GncNumeric("1/2") == 1/2
562  """
563  if 'instance' not in kargs:
564  kargs['instance'] = GncNumeric.__args_to_instance(args)
565  GnuCashCoreClass.__init__(self, [], **kargs)
566 
567  def __setattr__(self, name, value):
568  # num and denom are read-only accessor methods, not writable fields.
569  if name in ('num', 'denom'):
570  raise AttributeError(
571  "Cannot assign to '%s': it is a read-only accessor method on "
572  "GncNumeric, not a writable field, so the assignment would not "
573  "change the value. Construct a new value instead, e.g. "
574  "GncNumeric(numerator, denominator)." % name)
575  super().__setattr__(name, value)
576 
577  @staticmethod
578  def __args_to_instance(args):
579  if len(args) == 0:
580  return gnc_numeric_zero()
581  elif len(args) == 1:
582  arg = args[0]
583  if isinstance(arg, int):
584  return gnc_numeric_create(arg, 1)
585  elif isinstance(arg, float):
586  return double_to_gnc_numeric(arg, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER)
587  elif isinstance(arg, str):
588  instance = gnc_numeric_from_string(arg)
589  if gnc_numeric_check(instance):
590  raise TypeError('Failed to convert to GncNumeric: ' + str(args))
591  return instance
592  elif isinstance(arg, GncNumeric):
593  return arg.instance
594  else:
595  raise TypeError('Only single int/float/str/GncNumeric allowed: ' + str(args))
596  elif len(args) == 2:
597  if isinstance(args[0], int) and isinstance(args[1], int):
598  return gnc_numeric_create(*args)
599  else:
600  raise TypeError('Only two ints allowed: ' + str(args))
601  elif len(args) == 3:
602  if isinstance(args[0], float) \
603  and isinstance(args[1], int) \
604  and type(args[2]) == type(GNC_HOW_DENOM_FIXED):
605  return double_to_gnc_numeric(*args)
606  else:
607  raise TypeError('Only (float, int, GNC_HOW_RND_*) allowed: ' + str(args))
608  else:
609  raise TypeError('Required single int/float/str or two ints: ' + str(args))
610 
611  # from https://docs.python.org/3/library/numbers.html#numbers.Integral
612  # and https://github.com/python/cpython/blob/3.7/Lib/fractions.py
613 
614  def _operator_fallbacks(monomorphic_operator, fallback_operator):
615  """fallbacks are not needed except for method name,
616  keep for possible later use"""
617  def forward(a, b):
618  if isinstance(b, GncNumeric):
619  return monomorphic_operator(a, b)
620  if isinstance(b, (int, float)):
621  return monomorphic_operator(a, GncNumeric(b))
622  else:
623  return NotImplemented
624  forward.__name__ = '__' + fallback_operator.__name__ + '__'
625  forward.__doc__ = monomorphic_operator.__doc__
626 
627  def reverse(b, a):
628  # b is self, the right-hand operand; a is the left-hand one.
629  if isinstance(a, (GncNumeric, int, float)):
630  return forward(GncNumeric(a), b)
631  else:
632  return NotImplemented
633  reverse.__name__ = '__r' + fallback_operator.__name__ + '__'
634  reverse.__doc__ = monomorphic_operator.__doc__
635 
636  return forward, reverse
637 
638  def _add(a, b):
639  return a.add(b, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND)
640 
641  def _sub(a, b):
642  return a.sub(b, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND)
643 
644  def _mul(a, b):
645  return a.mul(b, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND)
646 
647  def _div(a, b):
648  return a.div(b, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND)
649 
650  def _floordiv(a, b):
651  return a.div(b, 1, GNC_HOW_RND_FLOOR)
652 
653  __add__, __radd__ = _operator_fallbacks(_add, operator.add)
654  __iadd__ = __add__
655  __sub__, __rsub__ = _operator_fallbacks(_sub, operator.sub)
656  __isub__ = __sub__
657  __mul__, __rmul__ = _operator_fallbacks(_mul, operator.mul)
658  __imul__ = __mul__
659  __truediv__, __rtruediv__ = _operator_fallbacks(_div, operator.truediv)
660  __itruediv__ = __truediv__
661  __floordiv__, __rfloordiv__ = _operator_fallbacks(_floordiv, operator.floordiv)
662  __ifloordiv__ = __floordiv__
663 
664  # Comparisons derived from https://github.com/python/cpython/blob/3.7/Lib/fractions.py
665  def _lt(a, b):
666  return a.compare(b) == -1
667 
668  def _gt(a, b):
669  return a.compare(b) == 1
670 
671  def _le(a, b):
672  return a.compare(b) in (0,-1)
673 
674  def _ge(a, b):
675  return a.compare(b) in (0,1)
676 
677  def _eq(a, b):
678  return a.compare(b) == 0
679 
680  def _richcmp(self, other, op):
681  """Helper for comparison operators, for internal use only.
682  Implement comparison between a GncNumeric instance `self`,
683  and either another GncNumeric instance, an int or a float
684  `other`. If `other` is not an instance of that kind, return
685  NotImplemented. `op` should be one of the six standard
686  comparison operators. The comparisons are based on
687  GncNumeric.compare().
688  """
689  import math
690  if isinstance(other, GncNumeric):
691  return op(other)
692  elif isinstance(other, (int, float)):
693  return op(GncNumeric(other))
694  else:
695  return NotImplemented
696 
697  def __lt__(a, b):
698  """a < b"""
699  return a._richcmp(b, a._lt)
700 
701  def __gt__(a, b):
702  """a > b"""
703  return a._richcmp(b, a._gt)
704 
705  def __le__(a, b):
706  """a <= b"""
707  return a._richcmp(b, a._le)
708 
709  def __ge__(a, b):
710  """a >= b"""
711  return a._richcmp(b, a._ge)
712 
713  def __eq__(a, b):
714  """a == b"""
715  return a._richcmp(b, a._eq)
716 
717  def __bool__(a):
718  """a != 0"""
719  return bool(a.num())
720 
721  def __float__(self):
722  return self.to_double()
723 
724  def __int__(self):
725  return int(self.to_fraction())
726 
727  def __pos__(a):
728  """+a"""
729  return GncNumeric(a.num(), a.denom())
730 
731  def __neg__(a):
732  """-a"""
733  return a.neg()
734 
735  def __abs__(a):
736  """abs(a)"""
737  return a.abs()
738 
739  def to_fraction(self):
740  from fractions import Fraction
741  # A negative denominator multiplies: 3/-100 is 300.
742  if self.denom() < 0:
743  return Fraction(self.num() * -self.denom())
744  return Fraction(self.num(), self.denom())
745 
746  def __str__(self):
747  """Returns a human readable numeric value string as UTF8."""
748  return gnc_numeric_to_string(self.instance)
749 
751  '''
752  Each priceEach price in the database represents an "instantaneous"
753  quote for a given commodity with respect to another commodity.
754  For example, a given price might represent the value of LNUX in USD on 2001-02-03.
755 
756  Fields:
757  * commodity: the item being priced.
758  * currency: the denomination of the value of the item being priced.
759  * value: the value of the item being priced.
760  * time: the time the price was valid.
761  * source: describes how the price was created. The string form used by
762  set_source_string() / get_source_string() must be one of the recognized
763  PriceSource values; set_source_string() raises ValueError otherwise.
764  * type: the type of quote - types possible right now are bid, ask, last, nav, and
765  unknown.Each price in the database represents an "instantaneous" quote for a given
766  commodity with respect to another commodity.
767  For example, a given price might represent the value of LNUX in USD on 2001-02-03.
768 
769  See also https://code.gnucash.org/docs/head/group__Price.html
770  '''
771  _new_instance = 'gnc_price_create'
772 GncPrice.add_methods_with_prefix('gnc_price_')
773 
774 # Deprecate set_source_string() in favour of set_source() with a PriceSource
775 # member. While it exists, guard it: the C setter maps a fixed set of canonical
776 # strings to the PriceSource enum and silently leaves the source unchanged for
777 # anything else, so a typo or obsolete string would change nothing -- detect
778 # that (the round-tripped source no longer equals the input) and raise instead.
779 _gnc_price_set_source_string = GncPrice.set_source_string
780 def _deprecated_set_source_string(self, source):
781  """Deprecated: use set_source() with a PriceSource member.
782 
783  Still raises ValueError if `source` is not a recognized PriceSource string
784  (the underlying C setter would otherwise leave the source unchanged)."""
785  _gnc_price_set_source_string(self, source)
786  if self.get_source_string() != source:
787  raise ValueError(
788  "%r is not a recognized price source string, so set_source_string() "
789  "left the source unchanged. Use set_source() with a PriceSource "
790  "member, e.g. set_source(PriceSource.FINANCE_QUOTE)." % (source,))
791 # Report the deprecation under the public method name, not the wrapper's.
792 _deprecated_set_source_string.__name__ = 'set_source_string'
793 _deprecated_set_source_string.__qualname__ = 'GncPrice.set_source_string'
794 GncPrice.set_source_string = deprecated(
795  "use set_source() with a PriceSource member, e.g. "
796  "price.set_source(PriceSource.FINANCE_QUOTE)")(_deprecated_set_source_string)
797 
798 
800  '''
801  a simple price database for gnucash.
802  The PriceDB is intended to be a database of price quotes, or more specifically,
803  a database of GNCPrices. For the time being, it is still a fairly simple
804  database supporting only fairly simple queries. It is expected that new
805  queries will be added as needed, and that there is some advantage to delaying
806  complex queries for now in the hope that we get a real DB implementation
807  before they're really needed.
808 
809  Every QofBook contains a GNCPriceDB, accessible via gnc_pricedb_get_db.
810 
811  Definition in file gnc-pricedb.h.
812  See also https://code.gnucash.org/docs/head/gnc-pricedb_8h.html
813  '''
814 
815 @deprecated("Use gnc_pricedb_latest_before_t64")
816 def gnc_pricedb_lookup_latest_before_t64(self, commodity, currency, date):
817  return self.lookup_nearest_before_t64(commodity, currency, date)
818 
819 GncPriceDB.add_method('gnc_pricedb_lookup_latest_before_t64', 'lookup_latest_before_t64')
820 
821 GncPriceDB.lookup_latest_before_t64 = method_function_returns_instance(GncPriceDB.lookup_latest_before_t64, GncPrice)
822 
823 GncPriceDB.add_methods_with_prefix('gnc_pricedb_')
824 PriceDB_dict = {
825  'lookup_latest' : GncPrice,
826  'lookup_nearest_in_time64' : GncPrice,
827  'lookup_nearest_before_t64' : GncPrice,
828  'nth_price' : GncPrice,
829  'lookup_day_t64' : GncPrice,
830  'convert_balance_latest_price' : GncNumeric,
831  'convert_balance_nearest_price_t64' : GncNumeric,
832  'convert_balance_nearest_before_price_t64' : GncNumeric,
833  'get_latest_price' : GncNumeric,
834  'get_nearest_price' : GncNumeric,
835  'get_nearest_before_price' : GncNumeric,
836  }
837 methods_return_instance(GncPriceDB,PriceDB_dict)
838 methods_return_instance_lists(
839  GncPriceDB, { 'get_prices': GncPrice,
840  'lookup_latest_any_currency': GncPrice,
841  'lookup_nearest_before_any_currency_t64': GncPrice,
842  'lookup_nearest_in_time_any_currency_t64': GncPrice,
843  })
844 
846 
848  """A CommodityTable provides a way to store and lookup commodities.
849  Commodities are primarily currencies, but other tradable things such as
850  stocks, mutual funds, and material substances are possible.
851 
852  Users of this library should not create their own CommodityTable, instead
853  the get_table method from the Book class should be used.
854 
855  This table is automatically populated with the GnuCash default commodity's
856  which includes most of the world's currencies.
857  """
858 
859  def _get_namespaces_py(self):
860  return [ns.get_name() for ns in self.get_namespaces_list()]
861 
863  pass
864 
865 class GncLot(GnuCashCoreClass):
866  def GetInvoiceFromLot(self):
867  from gnucash.gnucash_business import Invoice
868  return self.do_lookup_create_oo_instance(
869  gncInvoiceGetInvoiceFromLot, Invoice )
870 
872  """A GnuCash Transaction
873 
874  Consists of at least one (generally two) splits to represent a transaction
875  between two accounts.
876 
877 
878  Has a GetImbalance() method that returns a list of all the imbalanced
879  currencies. Each list item is a two element tuple, the first element is
880  the imbalanced commodity, the second element is the value.
881 
882  Warning, the commodity.get_instance() value can be None when there
883  is no currency set for the transaction.
884  """
885  _new_instance = 'xaccMallocTransaction'
886  def GetNthSplit(self, n):
887  return self.GetSplitList().pop(n)
888 
889  def GetInvoiceFromTxn(self):
890  from gnucash.gnucash_business import Invoice
891  return self.do_lookup_create_oo_instance(
892  gncInvoiceGetInvoiceFromTxn, Invoice )
893 
894  def __eq__(self, other):
895  return self.Equal(other, True, False, False, False)
896 
897 def decorate_monetary_list_returning_function(orig_function):
898  def new_function(self, *args):
899  """decorate function that returns list of gnc_monetary to return tuples of GncCommodity and GncNumeric
900 
901  Args:
902  *args: Variable length argument list. Will get passed to orig_function
903 
904  Returns:
905  array of tuples: (GncCommodity, GncNumeric)
906 
907  ToDo:
908  Maybe this function should better reside in module function_class (?)"""
909  # warning, item.commodity has been shown to be None
910  # when the transaction doesn't have a currency
911  return [(GncCommodity(instance=item.commodity),
912  GncNumeric(instance=item.value))
913  for item in orig_function(self, *args) ]
914  return new_function
915 
917  """A GnuCash Split
918 
919  The most basic representation of a movement of currency from one account to
920  another.
921  """
922  _new_instance = 'xaccMallocSplit'
923 
924  def __eq__(self, other):
925  return self.Equal(other, True, False, False)
926 
928  """A GnuCash Account.
929 
930  A fundamental entity in accounting, an Account provides representation
931  for a financial object, such as a ACCT_TYPE_BANK account, an
932  ACCT_TYPE_ASSET (like a building),
933  a ACCT_TYPE_LIABILITY (such as a bank loan), a summary of some type of
934  ACCT_TYPE_EXPENSE, or a summary of some source of ACCT_TYPE_INCOME .
935 
936  The words in upper case are the constants that GnuCash and this library uses
937  to describe account type. Here is the full list:
938  ACCT_TYPE_ASSET, ACCT_TYPE_BANK, ACCT_TYPE_CASH, ACCT_TYPE_CHECKING, \
939  ACCT_TYPE_CREDIT, ACCT_TYPE_EQUITY, ACCT_TYPE_EXPENSE, ACCT_TYPE_INCOME, \
940  ACCT_TYPE_LIABILITY, ACCT_TYPE_MUTUAL, ACCT_TYPE_PAYABLE, \
941  ACCT_TYPE_RECEIVABLE, ACCT_TYPE_STOCK, ACCT_TYPE_ROOT, ACCT_TYPE_TRADING
942 
943  These are not strings, they are attributes you can import from this
944  module
945  """
946  _new_instance = 'xaccMallocAccount'
947 
949  _new_instance = 'guid_new_return'
950 
951 # Session
952 Session.add_constructor_and_methods_with_prefix('qof_session_', 'new')
953 
954 def one_arg_default_none(function):
955  return default_arguments_decorator(function, None, None)
956 Session.decorate_functions(one_arg_default_none, "load", "save")
957 
958 Session.decorate_functions( Session.raise_backend_errors_after_call,
959  "begin", "load", "save", "end")
960 Session.decorate_method(default_arguments_decorator, "begin", None, mode=SessionOpenMode.SESSION_NORMAL_OPEN)
961 Session.decorate_functions(deprecated_args_session_begin, "begin")
962 
963 Session.get_book = method_function_returns_instance(
964  Session.get_book, Book )
965 
966 Session.book = property( Session.get_book )
967 
968 # import all of the session backend error codes into this module
969 this_module_dict = globals()
970 for error_name, error_value, error_name_after_prefix in \
971  extract_attributes_with_prefix(gnucash_core_c, 'ERR_'):
972  this_module_dict[ error_name ] = error_value
973 
974 #backend error codes used for reverse lookup
975 backend_error_dict = {}
976 for error_name, error_value, error_name_after_prefix in \
977  extract_attributes_with_prefix(gnucash_core_c, 'ERR_'):
978  backend_error_dict[ error_value ] = error_name
979 
980 # GncNumeric denominator computation schemes
981 # Used for the denom argument in arithmetic functions like GncNumeric.add
982 from gnucash.gnucash_core_c import GNC_DENOM_AUTO
983 
984 # GncNumeric rounding instructions
985 # used for the how argument in arithmetic functions like GncNumeric.add
986 from gnucash.gnucash_core_c import \
987  GNC_HOW_RND_FLOOR, GNC_HOW_RND_CEIL, GNC_HOW_RND_TRUNC, \
988  GNC_HOW_RND_PROMOTE, GNC_HOW_RND_ROUND_HALF_DOWN, \
989  GNC_HOW_RND_ROUND_HALF_UP, GNC_HOW_RND_ROUND, GNC_HOW_RND_NEVER
990 
991 # GncNumeric denominator types
992 # used for the how argument in arithmetic functions like GncNumeric.add
993 from gnucash.gnucash_core_c import \
994  GNC_HOW_DENOM_EXACT, GNC_HOW_DENOM_REDUCE, GNC_HOW_DENOM_LCD, \
995  GNC_HOW_DENOM_FIXED, GNC_HOW_DENOM_SIGFIG
996 
997 # import account types
998 from gnucash.gnucash_core_c import \
999  ACCT_TYPE_ASSET, ACCT_TYPE_BANK, ACCT_TYPE_CASH, ACCT_TYPE_CHECKING, \
1000  ACCT_TYPE_CREDIT, ACCT_TYPE_EQUITY, ACCT_TYPE_EXPENSE, ACCT_TYPE_INCOME, \
1001  ACCT_TYPE_LIABILITY, ACCT_TYPE_MUTUAL, ACCT_TYPE_PAYABLE, \
1002  ACCT_TYPE_RECEIVABLE, ACCT_TYPE_STOCK, ACCT_TYPE_ROOT, ACCT_TYPE_TRADING
1003 
1004 #Book
1005 Book.add_constructor_and_methods_with_prefix('qof_book_', 'new')
1006 Book.add_method('gnc_book_get_root_account', 'get_root_account')
1007 Book.add_method('gnc_book_set_root_account', 'set_root_account')
1008 Book.add_method('gnc_commodity_table_get_table', 'get_table')
1009 Book.add_method('gnc_pricedb_get_db', 'get_price_db')
1010 Book.add_method('qof_book_increment_and_format_counter', 'increment_and_format_counter')
1011 
1012 #Functions that return Account
1013 Book.get_root_account = method_function_returns_instance(
1014  Book.get_root_account, Account )
1015 #Functions that return GncCommodityTable
1016 Book.get_table = method_function_returns_instance(
1017  Book.get_table, GncCommodityTable )
1018 #Functions that return GNCPriceDB
1019 Book.get_price_db = method_function_returns_instance(
1020  Book.get_price_db, GncPriceDB)
1021 
1022 # GncNumeric
1023 GncNumeric.add_constructor_and_methods_with_prefix('gnc_numeric_', 'create')
1024 
1025 gncnumeric_dict = {
1026  'same' : GncNumeric,
1027  'add' : GncNumeric,
1028  'sub' : GncNumeric,
1029  'mul' : GncNumeric,
1030  'div' : GncNumeric,
1031  'neg' : GncNumeric,
1032  'abs' : GncNumeric,
1033  'add_fixed' : GncNumeric,
1034  'sub_fixed' : GncNumeric,
1035  'convert' : GncNumeric,
1036  'reduce' : GncNumeric,
1037  'invert' : GncNumeric
1038  }
1039 methods_return_instance(GncNumeric, gncnumeric_dict)
1040 
1041 # GncCommodity
1042 GncCommodity.add_constructor_and_methods_with_prefix('gnc_commodity_', 'new')
1043 gnc_commodity_dict = {
1044  'clone': GncCommodity,
1045  'obtain_twin': GncCommodity,
1046  'get_namespace_ds': GncCommodityNamespace,
1047  }
1048 methods_return_instance(GncCommodity, gnc_commodity_dict)
1049 
1050 # GncPrice (deferred until after GncCommodity is defined)
1051 gnc_price_dict = {
1052  'get_commodity': GncCommodity,
1053  'get_currency': GncCommodity,
1054  'clone': GncPrice,
1055  'get_value': GncNumeric,
1056  }
1057 methods_return_instance(GncPrice, gnc_price_dict)
1058 
1059 # GncCommodityTable
1060 GncCommodityTable.add_methods_with_prefix('gnc_commodity_table_')
1061 commoditytable_dict = {
1062  'lookup' : GncCommodity,
1063  'lookup_unique' : GncCommodity,
1064  'find_full' : GncCommodity,
1065  'insert' : GncCommodity,
1066  'add_namespace': GncCommodityNamespace,
1067  'find_namespace': GncCommodityNamespace,
1068  }
1069 methods_return_instance(GncCommodityTable, commoditytable_dict)
1070 
1071 methods_return_instance_lists(
1072  GncCommodityTable, { 'get_namespaces_list': GncCommodityNamespace,
1073  'get_commodities': GncCommodity,
1074  'get_quotable_commodities': GncCommodity,
1075 
1076  } )
1077 setattr(GncCommodityTable, 'get_namespaces', getattr(GncCommodityTable, '_get_namespaces_py'))
1078 
1079 # GncCommodityNamespace
1080 GncCommodityNamespace.add_methods_with_prefix('gnc_commodity_namespace_')
1081 GncCommodityNamespace.get_commodity_list = \
1082  method_function_returns_instance_list(
1083  GncCommodityNamespace.get_commodity_list, GncCommodity )
1084 
1085 # GncLot
1086 GncLot.add_constructor_and_methods_with_prefix('gnc_lot_', 'new')
1087 
1088 gnclot_dict = {
1089  'get_account' : Account,
1090  'get_book' : Book,
1091  'get_earliest_split' : Split,
1092  'get_latest_split' : Split,
1093  'get_balance' : GncNumeric,
1094  'lookup' : GncLot,
1095  'make_default' : GncLot
1096  }
1097 methods_return_instance(GncLot, gnclot_dict)
1098 methods_return_instance_lists(
1099  GncLot, { 'get_split_list': Split,
1100  })
1101 
1102 # Transaction
1103 Transaction.add_methods_with_prefix('xaccTrans')
1104 Transaction.add_method('gncTransGetGUID', 'GetGUID')
1105 
1106 Transaction.add_method('xaccTransGetDescription', 'GetDescription')
1107 Transaction.add_method('xaccTransDestroy', 'Destroy')
1108 
1109 trans_dict = {
1110  'GetSplit': Split,
1111  'FindSplitByAccount': Split,
1112  'Clone': Transaction,
1113  'Reverse': Transaction,
1114  'GetReversedBy': Transaction,
1115  'GetImbalanceValue': GncNumeric,
1116  'GetAccountValue': GncNumeric,
1117  'GetAccountAmount': GncNumeric,
1118  'GetAccountConvRate': GncNumeric,
1119  'GetAccountBalance': GncNumeric,
1120  'GetCurrency': GncCommodity,
1121  'GetGUID': GUID
1122  }
1123 
1124 methods_return_instance(Transaction, trans_dict)
1125 methods_return_instance_lists(
1126  Transaction, { 'GetSplitList': Split,
1127  })
1128 Transaction.decorate_functions(
1129  decorate_monetary_list_returning_function, 'GetImbalance')
1130 
1131 # Split
1132 Split.add_methods_with_prefix('xaccSplit')
1133 Split.add_method('gncSplitGetGUID', 'GetGUID')
1134 Split.add_method('xaccSplitDestroy', 'Destroy')
1135 
1136 split_dict = {
1137  'GetBook': Book,
1138  'GetAccount': Account,
1139  'GetParent': Transaction,
1140  'Lookup': Split,
1141  'GetOtherSplit': Split,
1142  'GetAmount': GncNumeric,
1143  'GetValue': GncNumeric,
1144  'GetSharePrice': GncNumeric,
1145  'ConvertAmount': GncNumeric,
1146  'GetBaseValue': GncNumeric,
1147  'GetBalance': GncNumeric,
1148  'GetClearedBalance': GncNumeric,
1149  'GetReconciledBalance': GncNumeric,
1150  'VoidFormerAmount': GncNumeric,
1151  'VoidFormerValue': GncNumeric,
1152  'GetNoclosingBalance': GncNumeric,
1153  'GetCapGains': GncNumeric,
1154  'GetGUID': GUID
1155  }
1156 methods_return_instance(Split, split_dict)
1157 
1158 Split.account = property( Split.GetAccount, Split.SetAccount )
1159 Split.parent = property( Split.GetParent, Split.SetParent )
1160 
1161 # Account
1162 Account.add_methods_with_prefix('xaccAccount')
1163 Account.add_methods_with_prefix('gnc_account_')
1164 Account.add_method('gncAccountGetGUID', 'GetGUID')
1165 Account.add_method('xaccAccountGetPlaceholder', 'GetPlaceholder')
1166 
1167 account_dict = {
1168  'get_book' : Book,
1169  'Lookup' : Account,
1170  'get_parent' : Account,
1171  'get_root' : Account,
1172  'nth_child' : Account,
1173  'lookup_by_code' : Account,
1174  'lookup_by_name' : Account,
1175  'lookup_by_full_name' : Account,
1176  'FindTransByDesc' : Transaction,
1177  'FindSplitByDesc' : Split,
1178  'GetBalance' : GncNumeric,
1179  'GetClearedBalance' : GncNumeric,
1180  'GetReconciledBalance' : GncNumeric,
1181  'GetPresentBalance' : GncNumeric,
1182  'GetProjectedMinimumBalance' : GncNumeric,
1183  'GetBalanceAsOfDate' : GncNumeric,
1184  'ConvertBalanceToCurrency' : GncNumeric,
1185  'ConvertBalanceToCurrencyAsOfDate' : GncNumeric,
1186  'GetBalanceInCurrency' : GncNumeric,
1187  'GetClearedBalanceInCurrency' : GncNumeric,
1188  'GetReconciledBalanceInCurrency' : GncNumeric,
1189  'GetPresentBalanceInCurrency' : GncNumeric,
1190  'GetProjectedMinimumBalanceInCurrency' : GncNumeric,
1191  'GetBalanceAsOfDateInCurrency' : GncNumeric,
1192  'GetBalanceChangeForPeriod' : GncNumeric,
1193  'GetCommodity' : GncCommodity,
1194  'get_currency_or_parent' : GncCommodity,
1195  'GetGUID': GUID
1196  }
1197 methods_return_instance(Account, account_dict)
1198 methods_return_instance_lists(
1199  Account, { 'GetSplitList': Split,
1200  'GetLotList': GncLot,
1201  'get_children': Account,
1202  'get_children_sorted': Account,
1203  'get_descendants': Account,
1204  'get_descendants_sorted': Account
1205  })
1206 Account.name = property( Account.GetName, Account.SetName )
1207 
1208 #GUID
1209 GUID.add_methods_with_prefix('guid_')
1210 GUID.add_method('xaccAccountLookup', 'AccountLookup')
1211 GUID.add_method('xaccTransLookup', 'TransLookup')
1212 GUID.add_method('xaccSplitLookup', 'SplitLookup')
1213 
1214 
1215 GUID.add_method('guid_to_string', 'to_string')
1216 #GUID.add_method('string_to_guid', 'string_to_guid')
1217 
1218 guid_dict = {
1219  'copy' : GUID,
1220  'TransLookup': Transaction,
1221  'AccountLookup': Account,
1222  'SplitLookup': Split
1223  }
1224 methods_return_instance(GUID, guid_dict)
1225 
1226 #GUIDString
1228  pass
1229 
1230 GUIDString.add_constructor_and_methods_with_prefix('string_', 'to_guid')
1231 
1232 #Query
1233 from gnucash.gnucash_core_c import \
1234  QOF_QUERY_AND, \
1235  QOF_QUERY_OR, \
1236  QOF_QUERY_NAND, \
1237  QOF_QUERY_NOR, \
1238  QOF_QUERY_XOR
1239 
1240 from gnucash.gnucash_core_c import \
1241  QOF_STRING_MATCH_NORMAL, \
1242  QOF_STRING_MATCH_CASEINSENSITIVE
1243 
1244 from gnucash.gnucash_core_c import \
1245  QOF_COMPARE_LT, \
1246  QOF_COMPARE_LTE, \
1247  QOF_COMPARE_EQUAL, \
1248  QOF_COMPARE_GT, \
1249  QOF_COMPARE_GTE, \
1250  QOF_COMPARE_NEQ, \
1251  QOF_COMPARE_CONTAINS, \
1252  QOF_COMPARE_NCONTAINS
1253 
1254 from gnucash.gnucash_core_c import \
1255  QOF_DATE_MATCH_NORMAL, \
1256  QOF_DATE_MATCH_DAY
1257 
1258 from gnucash.gnucash_core_c import \
1259  QOF_NUMERIC_MATCH_DEBIT, \
1260  QOF_NUMERIC_MATCH_CREDIT, \
1261  QOF_NUMERIC_MATCH_ANY
1262 
1263 from gnucash.gnucash_core_c import \
1264  QOF_GUID_MATCH_ANY, \
1265  QOF_GUID_MATCH_NONE, \
1266  QOF_GUID_MATCH_NULL, \
1267  QOF_GUID_MATCH_ALL, \
1268  QOF_GUID_MATCH_LIST_ANY
1269 
1270 from gnucash.gnucash_core_c import \
1271  QOF_CHAR_MATCH_ANY, \
1272  QOF_CHAR_MATCH_NONE
1273 
1274 from gnucash.gnucash_core_c import \
1275  INVOICE_TYPE
1276 
1277 from gnucash.gnucash_core_c import \
1278  INVOICE_IS_PAID
1279 
1281 
1282  def search_for(self, obj_type):
1283  """Set search_for to obj_type
1284 
1285  calls qof_query_search_for. Buffers search string for queries lifetime.
1286  @see https://bugs.gnucash.org/show_bug.cgi?id=796137"""
1287  self.__search_for_buf = obj_type
1288  self._search_for(self.__search_for_buf)
1289 
1290 Query.add_constructor_and_methods_with_prefix('qof_query_', 'create', exclude=["qof_query_search_for"])
1291 
1292 Query.add_method('qof_query_set_book', 'set_book')
1293 Query.add_method('qof_query_search_for', '_search_for')
1294 Query.add_method('qof_query_run', 'run')
1295 Query.add_method('qof_query_add_term', 'add_term')
1296 Query.add_method('qof_query_add_boolean_match', 'add_boolean_match')
1297 Query.add_method('qof_query_add_guid_list_match', 'add_guid_list_match')
1298 Query.add_method('qof_query_add_guid_match', 'add_guid_match')
1299 Query.add_method('qof_query_destroy', 'destroy')
1300 
1302  pass
1303 
1304 QueryStringPredicate.add_constructor_and_methods_with_prefix(
1305  'qof_query_','string_predicate')
1306 
1308  pass
1309 
1310 QueryBooleanPredicate.add_constructor_and_methods_with_prefix(
1311  'qof_query_', 'boolean_predicate')
1312 
1314  pass
1315 
1316 QueryInt32Predicate.add_constructor_and_methods_with_prefix(
1317  'qof_query_', 'int32_predicate')
1318 
1320  pass
1321 
1322 QueryDatePredicate.add_constructor_and_methods_with_prefix(
1323  'qof_query_', 'date_predicate', exclude=["qof_query_date_predicate_get_date"])
1324 QueryDatePredicate.add_method('qof_query_date_predicate_get_date', 'get_date')
1325 
1327  pass
1328 
1329 QueryGuidPredicate.add_constructor_and_methods_with_prefix(
1330  'qof_query_', 'guid_predicate')
1331 
1333  pass
1334 
1335 QueryNumericPredicate.add_constructor_and_methods_with_prefix(
1336  'qof_query_', 'numeric_predicate')
gnc_numeric double_to_gnc_numeric(double n, gint64 denom, gint how)
Convert a floating-point number to a gnc_numeric.
def search_for(self, obj_type)
def raise_backend_errors_after_call(function, args, kwargs)
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
def BillNextID(self, vendor)
def raise_backend_errors(self, called_function="qof_session function")
def do_lookup_create_oo_instance(self, lookup_function, cls, args)
def InvoiceNextID(self, customer)
def __init__(self, args, kargs)
gnc_numeric gnc_numeric_from_string(const gchar *str)
Read a gnc_numeric from str, skipping any leading whitespace.
def __init__(self, book_uri=None, mode=None, instance=None, book=None)
A convenient constructor that allows you to specify a book URI, begin the session, and load the book.
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
Check for error signal in value.