Added the notion of "virtual costs"
This commit is contained in:
parent
9f81c798ee
commit
c9f7195936
7 changed files with 24 additions and 8 deletions
|
|
@ -122,7 +122,12 @@ void annotation_t::parse(std::istream& in)
|
|||
else if (c == '(') {
|
||||
in.get(c);
|
||||
c = static_cast<char>(in.peek());
|
||||
if (c == '(') {
|
||||
if (c == '@') {
|
||||
in.clear();
|
||||
in.seekg(pos, std::ios::beg);
|
||||
break;
|
||||
}
|
||||
else if (c == '(') {
|
||||
if (value_expr)
|
||||
throw_(amount_error,
|
||||
_("Commodity specifies more than one valuation expresion"));
|
||||
|
|
|
|||
|
|
@ -246,6 +246,7 @@ cost_breakdown_t
|
|||
commodity_pool_t::exchange(const amount_t& amount,
|
||||
const amount_t& cost,
|
||||
const bool is_per_unit,
|
||||
const bool add_price,
|
||||
const optional<datetime_t>& moment,
|
||||
const optional<string>& tag)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ public:
|
|||
cost_breakdown_t exchange(const amount_t& amount,
|
||||
const amount_t& cost,
|
||||
const bool is_per_unit = false,
|
||||
const bool add_price = true,
|
||||
const optional<datetime_t>& moment = none,
|
||||
const optional<string>& tag = none);
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ public:
|
|||
#define POST_COST_CALCULATED 0x0080 // posting's cost was calculated
|
||||
#define POST_COST_IN_FULL 0x0100 // cost specified using @@
|
||||
#define POST_COST_FIXATED 0x0200 // cost is fixed using = indicator
|
||||
#define POST_ANONYMIZED 0x0400 // a temporary, anonymous posting
|
||||
#define POST_COST_VIRTUAL 0x0400 // cost is virtualized: (@)
|
||||
#define POST_ANONYMIZED 0x0800 // a temporary, anonymous posting
|
||||
|
||||
xact_t * xact; // only set for posts of regular xacts
|
||||
account_t * account;
|
||||
|
|
|
|||
|
|
@ -96,14 +96,15 @@ namespace {
|
|||
pool.exchange(commodity, per_unit_cost, moment);
|
||||
}
|
||||
|
||||
cost_breakdown_t py_exchange_5(commodity_pool_t& pool,
|
||||
cost_breakdown_t py_exchange_7(commodity_pool_t& pool,
|
||||
const amount_t& amount,
|
||||
const amount_t& cost,
|
||||
const bool is_per_unit,
|
||||
const bool add_prices,
|
||||
const boost::optional<datetime_t>& moment,
|
||||
const boost::optional<string>& tag)
|
||||
{
|
||||
return pool.exchange(amount, cost, is_per_unit, moment, tag);
|
||||
return pool.exchange(amount, cost, is_per_unit, add_prices, moment, tag);
|
||||
}
|
||||
|
||||
commodity_t * py_pool_getitem(commodity_pool_t& pool, const string& symbol)
|
||||
|
|
@ -280,7 +281,7 @@ void export_commodity()
|
|||
|
||||
.def("exchange", py_exchange_2, with_custodian_and_ward<1, 2>())
|
||||
.def("exchange", py_exchange_3, with_custodian_and_ward<1, 2>())
|
||||
.def("exchange", py_exchange_5)
|
||||
.def("exchange", py_exchange_7)
|
||||
|
||||
.def("parse_price_directive", &commodity_pool_t::parse_price_directive)
|
||||
.def("parse_price_expression", &commodity_pool_t::parse_price_expression,
|
||||
|
|
|
|||
|
|
@ -1447,12 +1447,16 @@ post_t * instance_t::parse_post(char * line,
|
|||
|
||||
// Parse the optional cost (@ PER-UNIT-COST, @@ TOTAL-COST)
|
||||
|
||||
if (*next == '@') {
|
||||
if (*next == '@' || (*next == '(' && *(next + 1) == '@')) {
|
||||
DEBUG("textual.parse", "line " << context.linenum << ": "
|
||||
<< "Found a price indicator");
|
||||
|
||||
bool per_unit = true;
|
||||
if (*next == '(') {
|
||||
post->add_flags(POST_COST_VIRTUAL);
|
||||
++next;
|
||||
}
|
||||
|
||||
bool per_unit = true;
|
||||
if (*++next == '@') {
|
||||
per_unit = false;
|
||||
post->add_flags(POST_COST_IN_FULL);
|
||||
|
|
@ -1460,6 +1464,9 @@ post_t * instance_t::parse_post(char * line,
|
|||
<< "And it's for a total price");
|
||||
}
|
||||
|
||||
if (post->has_flags(POST_COST_VIRTUAL) && *(next + 1) == ')')
|
||||
++next;
|
||||
|
||||
beg = static_cast<std::streamsize>(++next - line);
|
||||
|
||||
p = skip_ws(next);
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ bool xact_base_t::finalize()
|
|||
|
||||
cost_breakdown_t breakdown =
|
||||
commodity_pool_t::current_pool->exchange
|
||||
(post->amount, *post->cost, false,
|
||||
(post->amount, *post->cost, false, ! post->has_flags(POST_COST_VIRTUAL),
|
||||
datetime_t(date(), time_duration(0, 0, 0, 0)));
|
||||
|
||||
if (post->amount.has_annotation() && post->amount.annotation().price) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue