Re: Automatically Credit an Account

2014-06-07 Thread Martin Blais
On Wed, Jun 4, 2014 at 1:16 PM, Martin Blais bl...@furius.ca wrote:

 On Wed, Jun 4, 2014 at 4:23 AM, Jostein Berntsen jber...@broadpark.no
 wrote:


 This sounds like a great feature. Can you give an example on how it works?


 Sure.
 I attached an example input file (input.beancount).
 Run it like this:

   bean-query input.beancount print

 This says: parse input.beancount and produce the 'print' report.
 You should see output like print.beancount (also in attachment).

 I'm still improving it; for transactions with non-trivial balances, I want
 to spit out comments next to each posting that explicitly state which
 amounts are used in the balance calculation.  Also, price entries that are
 currently implicitly derived from positions with prices (e.g., @ ...) will
 be generated instead as explicit price entries being inserted in the flow
 of entries, by a stage that runs after parsing. I manually edited the
 output to give you an idea of what that will look like (attachment:
 print-future.beancount, diff it with print.beancount).


Both improvements are now implemented. Printing entries shows you the
amount that is used for balancing the entry, and the price directives that
used to be implicitly derived from postings with prices are now generated
explicitly in a first step, so they appear in the printed list.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-04 Thread Jostein Berntsen


On Wednesday, June 4, 2014 7:32:22 AM UTC+2, Martin Blais wrote:

 On Mon, Jun 2, 2014 at 8:55 PM, Martin Blais bl...@furius.ca 
 javascript: wrote:

 Why don't you build a tool for printing out the result of these 
 rule-based modifications? Do you think that would be useful? Is it 
 possible? I see a lot of questions like: Why doesn't my rule such and such 
 work? I see unexpected results in the register. If Ledger had a command to 
 expand everything, and print the expanded results, all of these questions 
 would be easily answered by inspecting what it's doing, no? Is that easy to 
 implement? 

 Just an idea. I'm building something exactly like that for Beancount, to 
 help in debugging plugins, which are essentially functions that transform a 
 list of entries in arbitrary ways, into a new, modified list of entries. 
 One should be able to diff the files and round-trip between data-structure 
 to text and back.


 Actually, I just completed support for round-trips tonight (I had been 
 writing comparison code lately in order to make it easier to write tests by 
 writing a list of expected transactions in the input syntax itself, so it 
 was a-propos). This means that Beancount can now read a complete ledger 
 file, spit it back out in text, and re-reading that output generates the 
 same data structures in memory. Writing that re-read structure out again to 
 a second file also shows no file diff against the first output to text, 
 it's identical. I tested this on my gigantic personal ledger of 8 years, 
 and it passes clean.

 I'll add a new report type called print shortly, which will just spit 
 out the data structure it read in memory back to text, after running all 
 the transformations (e.g. automatically setting the amounts on postings, 
 processing the tag directives, adding price entries for postings at a 
 price, and whatever else the plugins do). This should be a nice debugging 
 tool in the future, as it reflects what it does, e.g., what was 
 automatically generated by the syntax shortcuts.


This sounds like a great feature. Can you give an example on how it works?

