summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Bulatov <oleg@bulatov.me>2022-05-05 08:11:05 +0200
committerMartin Michlmayr <tbm@cyrius.com>2022-05-06 06:47:07 +0800
commit54991cc22e51733bfeadb1fdd8b3001b06df4d74 (patch)
tree98015b5e3abf3ce4352997bf1802afbc5e26e178
parented0b99fcfc37844f5d88eb7678ca23b490fd5b98 (diff)
downloadfork-ledger-54991cc22e51733bfeadb1fdd8b3001b06df4d74.tar.gz
fork-ledger-54991cc22e51733bfeadb1fdd8b3001b06df4d74.tar.bz2
fork-ledger-54991cc22e51733bfeadb1fdd8b3001b06df4d74.zip
Fix unrounding for equity
-rw-r--r--src/chain.cc2
-rw-r--r--src/filters.cc2
-rw-r--r--src/filters.h5
-rw-r--r--test/regress/equity-unround.test30
4 files changed, 36 insertions, 3 deletions
diff --git a/src/chain.cc b/src/chain.cc
index 7ac7d593..3a96f921 100644
--- a/src/chain.cc
+++ b/src/chain.cc
@@ -213,7 +213,7 @@ post_handler_ptr chain_post_handlers(post_handler_ptr base_handler,
// day_of_week_posts is like period_posts, except that it reports
// all the posts that fall on each subsequent day of the week.
if (report.HANDLED(equity))
- handler.reset(new posts_as_equity(handler, report, expr));
+ handler.reset(new posts_as_equity(handler, report, expr, report.HANDLED(unround)));
else if (report.HANDLED(subtotal))
handler.reset(new subtotal_posts(handler, expr));
}
diff --git a/src/filters.cc b/src/filters.cc
index 6db8af80..7f615785 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -1106,6 +1106,8 @@ void posts_as_equity::report_subtotal()
value_t total = 0L;
foreach (values_map::value_type& pair, values) {
value_t value(pair.second.value.strip_annotations(report.what_to_keep()));
+ if (unround)
+ value.in_place_unround();
if (! value.is_zero()) {
if (value.is_balance()) {
value.as_balance_lval().map_sorted_amounts
diff --git a/src/filters.h b/src/filters.h
index 4972b710..7252b057 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -790,13 +790,14 @@ class posts_as_equity : public subtotal_posts
post_t * last_post;
account_t * equity_account;
account_t * balance_account;
+ bool unround;
posts_as_equity();
public:
posts_as_equity(post_handler_ptr _handler, report_t& _report,
- expr_t& amount_expr)
- : subtotal_posts(_handler, amount_expr), report(_report) {
+ expr_t& amount_expr, bool _unround)
+ : subtotal_posts(_handler, amount_expr), report(_report), unround(_unround) {
create_accounts();
TRACE_CTOR(posts_as_equity, "post_handler_ptr, expr_t&");
}
diff --git a/test/regress/equity-unround.test b/test/regress/equity-unround.test
new file mode 100644
index 00000000..0fae2c9d
--- /dev/null
+++ b/test/regress/equity-unround.test
@@ -0,0 +1,30 @@
+commodity EUR
+ note Euro
+ format 1,000.00 EUR
+
+2022/05/04 * Test 1
+ Assets:Foo 1.0001 EUR
+ Income
+
+2022/05/04 * Test 2
+ Assets:Bar 0.0002 EUR
+ Income
+
+2022/05/04 * Test 3
+ Assets:Baz 3 EUR
+ Income
+
+test equity ^Assets: --unround
+2022/05/04 Opening Balances
+ Assets:Bar 0.0002 EUR
+ Assets:Baz 3.00 EUR
+ Assets:Foo 1.0001 EUR
+ Equity:Opening Balances -4.0003 EUR
+end test
+
+test reg --equity ^Assets: --unround
+22-May-04 Opening Balances Assets:Bar 0.0002 EUR 0.0002 EUR
+ Assets:Baz 3.00 EUR 3.0002 EUR
+ Assets:Foo 1.0001 EUR 4.0003 EUR
+ Equit:Opening Balances -4.0003 EUR 0
+end test