mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
It is split into - /libgnucash (for the non-gui bits) - /gnucash (for the gui) - /common (misc source files used by both) - /bindings (currently only holds python bindings) This is the first step in restructuring the code. It will need much more fine tuning later on.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
## @file
|
|
# @brief Output all the credits and debits on an account
|
|
# @ingroup python_bindings_examples
|
|
|
|
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
|
|
|
|
# Change this path to your own
|
|
gnucash_session = Session("/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()
|