account_amount() is now account().amount
This commit is contained in:
parent
115da19121
commit
a5f0b6e5dc
3 changed files with 39 additions and 65 deletions
76
src/post.cc
76
src/post.cc
|
|
@ -34,6 +34,7 @@
|
|||
#include "post.h"
|
||||
#include "xact.h"
|
||||
#include "account.h"
|
||||
#include "journal.h"
|
||||
#include "interactive.h"
|
||||
#include "unistring.h"
|
||||
#include "format.h"
|
||||
|
|
@ -212,13 +213,46 @@ namespace {
|
|||
|
||||
value_t get_account(call_scope_t& scope)
|
||||
{
|
||||
in_context_t<post_t> env(scope, "&l");
|
||||
in_context_t<post_t> env(scope, "&v");
|
||||
string name;
|
||||
account_t * account = NULL;
|
||||
bool seeking_account = false;
|
||||
|
||||
string name = env->reported_account()->fullname();
|
||||
if (env.has(0)) {
|
||||
if (env.value_at(0).is_long()) {
|
||||
if (env.get<long>(0) > 2)
|
||||
name = format_t::truncate(env->reported_account()->fullname(),
|
||||
env.get<long>(0) - 2,
|
||||
2 /* account_abbrev_length */);
|
||||
else
|
||||
name = env->reported_account()->fullname();
|
||||
}
|
||||
else if (env.value_at(0).is_string()) {
|
||||
name = env.get<string>(0);
|
||||
account = env->xact->journal->find_account(name, false);
|
||||
seeking_account = true;
|
||||
}
|
||||
else if (env.value_at(0).is_mask()) {
|
||||
name = env.get<mask_t>(0).str();
|
||||
account = env->xact->journal->find_account_re(name);
|
||||
seeking_account = true;
|
||||
}
|
||||
else {
|
||||
throw_(std::runtime_error,
|
||||
_("Expected string or mask for argument 1, but received %1")
|
||||
<< env.value_at(0).label());
|
||||
}
|
||||
|
||||
if (env.has(0) && env.get<long>(0) > 2)
|
||||
name = format_t::truncate(name, env.get<long>(0) - 2,
|
||||
2 /* account_abbrev_length */);
|
||||
if (seeking_account) {
|
||||
if (! account)
|
||||
throw_(std::runtime_error,
|
||||
_("Could not find an account matching ") << env.value_at(0));
|
||||
else
|
||||
return account; // return a scope object
|
||||
}
|
||||
} else {
|
||||
name = env->reported_account()->fullname();
|
||||
}
|
||||
|
||||
if (env->has_flags(POST_VIRTUAL)) {
|
||||
if (env->must_balance())
|
||||
|
|
@ -233,36 +267,6 @@ namespace {
|
|||
return string_value(post.reported_account()->name);
|
||||
}
|
||||
|
||||
value_t get_account_amount(call_scope_t& scope)
|
||||
{
|
||||
in_context_t<post_t> env(scope, "&v");
|
||||
|
||||
account_t * account = NULL;
|
||||
if (env.has(0)) {
|
||||
account_t * master = env->account;
|
||||
while (master->parent)
|
||||
master = master->parent;
|
||||
|
||||
if (env.value_at(0).is_string())
|
||||
account = master->find_account(env.get<string>(0), false);
|
||||
else if (env.value_at(0).is_mask())
|
||||
account = master->find_account_re(env.get<mask_t>(0).str());
|
||||
} else {
|
||||
account = env->reported_account();
|
||||
}
|
||||
|
||||
if (! account)
|
||||
throw_(std::runtime_error, _("Cannot locate referenced account"));
|
||||
|
||||
DEBUG("post.account_amount", "Found account: " << account->fullname());
|
||||
|
||||
value_t total = account->amount();
|
||||
if (total.is_null())
|
||||
return 0L;
|
||||
else
|
||||
return total.simplified();
|
||||
}
|
||||
|
||||
value_t get_account_depth(post_t& post) {
|
||||
return long(post.reported_account()->depth);
|
||||
}
|
||||
|
|
@ -289,8 +293,6 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind,
|
|||
return WRAP_FUNCTOR(get_wrapper<&get_amount>);
|
||||
else if (name == "account")
|
||||
return WRAP_FUNCTOR(get_account);
|
||||
else if (name == "account_amount")
|
||||
return WRAP_FUNCTOR(get_account_amount);
|
||||
else if (name == "account_base")
|
||||
return WRAP_FUNCTOR(get_wrapper<&get_account_base>);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -315,31 +315,6 @@ 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().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");
|
||||
|
|
@ -739,8 +714,6 @@ 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':
|
||||
|
|
|
|||
|
|
@ -151,7 +151,6 @@ 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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue