Bulk transaction move

Wm wm+gnc at tarrcity.demon.co.uk
Sun Dec 28 17:09:40 EST 2014


Sun, 28 Dec 2014 10:16:30 <54A048FE.80909 at polywatt.com>  Thomas Young 
<thomas at polywatt.com>

>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'm impressed.  Stick around, please.

>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.

Learning is fun.

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.

I'm going to guess Sebastien hasn't thought all of the scope things 
through.

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()


That wouldn't work here as my end of account tree names aren't unique 
and I use the same description for more than one thing.

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()


Maybe I am being thick but doesn't this mean the same transactions get 
changed more often than necessary ?

-- 
Wm...



More information about the gnucash-user mailing list