summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-05 14:27:58 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-05 14:27:58 -0500
commit67ce33430c1f37f0fa7da62e5bd055c5a00b614d (patch)
tree3357a0a2fd100f8dbf65e01ae1272770852c3e23
parent15555d497f56e4b4d39e9a14f74b2c82cce52b90 (diff)
parent09ace752d604d5afce698f7cc240e1a83cee934d (diff)
downloadfork-ledger-67ce33430c1f37f0fa7da62e5bd055c5a00b614d.tar.gz
fork-ledger-67ce33430c1f37f0fa7da62e5bd055c5a00b614d.tar.bz2
fork-ledger-67ce33430c1f37f0fa7da62e5bd055c5a00b614d.zip
Merge branch 'next'
-rwxr-xr-xacprep2
-rw-r--r--src/item.cc10
-rw-r--r--src/post.cc6
-rw-r--r--src/report.cc27
-rw-r--r--src/report.h1
-rw-r--r--src/value.cc2
6 files changed, 42 insertions, 6 deletions
diff --git a/acprep b/acprep
index a73e81f0..302a6368 100755
--- a/acprep
+++ b/acprep
@@ -385,7 +385,7 @@ class PrepareBuild(CommandLineApp):
def current_version(self):
if not self.current_ver:
if exists('.git') and isdir('.git'):
- date = self.get_stdout('git', 'log', '--format=%ci', 'HEAD^..HEAD')
+ date = self.get_stdout('git', 'log', '--format=%ci', '-1', 'HEAD')
date = re.sub(" [-+][0-9][0-9][0-9][0-9]$", "", date)
when = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
self.current_ver = when.strftime("%Y%m%d_%H%M%S")
diff --git a/src/item.cc b/src/item.cc
index acef2e44..f60db226 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -212,23 +212,23 @@ namespace {
else if (args[0].is_mask())
return item.has_tag(args[0].as_mask());
else
- throw_(std::logic_error,
- _("Expected string for argument 1, but received %1")
+ throw_(std::runtime_error,
+ _("Expected string or mask for argument 1, but received %1")
<< args[0].label());
}
else if (args.size() == 2) {
if (args[0].is_mask() && args[1].is_mask())
return item.has_tag(args[0].to_mask(), args[1].to_mask());
else
- throw_(std::logic_error,
+ throw_(std::runtime_error,
_("Expected masks for arguments 1 and 2, but received %1 and %2")
<< args[0].label() << args[1].label());
}
else if (args.size() == 0) {
- throw_(std::logic_error, _("Too few arguments to function"));
+ throw_(std::runtime_error, _("Too few arguments to function"));
}
else {
- throw_(std::logic_error, _("Too many arguments to function"));
+ throw_(std::runtime_error, _("Too many arguments to function"));
}
return false;
}
diff --git a/src/post.cc b/src/post.cc
index d7923866..4f45592f 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -160,6 +160,8 @@ namespace {
value_t get_amount(post_t& post) {
if (post.has_xdata() && post.xdata().has_flags(POST_EXT_COMPOUND))
return post.xdata().compound_value;
+ else if (post.amount.is_null())
+ return 0L;
else
return post.amount;
}
@@ -186,6 +188,8 @@ namespace {
else if (post.has_xdata() &&
post.xdata().has_flags(POST_EXT_COMPOUND))
return post.xdata().compound_value;
+ else if (post.amount.is_null())
+ return 0L;
else
return post.amount;
}
@@ -193,6 +197,8 @@ namespace {
value_t get_total(post_t& post) {
if (post.xdata_ && ! post.xdata_->total.is_null())
return post.xdata_->total;
+ else if (post.amount.is_null())
+ return 0L;
else
return post.amount;
}
diff --git a/src/report.cc b/src/report.cc
index e6f3ccb4..3b570682 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -313,6 +313,31 @@ value_t report_t::fn_price(call_scope_t& scope)
return args.value_at(0).price();
}
+value_t report_t::fn_account_total(call_scope_t& args)
+{
+ account_t * acct = NULL;
+ string name;
+ if (args[0].is_string()) {
+ name = args[0].as_string();
+ acct = session.journal->find_account(name, false);
+ }
+ else if (args[0].is_mask()) {
+ name = args[0].as_mask().expr.str();
+ acct = session.journal->find_account_re(name);
+ }
+ else {
+ throw_(std::runtime_error,
+ _("Expected string or mask for argument 1, but received %1")
+ << args[0].label());
+ }
+
+ if (! acct)
+ throw_(std::runtime_error,
+ _("Could not find an account matching ") << name);
+
+ return acct->amount();
+}
+
value_t report_t::fn_lot_date(call_scope_t& scope)
{
interactive_t args(scope, "v");
@@ -730,6 +755,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return MAKE_FUNCTOR(report_t::fn_ansify_if);
else if (is_eq(p, "abs"))
return MAKE_FUNCTOR(report_t::fn_abs);
+ else if (is_eq(p, "account_total"))
+ return MAKE_FUNCTOR(report_t::fn_account_total);
break;
case 'b':
diff --git a/src/report.h b/src/report.h
index 32648648..431eac3c 100644
--- a/src/report.h
+++ b/src/report.h
@@ -160,6 +160,7 @@ public:
value_t fn_ansify_if(call_scope_t& scope);
value_t fn_percent(call_scope_t& scope);
value_t fn_price(call_scope_t& scope);
+ value_t fn_account_total(call_scope_t& scope);
value_t fn_lot_date(call_scope_t& scope);
value_t fn_lot_price(call_scope_t& scope);
value_t fn_lot_tag(call_scope_t& scope);
diff --git a/src/value.cc b/src/value.cc
index a3a05b6c..4529300a 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -983,6 +983,8 @@ void value_t::in_place_cast(type_t cast_type)
if (type() == cast_type)
return;
+ _dup();
+
if (cast_type == BOOLEAN) {
set_boolean(bool(*this));
return;