Bulk transaction move

Thomas Young thomas at polywatt.com
Sun Dec 28 13:16:30 EST 2014


Hi Sebastien

Many many thanks for the good advice and help. Not being up to snuff on 
Python or GC internals I went out and purchased a book on Python and did 
a little studying. I then executed your script with mostly good results 
saving myself a great deal of tedious effort. So far I have been unable 
to find any negative consequences to my database, so I have been quite 
happy for several days now. Not only did I save myself a lot of effort, 
I have been learning a few things as well. The mysterious aspect to the 
code execution is that i had to run it about 5 times on my database 
before it transferred all the target transactions. It would do many but 
not all on each pass.

Here is my slightly modified version of your script.

import piecash
from piecash import open_book
with open_book("test.gnucash",readonly=False) as s:
     misc_acc = s.accounts.get(name="Miscellaneous")
     new_acc = s.accounts.get(name="TEMP")
     for spl in misc_acc.splits:
         if spl.transaction.description == "Cash":
             spl.account = new_acc
     s.save()

Sincerely
Thomas Young


On 12/24/2014 3:49 AM, Sébastien de Menten wrote:
> Hello Thomas,
>
> With the recently released piecash (python interface to gnucash), if 
> your gnucash file is in the sqlite format, you could do this with the 
> following script:
>
>     from piecash import open_book
>
>     with open_book("sample1.gnucash",readonly=False) as s:
>         misc_acc = s.accounts.get(name="Miscellaneous")
>         new_acc = s.accounts.get(name="Other account")
>         for spl in misc_acc.splits:
>             if spl.transaction.description = "some descrption":
>                 spl.account = new_acc
>         s.save()
>
>
> kr
>
> Sebastien
>
> On Tue, Dec 23, 2014 at 3:07 AM, Thomas Young <thomas at polywatt.com 
> <mailto:thomas at polywatt.com>> wrote:
>
>     Hello
>
>     I have an account named Miscellaneous with about 1400 transactions
>     and I would like to move about 600 of them to a different account.
>     Is there any way of doing this in a bulk move instead of one by
>     one? I have tried saving my Gnucash file as Sqlite3 and editing
>     account name records with openoffice but the results have been
>     essentially gibberish back in Gnucash. My attempts with exporting
>     and importing CSV have not been much better since it seems CSV
>     exporting does not include all data like memos for instance.
>
>     Many thanks
>     Thomas
>     _______________________________________________
>     gnucash-user mailing list
>     gnucash-user at gnucash.org <mailto:gnucash-user at gnucash.org>
>     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.
>



More information about the gnucash-user mailing list