Jostein 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-04 Thread Martin Blais
On Wed, Jun 4, 2014 at 4:23 AM, Jostein Berntsen jber...@broadpark.no
wrote:


 On Wednesday, June 4, 2014 7:32:22 AM UTC+2, Martin Blais wrote:

 On Mon, Jun 2, 2014 at 8:55 PM, Martin Blais bl...@furius.ca wrote:

 Why don't you build a tool for printing out the result of these
 rule-based modifications? Do you think that would be useful? Is it
 possible? I see a lot of questions like: Why doesn't my rule such and such
 work? I see unexpected results in the register. If Ledger had a command to
 expand everything, and print the expanded results, all of these questions
 would be easily answered by inspecting what it's doing, no? Is that easy to
 implement?

 Just an idea. I'm building something exactly like that for Beancount, to
 help in debugging plugins, which are essentially functions that transform a
 list of entries in arbitrary ways, into a new, modified list of entries.
 One should be able to diff the files and round-trip between data-structure
 to text and back.


 Actually, I just completed support for round-trips tonight (I had been
 writing comparison code lately in order to make it easier to write tests by
 writing a list of expected transactions in the input syntax itself, so it
 was a-propos). This means that Beancount can now read a complete ledger
 file, spit it back out in text, and re-reading that output generates the
 same data structures in memory. Writing that re-read structure out again to
 a second file also shows no file diff against the first output to text,
 it's identical. I tested this on my gigantic personal ledger of 8 years,
 and it passes clean.

 I'll add a new report type called print shortly, which will just spit
 out the data structure it read in memory back to text, after running all
 the transformations (e.g. automatically setting the amounts on postings,
 processing the tag directives, adding price entries for postings at a
 price, and whatever else the plugins do). This should be a nice debugging
 tool in the future, as it reflects what it does, e.g., what was
 automatically generated by the syntax shortcuts.


 This sounds like a great feature. Can you give an example on how it works?


Sure.
I attached an example input file (input.beancount).
Run it like this:

  bean-query input.beancount print

This says: parse input.beancount and produce the 'print' report.
You should see output like print.beancount (also in attachment).

I'm still improving it; for transactions with non-trivial balances, I want
to spit out comments next to each posting that explicitly state which
amounts are used in the balance calculation.  Also, price entries that are
currently implicitly derived from positions with prices (e.g., @ ...) will
be generated instead as explicit price entries being inserted in the flow
of entries, by a stage that runs after parsing. I manually edited the
output to give you an idea of what that will look like (attachment:
print-future.beancount, diff it with print.beancount).

Much of the Beancount operations can be expressed as transformations that
accept 3 arguments: (a list of entries/directives records, a list of
errors, and a map of options), and output the same tuple, but with entries
and errors modified (you can generates new entries or modify existing
ones).  It's a functional approach, using mostly immutable data, which
makes it very easy to understand. As I'm teasing more and more of the
complexity out of it, I'm discovering that I can even do much of the
processing using these stages:
https://hg.furius.ca/public/beancount/file/ece44b933ec8/src/python/beancount/loader.py#l62
I'm basically 1) parsing, 2) running transformations, and 3) checking some
invariants. Reports are generated from the resulting list of directives.
Filtering (e.g. year=2014) is simply another stage that lets through a
subset of the entries - all the reports work on a filtered list of entries
too. User plugins are simply functions that accept the three inputs and
output a modified version of those (you can do anything you want, as long
as some basic invariants are maintained).

So basically, the print report just spits out the list of entries after
the transformations and validation. If you're working on some idea for a
transformation, say, adding support for forecasting entries:
https://hg.furius.ca/public/beancount/file/ece44b933ec8/src/python/beancount/plugins/forecast.py#l32
you can now write a simple input file and use bean-query input.beancount
print to see what your transformation actually does, great for debugging.
Comparison routines that compare two lists of entries are available from
the testing support libraries, and because of the round-trip capability,
you can now just inspect the output, and if it's right, cut-n-paste the
input and output text into a unit test to specify a list of expected
entries from a transformation (!). Makes writing unit tests a breeze (which
was my goal when I started down that path recently).

I did not set out for the printer to have this 

Re: Automatically Credit an Account

2014-06-03 Thread Jostein Berntsen


On Tuesday, June 3, 2014 12:42:50 AM UTC+2, b0ef wrote:

 Jostein Berntsen jbe...@broadpark.no javascript: writes: 

  This seems to work for me: 
  
  = /Assets:1500/ 
   
 Assets:Total  1 
   Income:3010  -1 
  2014-06-02 foo   
  
 Assets:1500:foo:101011337 
  Assets:Total 
  2014-06-03 foo   
  
 Assets:1500:foo:201015100 
  Assets:Total 

 That's because you're doing something totally different. 

 If you look at my example, I only have one line in each transaction. 

 I don't want to write, ie Assets:Total 15 brazillion times. 



