Access to checkin/checkout of timelog entries

This commit is contained in:
John Wiegley 2012-03-13 03:41:00 -05:00
parent cb317f9d39
commit cfe8142b2b
3 changed files with 27 additions and 7 deletions

View file

@ -351,7 +351,14 @@ namespace {
return post.date(); return post.date();
} }
value_t get_datetime(post_t& post) { value_t get_datetime(post_t& post) {
return post.xdata().datetime; return (! post.xdata().datetime.is_not_a_date_time() ?
post.xdata().datetime : datetime_t(post.date()));
}
value_t get_checkin(post_t& post) {
return post.checkin ? *post.checkin : NULL_VALUE;
}
value_t get_checkout(post_t& post) {
return post.checkout ? *post.checkout : NULL_VALUE;
} }
template <value_t (*Func)(post_t&)> template <value_t (*Func)(post_t&)>
@ -444,6 +451,10 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(get_wrapper<&get_is_calculated>); return WRAP_FUNCTOR(get_wrapper<&get_is_calculated>);
else if (name == "commodity") else if (name == "commodity")
return WRAP_FUNCTOR(&get_commodity); return WRAP_FUNCTOR(&get_commodity);
else if (name == "checkin")
return WRAP_FUNCTOR(get_wrapper<&get_checkin>);
else if (name == "checkout")
return WRAP_FUNCTOR(get_wrapper<&get_checkout>);
break; break;
case 'd': case 'd':

View file

@ -68,6 +68,8 @@ public:
optional<expr_t> amount_expr; optional<expr_t> amount_expr;
optional<amount_t> cost; optional<amount_t> cost;
optional<amount_t> assigned_amount; optional<amount_t> assigned_amount;
optional<datetime_t> checkin;
optional<datetime_t> checkout;
post_t(account_t * _account = NULL, post_t(account_t * _account = NULL,
flags_t _flags = ITEM_NORMAL) flags_t _flags = ITEM_NORMAL)

View file

@ -76,6 +76,11 @@ namespace {
(_("Timelog check-out event does not match any current check-ins")); (_("Timelog check-out event does not match any current check-ins"));
} }
if (event.checkin.is_not_a_date_time())
throw parse_error(_("Timelog check-in has no corresponding check-out"));
if (out_event.checkin.is_not_a_date_time())
throw parse_error(_("Timelog check-out has no corresponding check-in"));
if (out_event.checkin < event.checkin) if (out_event.checkin < event.checkin)
throw parse_error throw parse_error
(_("Timelog check-out date less than corresponding check-in")); (_("Timelog check-out date less than corresponding check-in"));
@ -107,6 +112,8 @@ namespace {
post_t * post = new post_t(event.account, amt, POST_VIRTUAL); post_t * post = new post_t(event.account, amt, POST_VIRTUAL);
post->set_state(item_t::CLEARED); post->set_state(item_t::CLEARED);
post->pos = event.position; post->pos = event.position;
post->checkin = event.checkin;
post->checkout = out_event.checkin;
curr->add_post(post); curr->add_post(post);
event.account->add_post(post); event.account->add_post(post);