fix __eq__ in Split and Transaction

Compare guids with .Equal() when comparing Split and Transaction instances.
This commit is contained in:
andygoblins
2020-02-09 14:37:06 -06:00
parent 2d907ff495
commit 4502afad4f
3 changed files with 16 additions and 0 deletions

View File

@@ -434,6 +434,9 @@ class Transaction(GnuCashCoreClass):
return self.do_lookup_create_oo_instance(
gncInvoiceGetInvoiceFromTxn, Transaction )
def __eq__(self, other):
return self.Equal(other, True, False, False, False)
def decorate_monetary_list_returning_function(orig_function):
def new_function(self, *args):
"""decorate function that returns list of gnc_monetary to return tuples of GncCommodity and GncNumeric
@@ -461,6 +464,9 @@ class Split(GnuCashCoreClass):
"""
_new_instance = 'xaccMallocSplit'
def __eq__(self, other):
return self.Equal(other, True, False, False)
class Account(GnuCashCoreClass):
"""A GnuCash Account.

View File

@@ -57,6 +57,11 @@ class TestSplit( SplitSession ):
def test_equal(self):
COPY = self.split
self.assertTrue( self.split.Equal(COPY, True, False, False) )
# test __eq__ implementation
TRANS = Transaction(self.book)
self.split.SetParent(TRANS)
self.assertTrue( self.split == TRANS.GetSplitList()[0] )
self.assertTrue( self.split != Split(self.book) )
if __name__ == '__main__':
main()

View File

@@ -44,6 +44,11 @@ class TestTransaction( TransactionSession ):
def test_equal(self):
TRANS = self.trans
self.assertTrue( TRANS.Equal(self.trans, True, False, False, False) )
# test __eq__ implementation
SPLIT = Split(self.book)
SPLIT.SetParent(TRANS)
self.assertTrue( self.trans == SPLIT.GetParent() )
self.assertTrue( self.trans != Transaction(self.book) )
def test_clone(self):
domain = "gnc.engine"