Attached is a patch which updates the python bindings example scripts to
 use Transaction.BeginEdit() and Transaction.CommitEdit(). Doing so
allows these examples scripts to run without a bunch of warnings to
stderr from GnuCash as they did before.

apply with patch -p0

Mark Jenkins
Member
ParIT Worker Co-op

p.s.

You can also pull this from my subversion repository.
svn diff -r 579:581 \
http://svn.parit.ca/gnucash/branches/python-bindings/

and find in there my other python bindings patches from today as well,
the work I did with Transaction.GetImbalance(), and my work on feature
enhancement bug 625193
https://bugzilla.gnome.org/show_bug.cgi?id=625193
Index: src/optional/python-bindings/example_scripts/simple_test.py
===================================================================
--- src/optional/python-bindings/example_scripts/simple_test.py	(revision 579)
+++ src/optional/python-bindings/example_scripts/simple_test.py	(revision 581)
@@ -5,7 +5,7 @@
 
 FILE_1 = "/tmp/example.gnucash"
 
-session = Session("xml:%s" % FILE_1, True)
+session = Session("xml://%s" % FILE_1, True)
 
 book = session.book
 root_acct = Account(book)
@@ -13,7 +13,10 @@
 savings_acct = Account(book)
 opening_acct = Account(book)
 trans1 = Transaction(book)
+trans1.BeginEdit()
 trans2 = Transaction(book)
+trans2.BeginEdit()
+
 split1 = Split(book)
 split3 = Split(book)
 comm_table = book.get_table()
@@ -61,19 +64,20 @@
 trans2.SetCurrency(cad)
 trans2.SetDescription("Opening Savings Balance")
 
-split2 = split1.GetOtherSplit()
+split2 = Split(book)
 split2.SetAccount(savings_acct)
+split2.SetParent(trans1)
+split2.SetValue(num1.neg())
 
-split4 = split3.GetOtherSplit()
+split4 = Split(book)
 split4.SetAccount(opening_acct)
+split4.SetParent(trans2)
+split4.SetValue(num2.neg())
 
-book.print_dirty()
 
-book.mark_saved()
-book.mark_closed()
+trans1.CommitEdit()
+trans2.CommitEdit()
 
-book.print_dirty()
-
 session.save()
 session.end()
 session.destroy()
Index: src/optional/python-bindings/example_scripts/new_book_with_opening_balances.py
===================================================================
--- src/optional/python-bindings/example_scripts/new_book_with_opening_balances.py	(revision 579)
+++ src/optional/python-bindings/example_scripts/new_book_with_opening_balances.py	(revision 581)
@@ -130,8 +130,9 @@
             # balance acccount amount
             if commodity_tuple not in opening_balance_per_currency:
                 trans = Transaction(new_book)
+                trans.BeginEdit()
                 opening_balance_per_currency[commodity_tuple] = (
-                    Transaction(new_book), GncNumeric(0, 1) )
+                    trans, GncNumeric(0, 1) )
             trans, total = opening_balance_per_currency[commodity_tuple]
 
             new_total = total.sub(
@@ -256,6 +257,7 @@
     opening_trans.SetDate( *OPENING_DATE )
     opening_trans.SetCurrency(currency)
     opening_trans.SetDescription("Opening Balance")
+    opening_trans.CommitEdit()
 
     return simple_opening_name_used
         
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to