|
GnuCash 2.4.99
|
00001 #!/usr/bin/env python 00002 00003 ## @file 00004 # @brief Output all the credits and debits on an account 00005 # @ingroup python_bindings_examples 00006 00007 from gnucash import Session, Account 00008 00009 # choose the account code to select 00010 TARGET_ACCOUNT_CODE = '1234' 00011 00012 def mark_account_with_code_as_tax_related(account, target_code): 00013 """Looks at account to see if it has the target_account_code, if so 00014 set the account tax related flag to True and return True. 00015 If not, recursively tries to do the same to all children accounts 00016 of account. 00017 Returns False when recursion fails to find it. 00018 """ 00019 if account.GetCode() == target_code: 00020 account.SetTaxRelated(True) 00021 return True 00022 else: 00023 for child in account.get_children(): 00024 child = Account(instance=child) 00025 if mark_account_with_code_as_tax_related(child, target_code): 00026 return True 00027 return False 00028 00029 # Change this path to your own 00030 gnucash_session = Session("/home/mark/python-bindings-help/test.xac") 00031 00032 mark_account_with_code_as_tax_related( 00033 gnucash_session.book.get_root_account(), 00034 TARGET_ACCOUNT_CODE) 00035 00036 gnucash_session.save() 00037 gnucash_session.end()
1.7.4