While bored today I asked myself how close AI was to answering basic
questions about Gnucash books and submitted a couple of simple tests to
Google Gemini. To my surprise, it (nearly) works out of the box.
My question was "write code to report the five largest asset accounts in
a gnucash sqlite file". The code it responded with is:
========================
import piecash
def get_largest_assets_piecash(db_path):
# Open the GnuCash file in read-only mode
with piecash.open_book(db_path, readonly=True)as book:
asset_accounts = [accfor accin book.accountsif acc.type =='ASSET']
sorted_assets =sorted(asset_accounts, key=lambda a: a.get_balance(),
reverse=True)
print("Top 5 Largest Asset Accounts (piecash):")
print("-" *40)
for accin sorted_assets[:5]:
print(f"{acc.name}: ${acc.get_balance():,.2f}")
# Usage: # get_largest_assets_piecash("path_to_your_gnucash_file.gnucash")
==========================
This actually works, but it first prints several very wordy warnings saying:
"C:\Users\paul\AppData\Local\Python\pythoncore-3.15-64\Lib\site-packages\piecash\core\session.py:442:
SAWarning: relationship 'Price.slots' will copy column prices.guid to
column slots.obj_guid, which conflicts with relationship(s):
'Account.slots' (copies accounts.guid to slots.obj_guid), 'Slot.parent'
(copies slots.guid_val to slots.obj_guid), 'SlotFrame.slots' (copies
slots.guid_val to slots.obj_guid). If this is not the intention,
consider if these relationships should be linked with back_populates, or
if viewonly=True should be applied to one or more if they are read-only.
For the less common case that foreign key constraints are partially
overlapping, the orm.foreign() annotation can be used to isolate the
columns that should be written towards. To silence this warning, add
the parameter 'overlaps="parent,slots,slots"' to the 'Price.slots'
relationship. (Background on this error at: https://sqlalche.me/e/14/qzyx)".
What is this actually saying is wrong?
Thanks as always for all help, Paul
_______________________________________________
gnucash-user mailing list
[email protected]
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.