summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amount.cc30
-rw-r--r--amount.h9
-rw-r--r--main.py3
-rw-r--r--textual.cc2
4 files changed, 32 insertions, 12 deletions
diff --git a/amount.cc b/amount.cc
index 181f73da..48af1aa7 100644
--- a/amount.cc
+++ b/amount.cc
@@ -1056,6 +1056,16 @@ struct commodity_updater_wrap : public commodity_t::updater_t
}
};
+commodity_t * py_find_commodity_1(const std::string& symbol)
+{
+ return commodity_t::find_commodity(symbol);
+}
+
+commodity_t * py_find_commodity_2(const std::string& symbol, bool auto_create)
+{
+ return commodity_t::find_commodity(symbol, auto_create);
+}
+
void export_amount()
{
class_< amount_t > ("Amount")
@@ -1117,6 +1127,13 @@ void export_amount()
("Updater")
;
+ scope().attr("COMMODITY_STYLE_DEFAULTS") = COMMODITY_STYLE_DEFAULTS;
+ scope().attr("COMMODITY_STYLE_SUFFIXED") = COMMODITY_STYLE_SUFFIXED;
+ scope().attr("COMMODITY_STYLE_SEPARATED") = COMMODITY_STYLE_SEPARATED;
+ scope().attr("COMMODITY_STYLE_EUROPEAN") = COMMODITY_STYLE_EUROPEAN;
+ scope().attr("COMMODITY_STYLE_THOUSANDS") = COMMODITY_STYLE_THOUSANDS;
+ scope().attr("COMMODITY_STYLE_NOMARKET") = COMMODITY_STYLE_NOMARKET;
+
class_< commodity_t > ("Commodity")
.def(init<std::string, optional<unsigned int, unsigned int> >())
@@ -1131,18 +1148,21 @@ void export_amount()
.def_readwrite("ident", &commodity_t::ident)
.def_readwrite("updater", &commodity_t::updater)
- .def("add_commodity", &commodity_t::add_commodity)
- .def("remove_commodity", &commodity_t::remove_commodity)
- .def("find_commodity", &commodity_t::find_commodity,
- return_value_policy<reference_existing_object>())
+ .def(self_ns::str(self))
.def("add_price", &commodity_t::add_price)
.def("remove_price", &commodity_t::remove_price)
- .def("set_conversion", &commodity_t::set_conversion)
.def("value", &commodity_t::value)
.def("valid", &commodity_t::valid)
;
+
+ def("add_commodity", &commodity_t::add_commodity);
+ def("remove_commodity", &commodity_t::remove_commodity);
+ def("find_commodity", py_find_commodity_1,
+ return_value_policy<reference_existing_object>());
+ def("find_commodity", py_find_commodity_2,
+ return_value_policy<reference_existing_object>());
}
#endif // USE_BOOST_PYTHON
diff --git a/amount.h b/amount.h
index 17fec339..3d165b34 100644
--- a/amount.h
+++ b/amount.h
@@ -346,10 +346,6 @@ class commodity_t
return n > 0;
}
- void set_conversion(const amount_t& price) {
- conversion = price;
- }
-
amount_t value(const std::time_t moment = std::time(NULL));
bool valid() const {
@@ -369,6 +365,11 @@ class commodity_t
}
};
+inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
+ out << comm.symbol;
+ return out;
+}
+
inline commodity_t& amount_t::commodity() const {
if (! commodity_)
return *commodity_t::null_commodity;
diff --git a/main.py b/main.py
index cad0e6e8..e3f266a3 100644
--- a/main.py
+++ b/main.py
@@ -37,6 +37,5 @@ for entry in journal:
for xact in entry:
handler (xact)
-span = Interval ("weekly last month")
-for date in span:
+for date in Interval ("weekly last month"):
print time.strftime ("%c", time.localtime (date))
diff --git a/textual.cc b/textual.cc
index 8f231b5e..53310a63 100644
--- a/textual.cc
+++ b/textual.cc
@@ -484,7 +484,7 @@ unsigned int textual_parser_t::parse(std::istream& in,
price.parse(skip_ws(line));
commodity_t * commodity = commodity_t::find_commodity(symbol, true);
- commodity->set_conversion(price);
+ commodity->conversion = price;
break;
}