David, I did look at the Python bindings info a while back but at the time did not feel like getting started with Python because I just wanted to get done what I wanted to get done. I'm mostly a .NET & SQL guy so I stuck with what I knew. Fast forward a few months and add in the bounty of extra time that the quarantine has afforded and I have since started dipping my toes into Python a bit. I'm actually kind of excited now to take a fresh look at the Python bindings capabilities for GC. I agree with you 100% that there may be no need for me nor for Hal to do our own things if there is an existing way!
On Tue, Apr 28, 2020 at 5:59 PM David H <hell...@gmail.com> wrote: > Have you checked out the GnuCash Python Bindings - > https://code.gnucash.org/docs/MAINT/python_bindings_page.html - no point > in re-inventing the wheel :-) > > Cheers David H. > > What can Python Bindings be used for ? > > The python bindings supply the ability to access a wide range of the core > functions of GnuCash. You can read and write Transactions, Commodities, > Lots, access the business stuff... You gain the ability to manipulate your > financial data with a flexible scripting language. > > Not everything GnuCash can is possible to access though. The bindings > focus on basic accounting functions. Have a look at the examples to get an > impression. > > Some functions are broken because they have not been wrapped properly. > They may crash the program or return unaccessible values. Please file a bug > report if you find one to help support the development process. > > On Wed, 29 Apr 2020 at 07:44, Stu Perlman <sgperl...@gmail.com> wrote: > >> Hal, >> >> I'm sort of doing a liter version of what you are describing. I do >> manipulate some GC data from outside of GC. I have GC setup with the >> MySQL >> backend and while I don't create any new transactions from outside of GC I >> do manipulate them. I have some SQL routines that I created to clean up >> data points such as the Memo & Notes attributes that are part of each >> transaction. I have not run into any problems or data corruption after a >> few months of doing this. I did put a circuit breaker into my bolt-on app >> that at startup the 1st thing it does it check the GC lock record and if >> it >> detects that GC may still be running it will not allow my SQL routines to >> do anything. >> >> INSERTING new transaction records using SQL on the surface appears like it >> should be simple enough but I would proceed with extreme caution and a lot >> of testing as you go. I did not try creating any new transactions but I >> did try to create my own little routine (and then abandoned the effort) >> to let me set monthly budget amounts. *The reasons for that attempt are >> not >> important to this thread but the outcome may be*. >> >> I gave up after spending time creating the logic that I needed to insert >> into and/or change records in the SQL table [budget_amounts]. Everything >> I >> tested always looked perfect in the SQL backend until I went to work with >> that data in GC. It was like I did not change anything behind the scenes >> once I opened up GC again. I would go back to the SQL world and would >> sometimes notice that my changes to [budget_amounts] were either being a) >> ignored, b) wiped out or c) some other corruption. Through trial and >> error, I discovered that the SQL table [slots] (and it's various >> pseudo-tables) also maintains budget amount data and that said data in >> [slots] will persist when GC is restarted after my changes from SQL were >> executed. It was then that I decided that the amount of effort that I >> would spend reverse engineering the logic that GC is using with the >> [slots] >> table was never going to be worth the reward nor the risk. >> >> I don't know for a fact that for your particular use case that writing to >> [slots] will even be required because I never dug into the transactions >> that deeply. Maybe [transactions] and [splits] are isolated from the >> apparently superior related data that GC maintains in [slots]. If you >> happen to know the languages that the GC engine is written in you might be >> able to get the answer with a little bit of code review instead of the >> time >> consumed doing a bunch of testing, observing, and evaluating. >> >> Good luck! I'd love to know how it goes for you if you end up pursuing >> this idea. >> >> - Stu >> >> >> >> On Tue, Apr 28, 2020 at 3:15 PM Hal Vaughan <hal@hal.dance> wrote: >> >> > I’ve done some research on this issue and I’m trying to determine if >> it’s >> > worth doing more or if I’d just spend time on this topic and find it >> won’t >> > work. >> > >> > I have a situation I’ve been told GnuCash can’t handle, but I have a >> > Python library that can handle it. (It has to do with calculating >> interest >> > on a credit line with a variable balance.) >> > >> > Years ago, I remember checking into GnuCash and reading the XML data >> files >> > and finding that each transaction seemed to have a UUID with it, but >> that >> > the other data in each entry would be easy to generate from my own >> library >> > written in Python. I also know that now the data files can be in SQL, >> > using several different engines, and that if it’s an XML file, it’s in >> gzip >> > format. >> > >> > I do not need my program to run as a plug-in or anything like that. >> (Last >> > I looked, I had to install MacPorts for that, and last time I installed >> > MacPorts, it made a mess of the libraries for my old Perl scripts and >> some >> > Python ones.) >> > >> > But here’s what I’d like to do: >> > 1. Enter my transactions involving the credit line normally in GnuCash. >> > 2. Exit GnuCash >> > 3. Run my Python script that would read the GnuCash data file and find >> all >> > transactions with any credit lines. >> > 4. Do the interest calculations for my credit line >> > 5. Add a debit transaction for the interest amount before each new >> > transaction with the credit line >> > 6. Edit the comment field for each transaction involving the credit line >> > to include notes on interest and totals >> > 7. Save the ledger and exit my library script. >> > 8. Run GnuCash again and have the new transactions included and their >> > amounts included in any account totals. >> > >> > Is this even possible? I don’t mind doing the research to find out how >> to >> > generate a transaction ID and all the rest. I just want to know if I >> can >> > use my own library to add transactions to a file (or edit comments in a >> > transaction) and, when I’m done, for GnuCash to be able to read that >> file, >> > with my new transactions, in and to include the amounts in the added >> > transactions in account totals. >> > >> > >> > >> > Hal >> > _______________________________________________ >> > gnucash-user mailing list >> > gnucash-user@gnucash.org >> > To update your subscription preferences or to unsubscribe: >> > https://lists.gnucash.org/mailman/listinfo/gnucash-user >> > If you are using Nabble or Gmane, please see >> > https://wiki.gnucash.org/wiki/Mailing_Lists for more information. >> > ----- >> > Please remember to CC this list on all your replies. >> > You can do this by using Reply-To-List or Reply-All. >> > >> _______________________________________________ >> gnucash-user mailing list >> gnucash-user@gnucash.org >> To update your subscription preferences or to unsubscribe: >> https://lists.gnucash.org/mailman/listinfo/gnucash-user >> If you are using Nabble or Gmane, please see >> https://wiki.gnucash.org/wiki/Mailing_Lists for more information. >> ----- >> Please remember to CC this list on all your replies. >> You can do this by using Reply-To-List or Reply-All. >> > _______________________________________________ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user If you are using Nabble or Gmane, please see https://wiki.gnucash.org/wiki/Mailing_Lists for more information. ----- Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.