added support for "equity" in main.py
This commit is contained in:
parent
d110df6741
commit
528019ce25
6 changed files with 89 additions and 17 deletions
12
journal.cc
12
journal.cc
|
|
@ -569,6 +569,16 @@ account_t * py_find_account_2(journal_t& journal, const std::string& name,
|
|||
return journal.find_account(name, auto_create);
|
||||
}
|
||||
|
||||
PyObject * py_account_get_data(account_t& account)
|
||||
{
|
||||
return (PyObject *) account.data;
|
||||
}
|
||||
|
||||
void py_account_set_data(account_t& account, PyObject * obj)
|
||||
{
|
||||
account.data = obj;
|
||||
}
|
||||
|
||||
struct py_entry_finalizer_t : public entry_finalizer_t {
|
||||
object pyobj;
|
||||
py_entry_finalizer_t() {}
|
||||
|
|
@ -656,7 +666,7 @@ void export_journal()
|
|||
.def_readwrite("note", &account_t::note)
|
||||
.def_readonly("depth", &account_t::depth)
|
||||
.def_readonly("transactions", &account_t::transactions)
|
||||
.def_readwrite("data", &account_t::data)
|
||||
.add_property("data", py_account_get_data, py_account_set_data)
|
||||
.def_readonly("ident", &account_t::ident)
|
||||
|
||||
.def(self_ns::str(self))
|
||||
|
|
|
|||
59
main.py
59
main.py
|
|
@ -17,6 +17,7 @@
|
|||
import os
|
||||
import sys
|
||||
import string
|
||||
import time
|
||||
|
||||
true, false = 1, 0
|
||||
|
||||
|
|
@ -243,6 +244,50 @@ class FormatAccount (AccountHandler):
|
|||
self.output.write(self.formatter.format(account))
|
||||
account_xdata (account).dflags |= ACCOUNT_DISPLAYED
|
||||
|
||||
class FormatEquity (AccountHandler):
|
||||
output = None
|
||||
|
||||
def __init__ (self, fmt, pred):
|
||||
try:
|
||||
i = string.index (fmt, '%/')
|
||||
self.formatter = Format (fmt[: i])
|
||||
self.nformatter = Format (fmt[i + 2 :])
|
||||
except ValueError:
|
||||
self.formatter = Format (fmt)
|
||||
self.nformatter = None
|
||||
|
||||
self.predicate = AccountPredicate (pred)
|
||||
self.total = Value ()
|
||||
|
||||
if config.output_file:
|
||||
self.output = open(config.output_file, "w")
|
||||
else:
|
||||
self.output = sys.stdout
|
||||
|
||||
AccountHandler.__init__ (self)
|
||||
|
||||
header_entry = Entry ()
|
||||
header_entry.payee = "Opening Balances"
|
||||
header_entry.date = int(time.time())
|
||||
self.output.write (self.formatter.format (header_entry))
|
||||
|
||||
def __del__ (self):
|
||||
if config.output_file:
|
||||
self.output.close ()
|
||||
|
||||
def flush (self):
|
||||
summary = Account(Account (), "Equity:Opening Balances")
|
||||
account_xdata (summary).value = - self.total
|
||||
self.output.write (self.nformatter.format (summary))
|
||||
self.output.flush ()
|
||||
|
||||
def __call__ (self, account):
|
||||
if display_account (account, self.predicate):
|
||||
self.output.write(self.nformatter.format (account))
|
||||
if account_has_xdata (account):
|
||||
self.total += account_xdata (account).value
|
||||
account_xdata (account).dflags |= ACCOUNT_DISPLAYED
|
||||
|
||||
# Set the final transaction handler: for balances and equity reports,
|
||||
# it will simply add the value of the transaction to the account's
|
||||
# xdata, which is used a bit later to report those totals. For all
|
||||
|
|
@ -332,12 +377,11 @@ if command == "b":
|
|||
# print "--------------------"
|
||||
# config.format.format(out, details_t(*journal->master));
|
||||
|
||||
#elif command == "E":
|
||||
# format_equity acct_formatter(out, config.format, config.nformat,
|
||||
# config.display_predicate);
|
||||
# sum_accounts(*journal->master);
|
||||
# walk_accounts(*journal->master, acct_formatter, config.sort_string);
|
||||
# acct_formatter.flush();
|
||||
elif command == "E":
|
||||
acct_formatter = FormatEquity (format, config.display_predicate)
|
||||
sum_accounts (journal.master)
|
||||
walk_accounts (journal.master, acct_formatter, config.sort_string)
|
||||
acct_formatter.flush ()
|
||||
|
||||
# If the cache is being used, and is dirty, update it now.
|
||||
|
||||
|
|
@ -345,3 +389,6 @@ if config.use_cache and config.cache_dirty and config.cache_file:
|
|||
write_binary_journal(config.cache_file, journal);
|
||||
|
||||
# We're done!
|
||||
|
||||
clear_transactions_xdata ()
|
||||
clear_accounts_xdata ()
|
||||
|
|
|
|||
2
value.cc
2
value.cc
|
|
@ -707,6 +707,8 @@ void export_value()
|
|||
.def(other<amount_t>() / self)
|
||||
.def(int() / self)
|
||||
|
||||
.def(- self)
|
||||
|
||||
.def(self += self)
|
||||
.def(self += other<balance_pair_t>())
|
||||
.def(self += other<balance_t>())
|
||||
|
|
|
|||
12
value.h
12
value.h
|
|
@ -242,10 +242,18 @@ class value_t
|
|||
template <typename T>
|
||||
operator T() const;
|
||||
|
||||
void cast(type_t cast_type);
|
||||
void negate();
|
||||
void abs();
|
||||
value_t negated() const {
|
||||
value_t temp = *this;
|
||||
temp.negate();
|
||||
return temp;
|
||||
}
|
||||
value_t operator-() const {
|
||||
return negated();
|
||||
}
|
||||
|
||||
void abs();
|
||||
void cast(type_t cast_type);
|
||||
value_t cost() const;
|
||||
};
|
||||
|
||||
|
|
|
|||
12
walk.cc
12
walk.cc
|
|
@ -309,6 +309,16 @@ void dow_transactions::flush()
|
|||
}
|
||||
}
|
||||
|
||||
void clear_transactions_xdata()
|
||||
{
|
||||
transactions_xdata.clear();
|
||||
|
||||
for (std::list<void **>::iterator i = transactions_xdata_ptrs.begin();
|
||||
i != transactions_xdata_ptrs.end();
|
||||
i++)
|
||||
**i = NULL;
|
||||
}
|
||||
|
||||
void sum_accounts(account_t& account)
|
||||
{
|
||||
for (accounts_map::iterator i = account.accounts.begin();
|
||||
|
|
@ -469,6 +479,7 @@ void export_walk()
|
|||
|
||||
def("transaction_has_xdata", transaction_has_xdata);
|
||||
def("transaction_xdata", transaction_xdata, return_internal_reference<1>());
|
||||
def("clear_transactions_xdata", clear_transactions_xdata);
|
||||
|
||||
class_< xact_handler_t, item_handler_wrap<transaction_t> >
|
||||
("TransactionHandler")
|
||||
|
|
@ -579,6 +590,7 @@ void export_walk()
|
|||
|
||||
def("account_has_xdata", account_has_xdata);
|
||||
def("account_xdata", account_xdata, return_internal_reference<1>());
|
||||
def("clear_accounts_xdata", clear_accounts_xdata);
|
||||
|
||||
class_< account_handler_t, item_handler_wrap<account_t> > ("AccountHandler")
|
||||
.def(init<account_handler_t *>())
|
||||
|
|
|
|||
9
walk.h
9
walk.h
|
|
@ -143,14 +143,7 @@ inline void walk_entries(entries_list& list,
|
|||
walk_entries(list.begin(), list.end(), handler);
|
||||
}
|
||||
|
||||
inline void clear_transactions_xdata() {
|
||||
transactions_xdata.clear();
|
||||
|
||||
for (std::list<void **>::iterator i = transactions_xdata_ptrs.begin();
|
||||
i != transactions_xdata_ptrs.end();
|
||||
i++)
|
||||
**i = NULL;
|
||||
}
|
||||
void clear_transactions_xdata();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue