Bug #625193: Added 'search by ID' in python binding for invoices, customers and bills.

Patch by Mike E and Mark Jenkins:

When creating or appending to invoices, customers and bills, searching by ID is
likely more useful than by GUID.  I've added this functionality to the Python
bindings.

Search by ID using the python code:
tmp = gnucash.gnucash_core_c.search_invoice_on_id(ID,book.instance)
if tmp:
  invoice =  gnucash.gnucash_business.Invoice(instance=tmp)

Use the invoice object as in sample_scripts/simple_invoice_insert.py

I support this patch, but I've made a few improvments of my own.

I switched up the arguments in search_customer_on_id, search_invoice_on_id,
search_bill_on_id to have Book first and ID second. The reason for this was to
make these functions more consistent with the other functions where a search is
done through a book on a particular attribute.

Also added some specific python bindings support to allow this to be used as
methods of Book: Book.CustomerLookupByID, Book.InvoiceLookupByID,
Book.BillLoookupByID.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19431 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming
2010-08-14 20:48:18 +00:00
parent f8df02cdb4
commit 5fbfa23dbb
7 changed files with 283 additions and 8 deletions

View File

@@ -31,7 +31,8 @@ from function_class import \
from gnucash_core_c import gncInvoiceLookup, gncInvoiceGetInvoiceFromTxn, \
gncInvoiceGetInvoiceFromLot, gncEntryLookup, gncInvoiceLookup, \
gncCustomerLookup, gncVendorLookup, gncJobLookup, gncEmployeeLookup, \
gncTaxTableLookup, gncTaxTableLookupByName
gncTaxTableLookup, gncTaxTableLookupByName, search_invoice_on_id, \
search_customer_on_id, search_bill_on_id
class GnuCashCoreClass(ClassFromFunctions):
@@ -188,6 +189,21 @@ class Book(GnuCashCoreClass):
return self.do_lookup_create_oo_instance(
gncTaxTableLookupByName, TaxTable, name)
def BillLoookupByID(self, id):
from gnucash_business import Bill
return self.do_lookup_create_oo_instance(
search_bill_on_id, Bill, id)
def InvoiceLookupByID(self, id):
from gnucash_business import Invoice
return self.do_lookup_create_oo_instance(
search_invoice_on_id, Invoice, id)
def CustomerLookupByID(self, id):
from gnucash_business import Customer
return self.do_lookup_create_oo_instance(
search_customer_on_id, Customer, id)
class GncNumeric(GnuCashCoreClass):
"""Object used by GnuCash to store all numbers. Always consists of a
numerator and denominator.