2018-09-21 09:27:17 +02:00
|
|
|
#!/usr/bin/env python3
|
2009-09-05 00:33:37 +00:00
|
|
|
|
2010-12-17 20:36:40 +00:00
|
|
|
## @file
|
2018-09-26 08:21:17 +02:00
|
|
|
# @brief Recurse over all accounts in a book and marks the first one having target_account_code as tax related
|
2010-12-27 15:36:15 +00:00
|
|
|
# @ingroup python_bindings_examples
|
2010-12-17 20:36:40 +00:00
|
|
|
|
2009-09-05 00:33:37 +00:00
|
|
|
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():
|
|
|
|
|
if mark_account_with_code_as_tax_related(child, target_code):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2018-09-21 09:28:41 +02:00
|
|
|
|
2009-09-05 00:33:37 +00:00
|
|
|
# Change this path to your own
|
2011-01-28 20:57:54 +00:00
|
|
|
gnucash_session = Session("/home/mark/python-bindings-help/test.xac")
|
2009-09-05 00:33:37 +00:00
|
|
|
|
|
|
|
|
mark_account_with_code_as_tax_related(
|
|
|
|
|
gnucash_session.book.get_root_account(),
|
|
|
|
|
TARGET_ACCOUNT_CODE)
|
|
|
|
|
|
|
|
|
|
gnucash_session.save()
|
|
|
|
|
gnucash_session.end()
|