Then you can do something like this:

bucket 
Income:3010 




2014-06-02 
foo 

 

Assets:1500:foo:101011337

2014-06-03 
foo 

 

Assets:1500:foo:201015100
 
 ledger -f ~/Documents/Finans/testing/test.dat bal
6437  Assets:1500:foo
133710101
510020101
   -6437  Income:3010

   0

Jostein

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-03 Thread Esben Stien
Jostein Berntsen jber...@broadpark.no writes:

 Then you can do something like this:
 bucket Income:3010 

Now that's what I'm talking about;)

Hehe, that's excellent. I just placed the bucket statement in the top of
my file and it's working

Found it in the manual also. 

Really great; thanks.

I should probably put these income files in a different file, so as to
not auto balance any other transaction. 

-- 
Esben Stien is b0ef@e s  a 
 http://www. s tn m
  irc://irc.  b  -  i  .   e/%23contact
   sip:b0ef@   e e 
   jid:b0ef@n n

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-03 Thread Martin Blais
On Mon, Jun 2, 2014 at 8:55 PM, Martin Blais bl...@furius.ca wrote:

 Why don't you build a tool for printing out the result of these rule-based
 modifications? Do you think that would be useful? Is it possible? I see a
 lot of questions like: Why doesn't my rule such and such work? I see
 unexpected results in the register. If Ledger had a command to expand
 everything, and print the expanded results, all of these questions would
 be easily answered by inspecting what it's doing, no? Is that easy to
 implement?

 Just an idea. I'm building something exactly like that for Beancount, to
 help in debugging plugins, which are essentially functions that transform a
 list of entries in arbitrary ways, into a new, modified list of entries.
 One should be able to diff the files and round-trip between data-structure
 to text and back.


Actually, I just completed support for round-trips tonight (I had been
writing comparison code lately in order to make it easier to write tests by
writing a list of expected transactions in the input syntax itself, so it
was a-propos). This means that Beancount can now read a complete ledger
file, spit it back out in text, and re-reading that output generates the
same data structures in memory. Writing that re-read structure out again to
a second file also shows no file diff against the first output to text,
it's identical. I tested this on my gigantic personal ledger of 8 years,
and it passes clean.

I'll add a new report type called print shortly, which will just spit out
the data structure it read in memory back to text, after running all the
transformations (e.g. automatically setting the amounts on postings,
processing the tag directives, adding price entries for postings at a
price, and whatever else the plugins do). This should be a nice debugging
tool in the future, as it reflects what it does, e.g., what was
automatically generated by the syntax shortcuts.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-02 Thread Esben Stien
Jostein Berntsen jber...@broadpark.no writes:

 Could you check my example and see if that works for you?

I created a file foo.ledger:

= /Assets:1500/
 Income:Transaction(1 * amount)
 Income:3010  (-1 * amount)

2014-06-02 foo
Assets:1500:foo:101011337

..then I run ledger -f foo.ledger and I get: 

Ledger 3.0.2-20140507, the command-line accounting tool

While parsing file
foo.ledger,
line 6:
While balancing transaction from
foo.ledger,
lines 5-6:
 2014-06-02 foo
 Assets:1500:foo:101011337
Unbalanced remainder is:
1337
Amount to balance against:
1337
Error: Transaction does not balance

-- 
Esben Stien is b0ef@e s  a 
 http://www. s tn m
  irc://irc.  b  -  i  .   e/%23contact
   sip:b0ef@   e e 
   jid:b0ef@n n

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-02 Thread Erik Hetzner
At Sun, 01 Jun 2014 23:11:39 +0200,
Esben Stien wrote:
 
 I'm trying to do an automated transaction on this:
 
 [...]
 
 ..with $account 1 and the Income:3010 -1, but none of them seem to work
 
 Any pointers as to how I can do this?

