Moving transactions retrospectively
Lincoln A Baxter
lab at lincolnbaxter.com
Wed Aug 3 21:11:01 EDT 2016
On Wed, 2016-08-03 at 10:19 +1000, Chris Good wrote:
> > Message: 6
> > Date: Tue, 2 Aug 2016 21:57:26 +0100
> > From: Adam <gnucash at snowstone.org.uk>
> > To: GNU Cash User <gnucash-user at gnucash.org>
> > Subject: Moving transactions retrospectively
> > Message-ID: <442a9c04-3698-7e56-a67a-a9c0e9e95861 at snowstone.org.uk>
> > Content-Type: text/plain; charset=utf-8; format=flowed
> >
> > Hello,
> >
> > I've got some business accounts set up & have some income assigned
> to an
> > income account from marking invoices as paid. I'd now like to split
> the
> > recorded entries into two sets, under two different income
> accounts. Is
> this
> > possible?
> >
> > Thanks a lot,
> >
> > Adam
>
> Hi Adam,
>
> I believe if you are only splitting the income split into 2 income
> splits,
> that this will not cause any problems.
> I suggest doing this change from the income account register, rather
> than
> the Accounts Receivable account register.
>
> You may have set up GnuCash so that you cannot edit old transactions.
> If so,
> go into
> File, Properties, Accounts and change Day Threshold for Read-Only
> transactions to zero while you modify the old transactions.
>
> Regards, Chris Good
If if you want to do this I have a way to automate the reassignment of
splits. While back I discovered that I didn't like my COA with respect
to Charitable Donation. I had an account for every organization I gave
to. So I deleted all the sub accounts letting the splits more up. THEN
I discovered I really did want a subaccount for the payroll deduction
donations which happen 26 times a year (like United Way). Thus,
gc_move_splits was born. I used it successfully to select the splits I
wanted to move back down to a sub account.
I don't remember if I posted this one before, but I'm posted it again
attached to this email.
Note, I'll be setting up a git-hub repository for these xml based GC
tools soon. I've been talking to chris (good) about linking to this
from the GC Wiki.
If you decide you want to make modifications, please share them back to
me. If you find problems and can create a mini GC (sanitized) GnuCash
file that illustrates the problem, I'll try to fix then as quickly as I
can... (which might not be immediately ;-) ... I have a day job.
Lincoln
> _______________________________________________
> gnucash-user mailing list
> 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.
-------------- next part --------------
NAME
gc_move_splits.pl
COPYRIGHT
Copyright (C) 2016 Lincoln A Baxter
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
Please see the GNU General Public License at
<http://www.gnu.org/licenses/>
ABSTRACT
Move transaction splits from one account in the GC file to another.
Useful if you have consolidated accounts, and then discovered you want
to separate out some of the transactions into different accounts.
SYNOPSIS
gc_move_splits.pl [options] CG-file.xml [modified-GC-file.xml]
options:
--help print this synopsis help text
--man print the full man page (this file's POD)
--verbose increased verbosity (mainly for debugging)
--fromAcctSplit=AccountPath path of account the split should be move FROM
--toAccountSplit=AccountPath path of account the split should be move TO
--dumpAccount=file|- create a dump of account paths and guids
--description=regex Only move splits in transactions matching
description= my be repeated to specify more than one
--pathSeparator=char GnuCash account path separator (default=:)
The second file argument is is optional. With no destination output
file, gc_move_splits.pl runs in analytical/trial mode, and reports all
actions taken and produces all specified analysis outputs.
The source input file is never modified.
If your gnucash data file is compressed you must uncompress it first (on
unix based OSes) as follows:
cat gnucach_data_file gunzip > uncompressed_gnucash_file.xml
Or you can just uncheck the "compressed file" option in GnuCash and
save.
DISCUSSION
The script reads an uncompressed "version 2" GnuCash XML datafile and
writes a new file with the modified splits.
Splits to be moved are found by
1. Getting the Guid for the account from which the split is to be removed
2. Getting the Guid for the account into which the split should be moved
Then traversing all transactions in the file looking for
1. transactions with descriptions matching the input regex
2. finding the split with the guid to be removed
3. replacing the guid to be removed with the guid of the destination account
The script reads the GnuCash xml file *as XML* not as text. The script
uses XML::LibXML CPAN perl module to read, traverse modify and output a
new XML file. It is not dependant on the formating of the gnucash XML
unlike most perl scripts this author has seen on the GnuCash users email
list.
Because this script does not treat the GnuCash file as text, it is not
subject to the breakage that would occur if the formatting of the XML
data were to change.
Instead, this script reads the GnuCash data a DOM structure, and then
manipulates that structure.
The script does not modify the input GnuCash XML datafile. The user must
specify an outout data filename. The results of the script's operations
are written to this file, which should then be opened and checked in
GnuCash. Before replacing the original file.
To print a usage synopsis: gc_move_splits.pl --help
To print the synopsis, plus option descriptions: gc_move_splits.pl
--help --verbose
To print the entire man page: gc_move_splits.pl --man
ENVIRONMENT
Because gc_move_splits.pl reads the input XML file *as XML* using the
perl CPAN XML::LibXML module, using an XPath expression to find the
bayes matching data slots in each account, the script requires that your
perl environment have the CPAN XML::LibXML module installed.
The command
perl -c -MXML::LibXML </dev/null
will report an error if the module is not installed in your environment.
Of course the script will report this also, because if it is not
present, the script will not compile.
Unix/Linux environments
Most Linux distributions make this available via the their standard
package managers. On Debian based distributions this can be installed
with the following command:
sudo apt-get install libxml-perl
On Unix/Linux environments this script should be made executable with
the chmod command
chmod +x gc_move_splits.pl
Windows environments
XML::LibXML is also available in Active Perl, and in the cygwin
environments.
This author has not tested this script on windows, but knows of no
reason why it will not work, once the required environment is installed.
On windows, the easiest way to run the script would be by using perl
from a cmd prompt:
perl gc_move_splits.pl
Macintosh environments
This author is not familiar with the OSX environment. But knows it is
based on BSD Unix. The script should run from a terminal prompt, once
the requisit, LIBXml is installed in the perl environemnt. Patches to
these instructions are welcome.
OPTIONS
All options may be abbreviated as long as the option is distinct from
all other options.
--description='regex'
This regular expression is used for identifying transaction splits to be
moved or retargeted to another account.
This switch may be specified multiple times to specify multiple Regexes:
--descri='^Check' --descr='United Way'
The first will find "Check" at the beginning of a transaction
description. The second will find "United Way" anywhere in the
transaction description.
--verbose
Print very verbose output to STDOUT. Used for debugging. Don't bother.
Besides, this is also not very well implemented in this script at this
time.
--help (or -h)
Print help text.
--path(Separator)=:
Specifies the character used as the path separator in your GC datafile.
The default value is a colon (:)
--man
Print the full man page documentation
--fromAcctSplit=
Full path of account we what to move the split FROM.
--toAcctSplit=
Full path of account we what to move the split TO.
--description
Specifies the regex that will be looked for in the transaction
description. May be repeated.
--dumpAcct=file|-
Dump the full paths for all the accounts in the GC file to either the
file specified or to STDOUT, if "-" is used.
AUTHOR
Lincoln A. Baxter email: my intials (all three) (at) lincolnbaxter (dot)
com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gc_move_splits.pl
Type: application/x-perl
Size: 15614 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-user/attachments/20160803/10ee3824/attachment.pl>
More information about the gnucash-user
mailing list