From 82fe7a2f57dcbb7eb3bb95806586e8b2ce011aed Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Sat, 5 Sep 2009 00:33:37 +0000 Subject: [PATCH] Forgot to add new file (python patches) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18292 57a11ea4-9604-0410-9ed3-97b8803252fd --- .../example_scripts/change_tax_code.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/optional/python-bindings/example_scripts/change_tax_code.py diff --git a/src/optional/python-bindings/example_scripts/change_tax_code.py b/src/optional/python-bindings/example_scripts/change_tax_code.py new file mode 100644 index 0000000000..db6bb24129 --- /dev/null +++ b/src/optional/python-bindings/example_scripts/change_tax_code.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +from gnucash import Session, Account + +# choose the account code to select +TARGET_ACCOUNT_CODE = '1234' + +def mark_account_with_code_as_tax_related(account, target_code): + """Looks at account to see if it has the target_account_code, if so + set the account tax related flag to True and return True. + If not, recursively tries to do the same to all children accounts + of account. + Returns False when recursion fails to find it. + """ + if account.GetCode() == target_code: + account.SetTaxRelated(True) + return True + else: + for child in account.get_children(): + child = Account(instance=child) + if mark_account_with_code_as_tax_related(child, target_code): + return True + return False + +# Change this path to your own +gnucash_session = Session("xml:/home/mark/python-bindings-help/test.xac") + +mark_account_with_code_as_tax_related( + gnucash_session.book.get_root_account(), + TARGET_ACCOUNT_CODE) + +gnucash_session.save() +gnucash_session.end()