summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-11 03:06:50 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-03-11 03:06:50 -0500
commit2303aa993cf41ad5bde8f8f5722bd265c11e3aa7 (patch)
treec5ff39ce90a7ef74900b723f58495eb895e2bc1d
parent0d9d8453387e0f49f0dd4ea4b5f090da91c283bd (diff)
downloadfork-ledger-2303aa993cf41ad5bde8f8f5722bd265c11e3aa7.tar.gz
fork-ledger-2303aa993cf41ad5bde8f8f5722bd265c11e3aa7.tar.bz2
fork-ledger-2303aa993cf41ad5bde8f8f5722bd265c11e3aa7.zip
Allow balances to be passed to nail_down
Fixes #679
-rw-r--r--src/report.cc23
-rw-r--r--src/value.cc2
-rw-r--r--test/regress/14DB77E7.test18
3 files changed, 42 insertions, 1 deletions
diff --git a/src/report.cc b/src/report.cc
index fb585ce1..8205c1dd 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -794,6 +794,29 @@ value_t report_t::fn_nail_down(call_scope_t& args)
return tmp;
}
+ case value_t::BALANCE: {
+ balance_t tmp;
+ foreach (const balance_t::amounts_map::value_type& pair,
+ arg0.as_balance_lval().amounts) {
+ call_scope_t inner_args(*args.parent);
+ inner_args.push_back(pair.second);
+ inner_args.push_back(arg1);
+ tmp += fn_nail_down(inner_args).as_amount();
+ }
+ return tmp;
+ }
+
+ case value_t::SEQUENCE: {
+ value_t tmp;
+ foreach (value_t& value, arg0.as_sequence_lval()) {
+ call_scope_t inner_args(*args.parent);
+ inner_args.push_back(value);
+ inner_args.push_back(arg1);
+ tmp.push_back(fn_nail_down(inner_args));
+ }
+ return tmp;
+ }
+
default:
throw_(std::runtime_error, _("Attempting to nail down %1")
<< args[0].label());
diff --git a/src/value.cc b/src/value.cc
index 97328c37..c4e7170d 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -724,7 +724,7 @@ value_t& value_t::operator/=(const value_t& val)
return *this;
case AMOUNT:
if (as_balance().single_amount()) {
- in_place_simplify();
+ in_place_cast(AMOUNT);
as_amount_lval() /= val.as_amount();
return *this;
}
diff --git a/test/regress/14DB77E7.test b/test/regress/14DB77E7.test
new file mode 100644
index 00000000..ee155afb
--- /dev/null
+++ b/test/regress/14DB77E7.test
@@ -0,0 +1,18 @@
+D 1000.00 GBP
+
+;P 2011-01-01 EUR 0.8604 GBP
+P 2011-02-01 EUR 0.8576 GBP
+
+2011-01-31 * AdSense earnings
+ Assets:Receivable:AdSense 11.00 EUR
+ Income:AdSense
+
+2011-02-28 * AdSense earnings
+ Assets:Receivable:AdSense 10.00 EUR
+ Income:AdSense
+
+test reg income:adse -X GBP -H
+11-Jan-31 AdSense earnings Income:AdSense -11.00 EUR -11.00 EUR
+11-Feb-01 Commodities revalued <Revalued> -9.43 GBP -9.43 GBP
+11-Feb-28 AdSense earnings Income:AdSense -8.58 GBP -18.01 GBP
+end test