GnuCash  5.6-150-g038405b370+
change_tax_code.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 
6 
7 from gnucash import Session, Account
8 
9 # choose the account code to select
10 TARGET_ACCOUNT_CODE = '1234'
11 
12 def mark_account_with_code_as_tax_related(account, target_code):
13  """Looks at account to see if it has the target_account_code, if so
14  set the account tax related flag to True and return True.
15  If not, recursively tries to do the same to all children accounts
16  of account.
17  Returns False when recursion fails to find it.
18  """
19  if account.GetCode() == target_code:
20  account.SetTaxRelated(True)
21  return True
22  else:
23  for child in account.get_children():
24  if mark_account_with_code_as_tax_related(child, target_code):
25  return True
26  return False
27 
28 # Change this path to your own
29 gnucash_session = Session("/home/mark/python-bindings-help/test.xac")
30 
31 mark_account_with_code_as_tax_related(
32  gnucash_session.book.get_root_account(),
33  TARGET_ACCOUNT_CODE)
34 
35 gnucash_session.save()
36 gnucash_session.end()