summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-20 23:08:42 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-20 23:12:23 -0400
commitfc349389e3f074ae2ce22b93f3833f063f548a8f (patch)
treeb235bf0a9b6ca21aac1bcd56c8462f5570202723
parent96ff798736cd06812fb7e463c14d6c356c8228e3 (diff)
downloadfork-ledger-fc349389e3f074ae2ce22b93f3833f063f548a8f.tar.gz
fork-ledger-fc349389e3f074ae2ce22b93f3833f063f548a8f.tar.bz2
fork-ledger-fc349389e3f074ae2ce22b93f3833f063f548a8f.zip
Restored the --budget option
-rw-r--r--python/py_value.cc2
-rw-r--r--src/amount.h6
-rw-r--r--src/balance.cc2
-rw-r--r--src/entry.cc6
-rw-r--r--src/filters.cc8
-rw-r--r--src/op.cc2
-rw-r--r--src/value.h4
-rw-r--r--test/baseline/opt-budget.test272
-rw-r--r--test/unit/t_amount.cc18
9 files changed, 296 insertions, 24 deletions
diff --git a/python/py_value.cc b/python/py_value.cc
index 79b367a1..a4de7c04 100644
--- a/python/py_value.cc
+++ b/python/py_value.cc
@@ -174,7 +174,7 @@ void export_value()
.def(self / double())
.def(double() / self)
- .def("negate", &value_t::negate)
+ .def("negated", &value_t::negated)
.def("in_place_negate", &value_t::in_place_negate)
.def("in_place_not", &value_t::in_place_not)
.def(- self)
diff --git a/src/amount.h b/src/amount.h
index a20b46b1..730d3569 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -291,7 +291,7 @@ public:
/** Returns the negated value of an amount.
@see operator-()
*/
- amount_t negate() const {
+ amount_t negated() const {
amount_t temp(*this);
temp.in_place_negate();
return temp;
@@ -299,7 +299,7 @@ public:
void in_place_negate();
amount_t operator-() const {
- return negate();
+ return negated();
}
/** Returns the absolute value of an amount. Equivalent to:
@@ -309,7 +309,7 @@ public:
*/
amount_t abs() const {
if (sign() < 0)
- return negate();
+ return negated();
return *this;
}
diff --git a/src/balance.cc b/src/balance.cc
index 92a6c767..b8009607 100644
--- a/src/balance.cc
+++ b/src/balance.cc
@@ -81,7 +81,7 @@ balance_t& balance_t::operator-=(const amount_t& amt)
if (i->second.is_realzero())
amounts.erase(i);
} else {
- amounts.insert(amounts_map::value_type(&amt.commodity(), amt.negate()));
+ amounts.insert(amounts_map::value_type(&amt.commodity(), amt.negated()));
}
return *this;
}
diff --git a/src/entry.cc b/src/entry.cc
index ffcd3a51..a07481f1 100644
--- a/src/entry.cc
+++ b/src/entry.cc
@@ -140,16 +140,16 @@ bool entry_base_t::finalize()
const balance_t& bal(balance.as_balance());
foreach (const balance_t::amounts_map::value_type& pair, bal.amounts) {
if (first) {
- null_xact->amount = pair.second.negate();
+ null_xact->amount = pair.second.negated();
first = false;
} else {
- add_xact(new xact_t(null_xact->account, pair.second.negate(),
+ add_xact(new xact_t(null_xact->account, pair.second.negated(),
ITEM_GENERATED));
}
}
}
else if (balance.is_amount()) {
- null_xact->amount = balance.as_amount().negate();
+ null_xact->amount = balance.as_amount().negated();
null_xact->add_flags(XACT_CALCULATED);
}
else if (! balance.is_null() && ! balance.is_realzero()) {
diff --git a/src/filters.cc b/src/filters.cc
index 0e719037..0bb4cf98 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -215,11 +215,11 @@ void invert_xacts::operator()(xact_t& xact)
{
if (xact.has_xdata() &&
xact.xdata().has_flags(XACT_EXT_COMPOUND)) {
- xact.xdata().value.negate();
+ xact.xdata().value.in_place_negate();
} else {
- xact.amount.negate();
+ xact.amount.in_place_negate();
if (xact.cost)
- xact.cost->negate();
+ xact.cost->in_place_negate();
}
item_handler<xact_t>::operator()(xact);
@@ -705,7 +705,7 @@ void budget_xacts::report_budget_items(const date_t& date)
xact_t& temp = xact_temps.back();
temp.entry = &entry;
temp.add_flags(XACT_AUTO | ITEM_TEMP);
- temp.amount.negate();
+ temp.amount.in_place_negate();
entry.add_xact(&temp);
begin = pair.first.increment(begin);
diff --git a/src/op.cc b/src/op.cc
index 7dbbf3a2..389baf38 100644
--- a/src/op.cc
+++ b/src/op.cc
@@ -234,7 +234,7 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus)
break;
case O_NEG:
- result = left()->calc(scope, locus).negate();
+ result = left()->calc(scope, locus).negated();
break;
case O_NOT:
diff --git a/src/value.h b/src/value.h
index e3190ef4..3a052fb2 100644
--- a/src/value.h
+++ b/src/value.h
@@ -391,7 +391,7 @@ public:
/**
* Unary arithmetic operators.
*/
- value_t negate() const {
+ value_t negated() const {
value_t temp = *this;
temp.in_place_negate();
return temp;
@@ -400,7 +400,7 @@ public:
void in_place_not(); // exists for efficiency's sake
value_t operator-() const {
- return negate();
+ return negated();
}
value_t abs() const;
diff --git a/test/baseline/opt-budget.test b/test/baseline/opt-budget.test
new file mode 100644
index 00000000..154a61d8
--- /dev/null
+++ b/test/baseline/opt-budget.test
@@ -0,0 +1,272 @@
+reg --budget books
+<<<
+~ monthly
+ Expenses:Books $10.00
+ Assets:Cash
+
+2008/01/01 January
+ Expenses:Books $10.00
+ Assets:Cash
+
+2008/01/31 End of January
+ Expenses:Books $10.00
+ Assets:Cash
+
+2008/02/01 February
+ Expenses:Books $20.00
+ Assets:Cash
+
+2008/02/28 End of February
+ Expenses:Books $20.00
+ Assets:Cash
+
+2008/03/01 March
+ Expenses:Books $30.00
+ Assets:Cash
+
+2008/03/31 End of March
+ Expenses:Books $30.00
+ Assets:Cash
+
+2008/04/01 April
+ Expenses:Books $40.00
+ Assets:Cash
+
+2008/04/30 End of April
+ Expenses:Books $40.00
+ Assets:Cash
+
+2008/05/01 May
+ Expenses:Books $50.00
+ Assets:Cash
+
+2008/05/31 End of May
+ Expenses:Books $50.00
+ Assets:Cash
+
+2008/06/01 June
+ Expenses:Books $60.00
+ Assets:Cash
+
+2008/06/30 End of June
+ Expenses:Books $60.00
+ Assets:Cash
+
+2008/07/01 July
+ Expenses:Books $70.00
+ Assets:Cash
+
+2008/07/31 End of July
+ Expenses:Books $70.00
+ Assets:Cash
+
+2008/08/01 August
+ Expenses:Books $80.00
+ Assets:Cash
+
+2008/08/31 End of August
+ Expenses:Books $80.00
+ Assets:Cash
+
+2008/09/01 September
+ Expenses:Books $90.00
+ Assets:Cash
+
+2008/09/30 End of September
+ Expenses:Books $90.00
+ Assets:Cash
+
+2008/10/01 October
+ Expenses:Books $100.00
+ Assets:Cash
+
+2008/10/31 End of October
+ Expenses:Books $100.00
+ Assets:Cash
+
+2008/11/01 November
+ Expenses:Books $110.00
+ Assets:Cash
+
+2008/11/30 End of November
+ Expenses:Books $110.00
+ Assets:Cash
+
+2008/12/01 December
+ Expenses:Books $120.00
+ Assets:Cash
+
+2008/12/31 End of December
+ Expenses:Books $120.00
+ Assets:Cash
+
+2009/01/01 January
+ Expenses:Books $10.00
+ Assets:Cash
+
+2009/01/31 End of January
+ Expenses:Books $10.00
+ Assets:Cash
+
+2009/02/01 February
+ Expenses:Books $20.00
+ Assets:Cash
+
+2009/02/28 End of February
+ Expenses:Books $20.00
+ Assets:Cash
+
+2009/03/01 March
+ Expenses:Books $30.00
+ Assets:Cash
+
+2009/03/31 End of March
+ Expenses:Books $30.00
+ Assets:Cash
+
+2009/04/01 April
+ Expenses:Books $40.00
+ Assets:Cash
+
+2009/04/30 End of April
+ Expenses:Books $40.00
+ Assets:Cash
+
+2009/05/01 May
+ Expenses:Books $50.00
+ Assets:Cash
+
+2009/05/31 End of May
+ Expenses:Books $50.00
+ Assets:Cash
+
+2009/06/01 June
+ Expenses:Books $60.00
+ Assets:Cash
+
+2009/06/30 End of June
+ Expenses:Books $60.00
+ Assets:Cash
+
+2009/07/01 July
+ Expenses:Books $70.00
+ Assets:Cash
+
+2009/07/31 End of July
+ Expenses:Books $70.00
+ Assets:Cash
+
+2009/08/01 August
+ Expenses:Books $80.00
+ Assets:Cash
+
+2009/08/31 End of August
+ Expenses:Books $80.00
+ Assets:Cash
+
+2009/09/01 September
+ Expenses:Books $90.00
+ Assets:Cash
+
+2009/09/30 End of September
+ Expenses:Books $90.00
+ Assets:Cash
+
+2009/10/01 October
+ Expenses:Books $100.00
+ Assets:Cash
+
+2009/10/31 End of October
+ Expenses:Books $100.00
+ Assets:Cash
+
+2009/11/01 November
+ Expenses:Books $110.00
+ Assets:Cash
+
+2009/11/30 End of November
+ Expenses:Books $110.00
+ Assets:Cash
+
+2009/12/01 December
+ Expenses:Books $120.00
+ Assets:Cash
+
+2009/12/31 End of December
+ Expenses:Books $120.00
+ Assets:Cash
+>>>1
+08-Jan-01 January Expenses:Books $10.00 $10.00
+08-Jan-01 Budget entry Expenses:Books $-10.00 0
+08-Jan-31 End of January Expenses:Books $10.00 $10.00
+08-Feb-01 February Expenses:Books $20.00 $30.00
+08-Feb-01 Budget entry Expenses:Books $-10.00 $20.00
+08-Feb-28 End of February Expenses:Books $20.00 $40.00
+08-Mar-01 March Expenses:Books $30.00 $70.00
+08-Mar-01 Budget entry Expenses:Books $-10.00 $60.00
+08-Mar-31 End of March Expenses:Books $30.00 $90.00
+08-Apr-01 April Expenses:Books $40.00 $130.00
+08-Apr-01 Budget entry Expenses:Books $-10.00 $120.00
+08-Apr-30 End of April Expenses:Books $40.00 $160.00
+08-May-01 May Expenses:Books $50.00 $210.00
+08-May-01 Budget entry Expenses:Books $-10.00 $200.00
+08-May-31 End of May Expenses:Books $50.00 $250.00
+08-Jun-01 June Expenses:Books $60.00 $310.00
+08-Jun-01 Budget entry Expenses:Books $-10.00 $300.00
+08-Jun-30 End of June Expenses:Books $60.00 $360.00
+08-Jul-01 July Expenses:Books $70.00 $430.00
+08-Jul-01 Budget entry Expenses:Books $-10.00 $420.00
+08-Jul-31 End of July Expenses:Books $70.00 $490.00
+08-Aug-01 August Expenses:Books $80.00 $570.00
+08-Aug-01 Budget entry Expenses:Books $-10.00 $560.00
+08-Aug-31 End of August Expenses:Books $80.00 $640.00
+08-Sep-01 September Expenses:Books $90.00 $730.00
+08-Sep-01 Budget entry Expenses:Books $-10.00 $720.00
+08-Sep-30 End of September Expenses:Books $90.00 $810.00
+08-Oct-01 October Expenses:Books $100.00 $910.00
+08-Oct-01 Budget entry Expenses:Books $-10.00 $900.00
+08-Oct-31 End of October Expenses:Books $100.00 $1000.00
+08-Nov-01 November Expenses:Books $110.00 $1110.00
+08-Nov-01 Budget entry Expenses:Books $-10.00 $1100.00
+08-Nov-30 End of November Expenses:Books $110.00 $1210.00
+08-Dec-01 December Expenses:Books $120.00 $1330.00
+08-Dec-01 Budget entry Expenses:Books $-10.00 $1320.00
+08-Dec-31 End of December Expenses:Books $120.00 $1440.00
+09-Jan-01 January Expenses:Books $10.00 $1450.00
+09-Jan-01 Budget entry Expenses:Books $-10.00 $1440.00
+09-Jan-31 End of January Expenses:Books $10.00 $1450.00
+09-Feb-01 February Expenses:Books $20.00 $1470.00
+09-Feb-01 Budget entry Expenses:Books $-10.00 $1460.00
+09-Feb-28 End of February Expenses:Books $20.00 $1480.00
+09-Mar-01 March Expenses:Books $30.00 $1510.00
+09-Mar-01 Budget entry Expenses:Books $-10.00 $1500.00
+09-Mar-31 End of March Expenses:Books $30.00 $1530.00
+09-Apr-01 April Expenses:Books $40.00 $1570.00
+09-Apr-01 Budget entry Expenses:Books $-10.00 $1560.00
+09-Apr-30 End of April Expenses:Books $40.00 $1600.00
+09-May-01 May Expenses:Books $50.00 $1650.00
+09-May-01 Budget entry Expenses:Books $-10.00 $1640.00
+09-May-31 End of May Expenses:Books $50.00 $1690.00
+09-Jun-01 June Expenses:Books $60.00 $1750.00
+09-Jun-01 Budget entry Expenses:Books $-10.00 $1740.00
+09-Jun-30 End of June Expenses:Books $60.00 $1800.00
+09-Jul-01 July Expenses:Books $70.00 $1870.00
+09-Jul-01 Budget entry Expenses:Books $-10.00 $1860.00
+09-Jul-31 End of July Expenses:Books $70.00 $1930.00
+09-Aug-01 August Expenses:Books $80.00 $2010.00
+09-Aug-01 Budget entry Expenses:Books $-10.00 $2000.00
+09-Aug-31 End of August Expenses:Books $80.00 $2080.00
+09-Sep-01 September Expenses:Books $90.00 $2170.00
+09-Sep-01 Budget entry Expenses:Books $-10.00 $2160.00
+09-Sep-30 End of September Expenses:Books $90.00 $2250.00
+09-Oct-01 October Expenses:Books $100.00 $2350.00
+09-Oct-01 Budget entry Expenses:Books $-10.00 $2340.00
+09-Oct-31 End of October Expenses:Books $100.00 $2440.00
+09-Nov-01 November Expenses:Books $110.00 $2550.00
+09-Nov-01 Budget entry Expenses:Books $-10.00 $2540.00
+09-Nov-30 End of November Expenses:Books $110.00 $2650.00
+09-Dec-01 December Expenses:Books $120.00 $2770.00
+09-Dec-01 Budget entry Expenses:Books $-10.00 $2760.00
+09-Dec-31 End of December Expenses:Books $120.00 $2880.00
+>>>2
+=== 0
diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc
index 94553912..7e0f53b0 100644
--- a/test/unit/t_amount.cc
+++ b/test/unit/t_amount.cc
@@ -993,15 +993,15 @@ void AmountTestCase::testNegation()
amount_t x8(string("-123.456"));
amount_t x9(- x3);
- assertThrow(x0.negate(), amount_error);
+ assertThrow(x0.negated(), amount_error);
assertEqual(x5, x1);
assertEqual(x7, x1);
assertEqual(x6, x3);
assertEqual(x8, x3);
assertEqual(- x6, x9);
- assertEqual(x3.negate(), x9);
+ assertEqual(x3.negated(), x9);
- amount_t x10(x9.negate());
+ amount_t x10(x9.negated());
assertEqual(x3, x10);
@@ -1039,9 +1039,9 @@ void AmountTestCase::testCommodityNegation()
assertEqual(amount_t("-123.45€"), - x9);
assertEqual(amount_t("123.45€"), - x10);
- assertEqual(amount_t("$-123.45"), x1.negate());
- assertEqual(amount_t("$123.45"), x2.negate());
- assertEqual(amount_t("$123.45"), x3.negate());
+ assertEqual(amount_t("$-123.45"), x1.negated());
+ assertEqual(amount_t("$123.45"), x2.negated());
+ assertEqual(amount_t("$123.45"), x3.negated());
assertEqual(string("$-123.45"), (- x1).to_string());
assertEqual(string("$123.45"), (- x2).to_string());
@@ -1054,9 +1054,9 @@ void AmountTestCase::testCommodityNegation()
assertEqual(string("-123.45€"), (- x9).to_string());
assertEqual(string("123.45€"), (- x10).to_string());
- assertEqual(amount_t("$-123.45"), x1.negate());
- assertEqual(amount_t("$123.45"), x2.negate());
- assertEqual(amount_t("$123.45"), x3.negate());
+ assertEqual(amount_t("$-123.45"), x1.negated());
+ assertEqual(amount_t("$123.45"), x2.negated());
+ assertEqual(amount_t("$123.45"), x3.negated());
assertValid(x1);
assertValid(x2);