From 479ecc7b2b9603fceab4fb151d3f3ffb85534578 Mon Sep 17 00:00:00 2001 From: Oliver Lok Trevor Date: Thu, 10 Apr 2025 18:51:54 -0400 Subject: [PATCH 1/2] Fixed GetInvoiceFromTxn to convert to the right type of Python object for a GncInvoice. --- bindings/python/gnucash_core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/python/gnucash_core.py b/bindings/python/gnucash_core.py index 993ad8919b..6ee86786f9 100644 --- a/bindings/python/gnucash_core.py +++ b/bindings/python/gnucash_core.py @@ -822,9 +822,9 @@ class Transaction(GnuCashCoreClass): return self.GetSplitList().pop(n) def GetInvoiceFromTxn(self): - from gnucash.gnucash_business import Transaction + from gnucash.gnucash_business import Invoice return self.do_lookup_create_oo_instance( - gncInvoiceGetInvoiceFromTxn, Transaction ) + gncInvoiceGetInvoiceFromTxn, Invoice ) def __eq__(self, other): return self.Equal(other, True, False, False, False) From 008980c49787e6366ad81f17eea461506a711979 Mon Sep 17 00:00:00 2001 From: Oliver Lok Trevor Date: Thu, 24 Apr 2025 20:02:54 -0400 Subject: [PATCH 2/2] Added unit test --- bindings/python/tests/test_business.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bindings/python/tests/test_business.py b/bindings/python/tests/test_business.py index 4baea45a9f..9f176756ce 100644 --- a/bindings/python/tests/test_business.py +++ b/bindings/python/tests/test_business.py @@ -74,5 +74,14 @@ class TestBusiness(BusinessSession): def test_commodities(self): self.assertTrue( self.currency.equal( self.customer.GetCommoditiesList()[0] ) ) + def test_invoice_transaction(self): + """ + Test that you can get the posted transaction from a posted invoice and that you can get the invoice back from the transaction. + """ + posted_transaction = self.invoice.GetPostedTxn() + self.assertTrue( posted_transaction != None ) + invoice_from_transaction = posted_transaction.GetInvoiceFromTxn() + self.assertTrue( invoice_from_transaction != None and invoice_from_transaction.GetID() == self.invoice.GetID() ) + if __name__ == '__main__': main()