trevorld / r-ledger

Imports data from plain text accounting files
Other
39 stars 2 forks source link

Read beancount files in directly with an appropriate bean-query statement #14

Closed trevorld closed 5 years ago

trevorld commented 6 years ago

Currently use either bean-report (h)ledger and then either ledger csv or hledger register -o csv. Right now bean-query "SELECT *" doesn't give me what I want/need (in particular missing the crucial account field plus parsing historical cost and/or market values look like could be a bit of a pain as well):

$ bean-example > example.bean
$ bean-query -f csv example.bean "SELECT *" | csvlook | head
|-------------+------+---------------------------+--------------------------------------------------+---------------------------------|
|  date       | flag | payee                     | narration                                        | position                        |
|-------------+------+---------------------------+--------------------------------------------------+---------------------------------|
|  2016-01-01 | *    |                           | Opening Balance for checking account             |   3762.36  USD                  |
|  2016-01-01 | *    |                           | Opening Balance for checking account             |  -3762.36  USD                  |
|  2016-01-01 | *    |                           | Allowed contributions for one year               | -18000     IRAUSD               |
|  2016-01-01 | *    |                           | Allowed contributions for one year               |  18000     IRAUSD               |
|  2016-01-03 | *    | RiverBank Properties      | Paying the rent                                  |  -2400.00  USD                  |
|  2016-01-03 | *    | RiverBank Properties      | Paying the rent                                  |   2400.00  USD                  |
|  2016-01-04 | *    | BANK FEES                 | Monthly bank fee                                 |     -4.00  USD                  |
trevorld commented 5 years ago

I think something like

$ bean-query -f csv example.beancount "select date, flag as mark, account, payee, narration as description, number as amount, currency as commodity, cost(position), value(position), tags"  | csvlook | head
|-------------+------+----------------------------+-------------+--------------------------------+----------+-----------+---------------+----------------+-------------|
|  date       | mark | account                    | payee       | description                    | amount   | commodity | cost_position | value_position | tags        |
|-------------+------+----------------------------+-------------+--------------------------------+----------+-----------+---------------+----------------+-------------|
|  2015-12-31 | *    | Assets:JT-Checking         |             | Opening Balances               |  5000.00 | USD       |  5000.00 USD  |  5000.00 USD   |             |
|  2015-12-31 | *    | Equity:Opening             |             | Opening Balances               | -5000.00 | USD       | -5000.00 USD  | -5000.00 USD   |             |
|  2016-01-01 | *    | Assets:JT-Checking         | Landlord    | Rent                           | -1500.00 | USD       | -1500.00 USD  | -1500.00 USD   |             |
|  2016-01-01 | *    | Expenses:Shelter:Rent      | Landlord    | Rent                           |  1500.00 | USD       |  1500.00 USD  |  1500.00 USD   |             |
|  2016-01-01 | *    | Assets:JT-Checking         | Brokerage   | Buy Stock                      | -1000    | USD       | -1000    USD  | -1000    USD   |             |
|  2016-01-01 | *    | Equity:Transfer            | Brokerage   | Buy Stock                      |  1000    | USD       |  1000    USD  |  1000    USD   |             |
|  2016-01-01 | *    | Assets:JT-Brokerage        | Brokerage   | Buy Stock                      |     4    | SP        |  1000    USD  |  2000    USD   |             |

gets us what we need (and splitting up the cost_position and value_position into historical_cost, hc_commodity, market_value, and mv_commodity should be straightforward).