Commit graph

67 commits

Author SHA1 Message Date
Brett Smith
c9382a2604 historical: Fix the rate ordering with two dates.
Darnit, I wrote the tests first, and I wrote them right, and then I
mixed up the ordering in the code, and somehow I convinced myself
the code was the right and the tests were wrong. But no, I had the
tests right, this is really what we want. This gets the output to
follow the examples from our bookkeeping documentation.
2020-05-20 15:21:13 -04:00
Brett Smith
ae3e4617d3 historical: Always format rates with the same precision.
When we format a rate as a price, we don't know how much precision
is "enough" to do the conversion, because we don't know what's
being converted to. As a result, we may (=will almost certainly)
end up formatting the rate with different precision on the cost
date vs. the price date, and that causes Beancount/Ledger to fail
to make the connection between them.

Using a constant of 6 is enough to make the current test for
"enough" precision pass, so just do that for now. This might need
further refinement in the future.
2020-05-19 15:56:19 -04:00
Brett Smith
8dede9d139 historical: Swap Ledger and Beancount formatters in the class hierarchy.
This makes sense for a couple of reasons:

* The Beancount formatter has "less features" than the Ledger formatter, so
  this is a more "logical" organization of the hierarchy anyway. Note how
  this eliminates the need for the BeancountFormatter.__init__ override to
  turn off Ledger features.

* Any future work will probably be focused on the Beancount formatter, so
  this reduces the amount of code you have to understand and hold in your
  head to do that.