Hi Esben,

I'm pretty sure I encountered the same issue when fooling around with
trying to get a budget together. I think the transaction must be
balanced before any automatic transaction is applied, and I doubt this
is going to change.

best, Erik

-- 
Sent from my free software system http://fsf.org/.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-02 Thread Esben Stien
Jostein Berntsen jber...@broadpark.no writes:

 This seems to work for me:

 = /Assets:1500/   
 
 Assets:Total  1 
  Income:3010  -1
 2014-06-02 foo
 
 Assets:1500:foo:101011337 
 Assets:Total
 2014-06-03 foo
 
 Assets:1500:foo:201015100 
 Assets:Total

That's because you're doing something totally different. 

If you look at my example, I only have one line in each transaction.

I don't want to write, ie Assets:Total 15 brazillion times.

-- 
Esben Stien is b0ef@e s  a 
 http://www. s tn m
  irc://irc.  b  -  i  .   e/%23contact
   sip:b0ef@   e e 
   jid:b0ef@n n

-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-02 Thread Martin Blais
Why don't you build a tool for printing out the result of these rule-based
modifications? Do you think that would be useful? Is it possible? I see a
lot of questions like: Why doesn't my rule such and such work? I see
unexpected results in the register. If Ledger had a command to expand
everything, and print the expanded results, all of these questions would
be easily answered by inspecting what it's doing, no? Is that easy to
implement?

Just an idea. I'm building something exactly like that for Beancount, to
help in debugging plugins, which are essentially functions that transform a
list of entries in arbitrary ways, into a new, modified list of entries.
One should be able to diff the files and round-trip between data-structure
to text and back.





On Mon, Jun 2, 2014 at 6:42 PM, Esben Stien b...@esben-stien.name wrote:

 Jostein Berntsen jber...@broadpark.no writes:

  This seems to work for me:
 
  = /Assets:1500/
  
 Assets:Total  1
   Income:3010  -1
  2014-06-02 foo
 
 Assets:1500:foo:101011337
  Assets:Total
  2014-06-03 foo
 
 Assets:1500:foo:201015100
  Assets:Total

 That's because you're doing something totally different.

 If you look at my example, I only have one line in each transaction.

 I don't want to write, ie Assets:Total 15 brazillion times.

 --
 Esben Stien is b0ef@e s  a
  http://www. s tn m
   irc://irc.  b  -  i  .   e/%23contact
sip:b0ef@   e e
jid:b0ef@n n

 --

 ---
 You received this message because you are subscribed to the Google Groups
 Ledger group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to ledger-cli+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically Credit an Account

2014-06-01 Thread Jostein Berntsen
On 01.06.14,23:11, Esben Stien wrote:
 I'm trying to do an automated transaction on this:
 
 2014-06-01 foo
 ;[[id:e235bd4a-ec6f-4975-ab26-7da247b3bb77][1337453 foo]]
 Assets:1500:foo:1337453 1337
 
 The actual transaction without automation would be: 
 
 2014-06-01 foo
 ;[[id:e235bd4a-ec6f-4975-ab26-7da247b3bb77][1337453 foo]]
 Assets:1500:foo:1337453 1337
 Income:3010
 
 So, this amount is supposed to be credited from the Income:3010 account, so
 I've tried many possible variations of this:
 
 = Assets:1500
 Income:3010
 
 ..with $account 1 and the Income:3010 -1, but none of them seem to work
 
 Any pointers as to how I can do this?
 

Have you tried something like this?


= /Assets:1500/
 Income:Transaction(1 * amount)
 Income:3010  (-1 * amount)


Jostein


-- 

--- 
You received this message because you are subscribed to the Google Groups 
Ledger group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.