r21363 - gnucash/trunk/src - Completed mapping for owner types and added tests.
Geert Janssens
gjanssens at code.gnucash.org
Thu Sep 29 07:00:19 EDT 2011
Author: gjanssens
Date: 2011-09-29 07:00:19 -0400 (Thu, 29 Sep 2011)
New Revision: 21363
Trac: http://svn.gnucash.org/trac/changeset/21363
Added:
gnucash/trunk/src/optional/python-bindings/tests/test_business.py
Modified:
gnucash/trunk/src/base-typemaps.i
gnucash/trunk/src/optional/python-bindings/gnucash_business.py
gnucash/trunk/src/optional/python-bindings/gnucash_core.i
gnucash/trunk/src/optional/python-bindings/tests/Makefile.am
gnucash/trunk/src/optional/python-bindings/tests/runTests.py
gnucash/trunk/src/optional/python-bindings/tests/test_book.py
gnucash/trunk/src/optional/python-bindings/tests/test_split.py
gnucash/trunk/src/optional/python-bindings/tests/test_transaction.py
Log:
Completed mapping for owner types and added tests.
Patch by Hendrik van Antwerpen <hendrik at van-antwerpen.net>
* Include gncOwner later, to use typemap.
* Add gncOwner functions to GnuCashBusinessEntity.
* Removed Owner, since it's basically GnuCashBusinessEntity.
* Included test for some business classes.
* Added currency to tests to reduce complaining.
Modified: gnucash/trunk/src/base-typemaps.i
===================================================================
--- gnucash/trunk/src/base-typemaps.i 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/base-typemaps.i 2011-09-29 11:00:19 UTC (rev 21363)
@@ -192,8 +192,6 @@
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncEmployee, 0));
else if (GNC_IS_JOB(data))
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncJob, 0));
- else if (GNC_IS_OWNER(data))
- PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncOwner, 0));
else if ($1_descriptor == $descriptor(MonetaryList *))
PyList_Append(list, SWIG_NewPointerObj(data, $descriptor(gnc_monetary *), 0));
else
Modified: gnucash/trunk/src/optional/python-bindings/gnucash_business.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/gnucash_business.py 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/gnucash_business.py 2011-09-29 11:00:19 UTC (rev 21363)
@@ -63,27 +63,13 @@
else:
GnuCashCoreClass.__init__(self, instance=instance)
- def ApplyPayment(self, invoice, posted_acc, xfer_acc, amount,
- exch, date, memo, num):
- if invoice != None:
- invoice = invoice.get_instance()
- trans = gncOwnerApplyPayment(
- self.get_instance(), invoice, posted_acc.get_instance(),
- xfer_acc.get_instance(), amount.get_instance(),
- exch.get_instance(), date, memo, num)
- if trans != None:
- trans = Transaction(instance=trans)
- return trans
-
-class Owner(GnuCashBusinessEntity): pass
-
-class Customer(Owner): pass
+class Customer(GnuCashBusinessEntity): pass
-class Employee(Owner): pass
+class Employee(GnuCashBusinessEntity): pass
-class Vendor(Owner): pass
+class Vendor(GnuCashBusinessEntity): pass
-class Job(Owner):
+class Job(GnuCashBusinessEntity):
# override the superclass contructor, as Job doesn't require
# a currency but it does require an owner
def __init__(self, book=None, id=None, owner=None, name=None,
@@ -230,7 +216,7 @@
GnuCashCoreClass.__init__(self, instance=instance)
# Owner
-Owner.add_constructor_and_methods_with_prefix('gncOwner', 'New')
+GnuCashBusinessEntity.add_methods_with_prefix('gncOwner')
owner_dict = {
'GetCustomer' : Customer,
@@ -239,11 +225,16 @@
'GetJob' : Job,
'GetAddr' : Address,
'GetCurrency' : GncCommodity,
- 'GetEndOwner': Owner,
+ 'GetEndOwner': GnuCashBusinessEntity,
'GetBalanceInCurrency': GncNumeric,
}
-methods_return_instance(Owner, owner_dict)
+methods_return_instance(GnuCashBusinessEntity, owner_dict)
+methods_return_instance_lists(
+ GnuCashBusinessEntity, {
+ 'GetCommoditiesList': GncCommodity
+ })
+
# Customer
Customer.add_constructor_and_methods_with_prefix('gncCustomer', 'Create')
Modified: gnucash/trunk/src/optional/python-bindings/gnucash_core.i
===================================================================
--- gnucash/trunk/src/optional/python-bindings/gnucash_core.i 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/gnucash_core.i 2011-09-29 11:00:19 UTC (rev 21363)
@@ -113,8 +113,6 @@
%include <gnc-commodity.h>
-%include <gncOwner.h>
-
%typemap(out) GncOwner * {
GncOwnerType owner_type = gncOwnerGetType($1);
PyObject * owner_tuple = PyTuple_New(2);
@@ -189,6 +187,7 @@
%include <gnc-lot.h>
//business-core includes
+%include <gncOwner.h>
%include <gncCustomer.h>
%include <gncEmployee.h>
%include <gncVendor.h>
Modified: gnucash/trunk/src/optional/python-bindings/tests/Makefile.am
===================================================================
--- gnucash/trunk/src/optional/python-bindings/tests/Makefile.am 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/tests/Makefile.am 2011-09-29 11:00:19 UTC (rev 21363)
@@ -9,4 +9,5 @@
test_account.py \
test_book.py \
test_split.py \
- test_transaction.py
+ test_transaction.py \
+ test_business.py
Modified: gnucash/trunk/src/optional/python-bindings/tests/runTests.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/tests/runTests.py 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/tests/runTests.py 2011-09-29 11:00:19 UTC (rev 21363)
@@ -6,9 +6,10 @@
from test_account import TestAccount
from test_split import TestSplit
from test_transaction import TestTransaction
+from test_business import TestBusiness
def test_main():
- test_support.run_unittest(TestBook, TestAccount, TestSplit, TestTransaction)
+ test_support.run_unittest(TestBook, TestAccount, TestSplit, TestTransaction, TestBusiness)
if __name__ == '__main__':
test_main()
Modified: gnucash/trunk/src/optional/python-bindings/tests/test_book.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/tests/test_book.py 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/tests/test_book.py 2011-09-29 11:00:19 UTC (rev 21363)
@@ -6,6 +6,8 @@
def setUp(self):
self.ses = Session()
self.book = self.ses.get_book()
+ table = self.book.get_table()
+ self.currency = table.lookup('CURRENCY', 'EUR')
class TestBook( BookSession ):
def test_markclosed(self):
Added: gnucash/trunk/src/optional/python-bindings/tests/test_business.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/tests/test_business.py (rev 0)
+++ gnucash/trunk/src/optional/python-bindings/tests/test_business.py 2011-09-29 11:00:19 UTC (rev 21363)
@@ -0,0 +1,82 @@
+from unittest import main
+
+from datetime import datetime
+
+from gnucash import Account, \
+ ACCT_TYPE_RECEIVABLE, ACCT_TYPE_INCOME, ACCT_TYPE_BANK, \
+ GncNumeric
+from gnucash.gnucash_business import Vendor, Employee, Customer, Job, Invoice, Entry
+
+from test_book import BookSession
+
+class BusinessSession( BookSession ):
+ def setUp(self):
+ BookSession.setUp(self)
+
+ self.today = datetime.today()
+
+ self.bank = Account(self.book)
+ self.bank.SetType(ACCT_TYPE_BANK)
+ self.bank.SetCommodity(self.currency)
+ self.income = Account(self.book)
+ self.income.SetType(ACCT_TYPE_INCOME)
+ self.income.SetCommodity(self.currency)
+ self.receivable = Account(self.book)
+ self.receivable.SetType(ACCT_TYPE_RECEIVABLE)
+ self.receivable.SetCommodity(self.currency)
+
+ self.customer = Customer(self.book,'CustomerID',self.currency)
+ self.vendor = Vendor(self.book,'VendorID',self.currency)
+ self.employee = Employee(self.book,'EmployeeID',self.currency)
+ self.job = Job(self.book,'JobID',self.customer)
+
+ self.invoice = Invoice(self.book,'InvoiceID',self.currency,self.customer)
+ self.invoice.SetDateOpened(self.today)
+ entry = Entry(self.book)
+ entry.SetDate(self.today)
+ entry.SetDescription("Some income")
+ entry.SetQuantity(GncNumeric(1))
+ entry.SetInvAccount(self.income)
+ entry.SetInvPrice(GncNumeric(100))
+ self.invoice.AddEntry(entry)
+
+ self.invoice.PostToAccount(self.receivable,
+ self.today, self.today, "", True)
+
+class TestBusiness( BusinessSession ):
+ def test_equal(self):
+ self.assertTrue( self.vendor.Equal( self.vendor.GetVendor() ) )
+ self.assertTrue( self.customer.Equal( self.job.GetOwner() ) )
+ self.assertTrue( self.customer.Equal( self.invoice.GetOwner() ) )
+
+ def test_post(self):
+ self.assertTrue( self.invoice.IsPosted() )
+
+ def test_payment(self):
+ self.assertFalse( self.invoice.IsPaid() )
+ self.customer.ApplyPayment(
+ self.invoice,
+ self.receivable, self.bank,
+ GncNumeric(50), GncNumeric(50),
+ self.today,
+ "", "")
+ self.assertFalse( self.invoice.IsPaid() )
+ BAL = self.invoice.GetPostedLot().get_balance()
+ self.assertTrue( GncNumeric(50).equal( BAL ) )
+ self.customer.ApplyPayment(
+ self.invoice,
+ self.receivable, self.bank,
+ GncNumeric(50), GncNumeric(50),
+ self.today,
+ "", "")
+ self.assertTrue( self.invoice.IsPaid() )
+
+ def test_owner(self):
+ OWNER = self.invoice.GetOwner()
+ self.assertTrue( self.customer.Equal( OWNER ) )
+
+ def test_commodities(self):
+ self.assertTrue( self.currency.equal( self.customer.GetCommoditiesList()[0] ) )
+
+if __name__ == '__main__':
+ main()
Modified: gnucash/trunk/src/optional/python-bindings/tests/test_split.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/tests/test_split.py 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/tests/test_split.py 2011-09-29 11:00:19 UTC (rev 21363)
@@ -18,12 +18,14 @@
def test_account(self):
ACCT = Account(self.book)
+ ACCT.SetCommodity(self.currency)
self.split.SetAccount(ACCT)
self.assertTrue( ACCT.Equal(self.split.GetAccount(), True) )
def test_transaction(self):
TRANS = Transaction(self.book)
self.split.SetParent(TRANS)
+ TRANS.SetCurrency(self.currency)
TRANS.SetDescription("Foo")
self.assertEquals( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
Modified: gnucash/trunk/src/optional/python-bindings/tests/test_transaction.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/tests/test_transaction.py 2011-09-29 11:00:06 UTC (rev 21362)
+++ gnucash/trunk/src/optional/python-bindings/tests/test_transaction.py 2011-09-29 11:00:19 UTC (rev 21363)
@@ -13,6 +13,7 @@
self.split = Split(self.book)
self.split.SetParent(self.trans)
############
+ self.trans.SetCurrency(self.currency)
class TestTransaction( TransactionSession ):
def test_equal(self):
@@ -26,6 +27,9 @@
#Clone and original should have the same balance
self.assertTrue( TRANS.Equal(self.trans, False, False, True, False) )
+ def test_setcurrency(self):
+ self.assertTrue( self.currency.equal( self.trans.GetCurrency() ) )
+
def test_edit(self):
self.assertFalse( self.trans.IsOpen() )
self.trans.BeginEdit()
@@ -44,6 +48,7 @@
def test_findsplit(self):
ACCT = Account(self.book)
+ ACCT.SetCommodity(self.currency)
self.split.SetAccount( ACCT )
SPLIT = self.trans.FindSplitByAccount( ACCT )
self.assertTrue( SPLIT.Equal(self.split, True, False, False) )
More information about the gnucash-changes
mailing list