On Tuesday, July 10, 2012 6:51:44 PM UTC+2, John Wiegley wrote: > > >>>>> Qwertyu writes: > > > how can I remove '<Adjustment>' lines from a monthly report. > > It makes parsing the report quite difficult, since there are two entries > for > > the same date. > > They are required for the running total to make sense. But they only > appear > if you are converting currencies. > > Have you also tried the -n flag? >
I use the -n flag already to suppress the sub-accounts to only get a total. Maybe a flag like '--silent-adjustment' is needed? BTW, I don't really understand how the adjustments work. See the attached (minimal example) files. The difference between the files is only the price. Sometimes adjustments are shown and sometime not. Why? (See the comments in the attached ledger files.) Note, if there is no text between 'test....' and 'end test', then ledger produced no output. BTW 2, for testing an option --test would be good, which runs the 'test...' sections in the give ledger file and compares the output to what is given between 'test..' and 'end test'. You could then easily collect many ledger files with unit tests, to test against regressions. (I do that with a shell script, which you can find attached. Use at your own risk.) Also an option '--fill-test' would be useful to fill the test sections if they are empty. (This is also done by the attached shell script.) All the best and thanks for the great work on ledger.
adjustment-test_p011.ledger
Description: Binary data
adjustment-test_p051.ledger
Description: Binary data
adjustment-test_p001.ledger
Description: Binary data
#!/bin/bash
# todo: keep comments on the test sections
f=$1
test -r "$f" || { echo "$0: Please provide a ledger file as input"; exit 1; }
d=$f.d
test -d $d && rm -rf $d
mkdir $d
cd $d
# copy the ledger file (call it 'i' for input)
cp ../$f ./i
unset f
# generate test files (start with 't' followed by 3 digits)
sed -n '/^test/,/^end test/p' i | csplit -f t -q -n3 -z - '/^end test/1' '{*}'
# generate test commands; run test; compare output
keepDir=0 # we keep everything only if there is a difference
for tf in t???
do
cf=$(echo $tf | tr t c) # the command file contains the full ledger command to be run with 'eval'
of=$(echo $tf | tr t o) # the output file
# generate the command
{
echo -n 'ledger -f i '
sed -n 's/test \(.*\)/\1/p' $tf
} >$cf
# run the command
{
head -n1 $tf
eval $(cat $cf)
tail -n1 $tf
} >$of
# check for differences
if ! diff -q $tf $of >/dev/null
then
keepDir=1
echo "$0: Test $tf in directory $d failed"
diff -u $tf $of
fi
done
# ledger file with all test sections filled
{
cat i | sed '/^test/,/^end test/d;'
for f in o???
do
echo; echo; echo
cat $f
done
echo
} >o
cd ..
if test $keepDir -eq 0
then
rm -rf $d
else
echo "$0: keeping directory $d"
echo "$0: file $d/o contains the test sections filled with the current results"
fi
