simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
3.05k stars 320 forks source link

Support simple expressions in postings #183

Open alexanderkjeldaas opened 10 years ago

alexanderkjeldaas commented 10 years ago

When working with differenciated VAT (in EU), an invoice might say:

Food A (12% vat) EUR 50 Food B (12% vat) EUR 10 ... ... Plastic bag (25% vat) EUR 0.1 Transportation (25% vat) EUR 4

Total: EUR 1423.00 including VAT 25% EUR 0.82 including VAT 12% EUR 240

In this scenario, it is useful to be able to write any of the following:

expenses:food:12%   1423.10 - 0.1 - 4
expenses:other:25%     0.1 + 4
cash

That is, if a few entries have a different vat setting, being able to use some simple calculations is good. The idea is that the posting should only include numbers that are easy to find on the receipt and it should be succinct.

It could have been written:

expenses:food:12%   1423.10
expenses:food:12%        -0.1
expenses:food:12%        -4
expenses:other:25%     0.1
expenses:other:25%     4
cash

but that is pretty hackish and unclear I think.

In this example I have accounts that have fixed VAT amounts, so I can transfer the VAT at the end of the reporting period:

expenses:food:12%     -41243  = 0
expenses:food             41243/1.12
vat:incoming:12%

Another way to do this is like this:

expenses:food:12%   (1423.10 - 0.1 - 4)/1.12
vat:incoming:12%        240
expenses:other:25%     (0.1 + 4)/1.25
vat:incoming:25%       0.82
cash                           -1423

In that example, only numbers from the receipt are used, and the posting must balance. Without the ability to calculate non-vat food and other expenses, a calculator must be used, which makes writing the posting 3x as much work. A posting where the numbers are calculated is also less clear. It is hard to know whether the numbers correspond to the receipt.

The following simple 2-minute hack in perl implements this partially as a preprocessor, but more principled support would be great.

#!/usr/bin/perl -p

if (m/(\s+[a-zäöåA-ZÖÄÅ0-9:%]+\s\s+)(-?[0-9.()]+(\s*[-+*\/]\s*[0-9.()]+)+)/) {
    $_=$1.eval($2)."\n";
}
simonmichael commented 10 years ago

A nice feature request with great examples. I can see how this can be useful and a labour saver, yet I feel it will bring a lot of new complexities, interactions and support burden. It will be quite a few more lines of code than your (annoyingly short) perl script too. So I think I'm around -0.1 on this feature. But if a pull request appeared I would accept it.

simonmichael commented 9 years ago

Needs discussion/developers, closing.

simonmichael commented 6 years ago

On #913 @sorsasampo wrote:

@simonmichael I think it would be nice if there was a separate issue for expression amounts that people could subscribe to.

I followed #183 / #923 -> #871 comments here.

I can't easily keep track of this set of issues, so I'm not sure if we have one already, but I've reopened #183 for this.

simonmichael commented 6 years ago

Summary: there is new interest in this issue and some related PRs from @ag-eitilt, beginning with #871. It might happen, if we can keep the complexities down.