A simple wrapper to create and manage reports based on hledger queries.
Project description
hreports
A simple wrapper to create and manage reports based on hledger queries.
Free software: MIT license
Documentation: https://hreports.readthedocs.io.
Features
hreports saves shortcuts to hledger queries to conveniently manage multiple queries with different settings and ledger files. In addition, hreports can save the query output to pdfs with jinja templates using Pandoc.
Conveniently create and manage multiple heldger queries
Customize the representation of hledger query results with templates
Save report results in pdf format
Parametrize queries
Use case: generate invoices with a single command, e.g. hreports save invoice_client1
Use case: Manage tax reports, e.g. hreports show tax_2017
Quickstart
Ensure that hledger is installed. If you want to save generate pdf reports pandoc (>=1.16) and a PDF engine such as wkhtml2pdf need to be installed as well. Ensure to use the patched version wkthmltopdf to ensure https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2037
Use pip to install hreports:
$ pip install hreports
The starting point of running hledger queries is having a ledger to run queries against. Imagine following simple hlegder file:
$ cat cash-account.ledger 1917/12/14 * Income assets:cash 10 USD income:client1 1917/12/12 * Expense assets:cash 5 USD expense:milk
and a hledger timesheet:
$ cat timesheet.ledger 1917/12/14 * Time (consulting:clien1) 1
The following command creates a report named balance that executes the query hledger bal –depth 1 on the ledger cash.ledger:
$ hreports create balance --query "bal --depth 1" --ledger cash.ledger
When executed, hreports stores the query data in a config file for future reference. Now hreports can render the query by running:
$ hreports show balance 5 USD assets -------------------- 5 USD
This makes it easy to store many different queries on different ledger files and executing them by refering to their hreports name.
Templating
Sometimes, it is helpful to add context to query results. hreports uses jinja templates to customize the representation of reports. The query results are added to the output variabel in the context of the template. In addition, the report configuration data, global configuration and custom variables are added.
Imagine the folowing simple template:
$ cat balance.template The balance on {{ now }} the balance was {{ output|last }}
hreports can now use this template to embed query results:
$ hreports show balance --template balance.template The balance on 2017-12-15 15:39:11.519658 was: 5 USD
If you need this information for future reference, create a pdf of it by executing:
$ hreports save balance --template balance.template Saved balance.pdf
If you keep reusing this command, simply your life by updating the report:
$ hreports update balance --template balance.template
Now hreports will always use the balance.template when rendering the balance report.
Templating is also helpful when you use hledger for timetracking and invoicing. Create a hreport and a simple demo template. Add a custom variable name (“hourly_rate”) and value (“20”) with the -var option:
$ hreports create timesheet --ledger timesheet.ledger -q "bal" -var hourly_rate 20 --template invoice.template $ cat invoice.template {% set hours = output|last|float|round(2) %} {% set net = hours * hourly_rate|float %} Please pay me {{ net }} USD. Signed {{ now|datetime("%Y/%m/%d") }} $ hreports show timesheet Please pay me 20.0 USD. Signed on 2017/12/15
Admittedly, this is a somewhat simple example. But feel free to check out heldger edit –template invoice_de.template for a fully fledged template of a German invoice.
Finally, all report configuration data is stored in a simple YAML file which can be manipulated manually if preferred. To inspect and manipulated the config file run:
$ hreports edit
Roadmap
Add documentation
Add tests
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.2.1 (2018-12-23)
Adds string decoding to output subprocess call
Updates dependencies and minor fixes
0.2.0 (2018-04-01)
Adds tests
Improves exception handling
0.1.5 (2018-03-05)
Adds template filter to create relative dates
Adds multiply_last_column template filter to add an extra column which multiplies the last string on each line with a custom factor
Adds percentage_column template filter to add an extra column which shows the percentage of the last string in a line in comparision to the buttom right value of the output
Preserves whitespace in double quotes for check_output command
Shows report listing in alphabetic order
0.1.4 (2017-12-15)
Adds first template (german invoice)
Adds exception catching for template rendering and hledger commands
0.1.3 (2017-12-15)
Adds templating and some initial documenation.
0.1.2 (2017-12-03)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hreports-0.2.1.tar.gz
.
File metadata
- Download URL: hreports-0.2.1.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34982f309af9e7e7a4d6636061a2d9e4e3ea91eedb4043b8801360ce593db6eb |
|
MD5 | 03fca7a4548d27910696f5320409200e |
|
BLAKE2b-256 | e8cc780bc00c71412a86c65bda2f74052660d1cdba529732e28d2f520621d259 |
File details
Details for the file hreports-0.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: hreports-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | baa02fad8fd4580b1cae91a5ddf1b70415035dade515670edb755be2a50d9e83 |
|
MD5 | 6c8102a69b0e8474713b5077074ddb17 |
|
BLAKE2b-256 | 0bb3ccbaf51ebac542b6168deab50c403aa22e49833c0905709813f294f4e6bf |