2020-05-19 15:27:04 -04:00
Brett Smith
c3fd55ec15 historical: Beancount can handle commas in amounts.
And having it looks nicer, is more consistent with our historical
books, is less code for me, and is no more trouble for the user.
2020-05-19 15:22:00 -04:00
Brett Smith
e158eae7d9 gitignore: Modernize. 2020-05-17 14:12:15 -04:00
Brett Smith
30e9f1c1e8 setup: Version 2.0 for all the recent changes. 2020-05-17 14:10:17 -04:00
Brett Smith
5573caf7ee oxrlib_example: Update for Beancount. 2020-05-17 14:08:59 -04:00
Brett Smith
3a3afb7978 historical: Add Beancount output format. 2020-05-17 14:05:49 -04:00
Brett Smith
7c11ae408c tests: Prep historical tests for parametrizing on output format. 2020-05-17 13:32:32 -04:00
Brett Smith
2d753c31aa historical: Add support for from_date arg. 2020-05-17 13:32:32 -04:00
Brett Smith
71893ace4d tests: Historical tests use more flexible rate matching.
This lets the tests be more flexible about how much precision is used in
rates when appropriate, and makes them ready to parametrize for
Beancount.
2020-05-17 10:44:03 -04:00
Brett Smith
fb2114896d historical: Normalize class instantiation for formatters.
This will make them easier to extend with different price/cost rates,
and to add a Beancount formatter.
2020-05-16 16:56:29 -04:00
Brett Smith
80fd49a98a historical: Introduce --output-format option.
Beancount output will be added here.
2020-05-16 15:07:20 -04:00
Brett Smith
27dbe14b94 config: Accept a source date for displaying rates.
For output formats that can show both a cost and a price,
this will be used to distinguish them.
2020-05-16 14:17:29 -04:00
Brett Smith
9b6d562d46 tests: Stop calling fixtures directly.
Avoid deprecation warnings from pytest.
2020-05-06 14:48:27 -04:00
Brett Smith
a3cc41a5cf tests: Run with oxrlib's decimal context. 2017-12-31 10:04:37 -05:00
Brett Smith
3b732505fa main: Decimal context sets the state of all traps.
This commit started because I noticed in the decimal documentation that
BasicContext doesn't trap decimal.Subnormal, while oxrlib probably should.
The point of this function is to set all the parts of a context that oxrlib
should have to handle currency correctly and safely.  With that motivation,
it makes more sense to set all the traps exactly as we want them, rather
than selectively setting "important" ones: they're all important.
2017-12-31 09:03:05 -05:00
Brett Smith
cb17033279 config: Only try to load the default config file if it exists. 2017-09-07 10:00:56 -04:00
Brett Smith
f7a57ded86 historical: Add comments to explain the precision-finding code. 2017-07-06 10:17:08 -04:00
Brett Smith
d0f5f1547c config: Error out when historical arguments are ambiguous. 2017-06-29 17:18:47 -04:00
Brett Smith
b270db02e8 historical: Ledger conversions show enough rate precision to stay balanced. 2017-06-29 16:54:16 -04:00
Brett Smith
8ab2373ba1 config: Assume abbreviated dates are in the past. 2017-06-22 15:54:24 -04:00
Martin Michlmayr
419f52abe3 Fix typo in variable name 2017-06-13 09:24:18 -04:00
Brett Smith
97222c2f75 setup: New version for recent changes. 2017-06-09 13:22:37 -04:00
Brett Smith
936237eceb config: Nicer determination of default currency for converting/signing.
base defaults to USD more as an API restriction than anything else, so avoid
using it as a default setting.  Instead, use the user's books denomination
or locale setting.
2017-06-09 13:22:12 -04:00
Brett Smith
dfac0cf853 config: Improve wording consistency of date format help. 2017-06-09 13:14:06 -04:00
Brett Smith
baa2e883cd config: historical command accepts just two currency arguments.
This shows the rates between two currencies without converting a specific
amount.
2017-06-09 13:11:16 -04:00
Brett Smith
55f5833aa0 historical: Add a setting to denominate Ledger conversions.
This makes conversion output easier to add to ledgers directly.
2017-06-09 11:06:51 -04:00
Brett Smith
992c91fc90 config: Nicer implementation of date parsing.
Keeps less local state through the function, to reduce the risk of that
state getting inconsistent.
2017-06-08 12:12:49 -04:00
Brett Smith
385a492ae7 config: More flexible date parsing.
* Accept partial dates, filling in the current year and month as needed.
* Accept more separators.
2017-06-08 09:52:47 -04:00
Brett Smith
17ff9a8b71 setup.py: Add oxrlib.commands package. 2017-06-01 14:01:11 -04:00
Brett Smith
0b6edde60c README: Markup fixes throughout. 2017-05-22 11:24:43 -04:00
Brett Smith
c8000a8a74 config: Print usage if no subcommand is given. 2017-05-19 10:21:33 -04:00
Brett Smith
b1fda6a647 config: Touch up historical --help output throughout. 2017-05-19 10:05:53 -04:00
Brett Smith
9be9b07a8d historical: Add Ledger output formatting. 2017-05-18 13:49:05 -04:00
Brett Smith
5b7f2b92a1 rate: Make sure to parse ints as Decimal objects too. 2017-05-18 13:33:32 -04:00
Brett Smith
ec3b9e83f8 historical: Format amounts according to currency convention. 2017-05-17 17:38:45 -04:00
Brett Smith
84bc0c7e84 tests: Rename TestCacheFile to avoid pytest warnings. 2017-05-17 17:33:15 -04:00
Brett Smith
348b82e087 .gitignore: setup.py: Integrate pytest to run tests. 2017-05-17 17:22:39 -04:00
Brett Smith
a6e46b0cca Documentation: Add README and example config. 2017-05-17 16:23:56 -04:00
Brett Smith
63b0ad3c76 Configuration: Improve --help output throughout. 2017-05-17 15:34:51 -04:00
Brett Smith
5fb01151d1 .gitignore: Ignore egg-info. 2017-05-17 15:31:24 -04:00
Brett Smith
8e5cb0642f CacheWriter: Update tests for previous open file change. 2017-05-17 15:29:21 -04:00
Brett Smith
08840e6757 setup.py: Start script. 2017-05-17 14:42:22 -04:00
Brett Smith
cff18d9d96 LICENSE: Add license. 2017-05-17 14:40:50 -04:00
Brett Smith
b49356bcb6 __main__: Start module to run the tool. 2017-05-17 14:40:43 -04:00
Brett Smith
3b5a563ef6 historical: Write results to cache when appropriate. 2017-05-17 12:56:19 -04:00
Brett Smith
7ae8c359e0 CacheFile opens the file immediately.
This is necessary to work correctly with the error-catching logic of LoaderChain.
2017-05-17 12:52:37 -04:00
Brett Smith
cdc748c14f config: Fix type of path passed to cache classes. 2017-05-17 12:52:02 -04:00
Brett Smith
620816fe72 config: Fix date_from type return value. 2017-05-17 12:45:19 -04:00