mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Completed mapping for owner types and added tests.
Patch by Hendrik van Antwerpen <hendrik@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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21363 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
698a1dc6ac
commit
ff9ddda750
@ -192,8 +192,6 @@ typedef char gchar;
|
|||||||
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncEmployee, 0));
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncEmployee, 0));
|
||||||
else if (GNC_IS_JOB(data))
|
else if (GNC_IS_JOB(data))
|
||||||
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncJob, 0));
|
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 *))
|
else if ($1_descriptor == $descriptor(MonetaryList *))
|
||||||
PyList_Append(list, SWIG_NewPointerObj(data, $descriptor(gnc_monetary *), 0));
|
PyList_Append(list, SWIG_NewPointerObj(data, $descriptor(gnc_monetary *), 0));
|
||||||
else
|
else
|
||||||
|
@ -63,27 +63,13 @@ class GnuCashBusinessEntity(GnuCashCoreClass):
|
|||||||
else:
|
else:
|
||||||
GnuCashCoreClass.__init__(self, instance=instance)
|
GnuCashCoreClass.__init__(self, instance=instance)
|
||||||
|
|
||||||
def ApplyPayment(self, invoice, posted_acc, xfer_acc, amount,
|
class Customer(GnuCashBusinessEntity): pass
|
||||||
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 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
|
# override the superclass contructor, as Job doesn't require
|
||||||
# a currency but it does require an owner
|
# a currency but it does require an owner
|
||||||
def __init__(self, book=None, id=None, owner=None, name=None,
|
def __init__(self, book=None, id=None, owner=None, name=None,
|
||||||
@ -230,7 +216,7 @@ class Entry(GnuCashCoreClass):
|
|||||||
GnuCashCoreClass.__init__(self, instance=instance)
|
GnuCashCoreClass.__init__(self, instance=instance)
|
||||||
|
|
||||||
# Owner
|
# Owner
|
||||||
Owner.add_constructor_and_methods_with_prefix('gncOwner', 'New')
|
GnuCashBusinessEntity.add_methods_with_prefix('gncOwner')
|
||||||
|
|
||||||
owner_dict = {
|
owner_dict = {
|
||||||
'GetCustomer' : Customer,
|
'GetCustomer' : Customer,
|
||||||
@ -239,10 +225,15 @@ owner_dict = {
|
|||||||
'GetJob' : Job,
|
'GetJob' : Job,
|
||||||
'GetAddr' : Address,
|
'GetAddr' : Address,
|
||||||
'GetCurrency' : GncCommodity,
|
'GetCurrency' : GncCommodity,
|
||||||
'GetEndOwner': Owner,
|
'GetEndOwner': GnuCashBusinessEntity,
|
||||||
'GetBalanceInCurrency': GncNumeric,
|
'GetBalanceInCurrency': GncNumeric,
|
||||||
}
|
}
|
||||||
methods_return_instance(Owner, owner_dict)
|
methods_return_instance(GnuCashBusinessEntity, owner_dict)
|
||||||
|
|
||||||
|
methods_return_instance_lists(
|
||||||
|
GnuCashBusinessEntity, {
|
||||||
|
'GetCommoditiesList': GncCommodity
|
||||||
|
})
|
||||||
|
|
||||||
# Customer
|
# Customer
|
||||||
Customer.add_constructor_and_methods_with_prefix('gncCustomer', 'Create')
|
Customer.add_constructor_and_methods_with_prefix('gncCustomer', 'Create')
|
||||||
|
@ -113,8 +113,6 @@
|
|||||||
|
|
||||||
%include <gnc-commodity.h>
|
%include <gnc-commodity.h>
|
||||||
|
|
||||||
%include <gncOwner.h>
|
|
||||||
|
|
||||||
%typemap(out) GncOwner * {
|
%typemap(out) GncOwner * {
|
||||||
GncOwnerType owner_type = gncOwnerGetType($1);
|
GncOwnerType owner_type = gncOwnerGetType($1);
|
||||||
PyObject * owner_tuple = PyTuple_New(2);
|
PyObject * owner_tuple = PyTuple_New(2);
|
||||||
@ -189,6 +187,7 @@
|
|||||||
%include <gnc-lot.h>
|
%include <gnc-lot.h>
|
||||||
|
|
||||||
//business-core includes
|
//business-core includes
|
||||||
|
%include <gncOwner.h>
|
||||||
%include <gncCustomer.h>
|
%include <gncCustomer.h>
|
||||||
%include <gncEmployee.h>
|
%include <gncEmployee.h>
|
||||||
%include <gncVendor.h>
|
%include <gncVendor.h>
|
||||||
|
@ -9,4 +9,5 @@ EXTRA_DIST = \
|
|||||||
test_account.py \
|
test_account.py \
|
||||||
test_book.py \
|
test_book.py \
|
||||||
test_split.py \
|
test_split.py \
|
||||||
test_transaction.py
|
test_transaction.py \
|
||||||
|
test_business.py
|
||||||
|
@ -6,9 +6,10 @@ from test_book import TestBook
|
|||||||
from test_account import TestAccount
|
from test_account import TestAccount
|
||||||
from test_split import TestSplit
|
from test_split import TestSplit
|
||||||
from test_transaction import TestTransaction
|
from test_transaction import TestTransaction
|
||||||
|
from test_business import TestBusiness
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(TestBook, TestAccount, TestSplit, TestTransaction)
|
test_support.run_unittest(TestBook, TestAccount, TestSplit, TestTransaction, TestBusiness)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
@ -6,6 +6,8 @@ class BookSession( TestCase ):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.ses = Session()
|
self.ses = Session()
|
||||||
self.book = self.ses.get_book()
|
self.book = self.ses.get_book()
|
||||||
|
table = self.book.get_table()
|
||||||
|
self.currency = table.lookup('CURRENCY', 'EUR')
|
||||||
|
|
||||||
class TestBook( BookSession ):
|
class TestBook( BookSession ):
|
||||||
def test_markclosed(self):
|
def test_markclosed(self):
|
||||||
|
82
src/optional/python-bindings/tests/test_business.py
Normal file
82
src/optional/python-bindings/tests/test_business.py
Normal file
@ -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()
|
@ -18,12 +18,14 @@ class TestSplit( SplitSession ):
|
|||||||
|
|
||||||
def test_account(self):
|
def test_account(self):
|
||||||
ACCT = Account(self.book)
|
ACCT = Account(self.book)
|
||||||
|
ACCT.SetCommodity(self.currency)
|
||||||
self.split.SetAccount(ACCT)
|
self.split.SetAccount(ACCT)
|
||||||
self.assertTrue( ACCT.Equal(self.split.GetAccount(), True) )
|
self.assertTrue( ACCT.Equal(self.split.GetAccount(), True) )
|
||||||
|
|
||||||
def test_transaction(self):
|
def test_transaction(self):
|
||||||
TRANS = Transaction(self.book)
|
TRANS = Transaction(self.book)
|
||||||
self.split.SetParent(TRANS)
|
self.split.SetParent(TRANS)
|
||||||
|
TRANS.SetCurrency(self.currency)
|
||||||
TRANS.SetDescription("Foo")
|
TRANS.SetDescription("Foo")
|
||||||
self.assertEquals( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
|
self.assertEquals( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ class TransactionSession( BookSession ):
|
|||||||
self.split = Split(self.book)
|
self.split = Split(self.book)
|
||||||
self.split.SetParent(self.trans)
|
self.split.SetParent(self.trans)
|
||||||
############
|
############
|
||||||
|
self.trans.SetCurrency(self.currency)
|
||||||
|
|
||||||
class TestTransaction( TransactionSession ):
|
class TestTransaction( TransactionSession ):
|
||||||
def test_equal(self):
|
def test_equal(self):
|
||||||
@ -26,6 +27,9 @@ class TestTransaction( TransactionSession ):
|
|||||||
#Clone and original should have the same balance
|
#Clone and original should have the same balance
|
||||||
self.assertTrue( TRANS.Equal(self.trans, False, False, True, False) )
|
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):
|
def test_edit(self):
|
||||||
self.assertFalse( self.trans.IsOpen() )
|
self.assertFalse( self.trans.IsOpen() )
|
||||||
self.trans.BeginEdit()
|
self.trans.BeginEdit()
|
||||||
@ -44,6 +48,7 @@ class TestTransaction( TransactionSession ):
|
|||||||
|
|
||||||
def test_findsplit(self):
|
def test_findsplit(self):
|
||||||
ACCT = Account(self.book)
|
ACCT = Account(self.book)
|
||||||
|
ACCT.SetCommodity(self.currency)
|
||||||
self.split.SetAccount( ACCT )
|
self.split.SetAccount( ACCT )
|
||||||
SPLIT = self.trans.FindSplitByAccount( ACCT )
|
SPLIT = self.trans.FindSplitByAccount( ACCT )
|
||||||
self.assertTrue( SPLIT.Equal(self.split, True, False, False) )
|
self.assertTrue( SPLIT.Equal(self.split, True, False, False) )
|
||||||
|
Loading…
Reference in New Issue
Block a user