Fixed the way item state is parsed and managed

This commit is contained in:
John Wiegley 2009-02-27 02:35:51 -04:00
parent fbb0d25831
commit 06365aac05
5 changed files with 21 additions and 31 deletions

View file

@ -102,17 +102,6 @@ optional<date_t> post_t::effective_date() const
return date;
}
item_t::state_t post_t::state() const
{
if (xact) {
state_t xact_state = xact->state();
if ((_state == UNCLEARED && xact_state != UNCLEARED) ||
(_state == PENDING && xact_state == CLEARED))
return xact_state;
}
return _state;
}
namespace {
value_t get_this(post_t& post) {
return value_t(static_cast<scope_t *>(&post));

View file

@ -118,8 +118,6 @@ public:
virtual date_t date() const;
virtual optional<date_t> effective_date() const;
virtual state_t state() const;
bool must_balance() const {
return ! has_flags(POST_VIRTUAL) || has_flags(POST_MUST_BALANCE);
}

View file

@ -1220,6 +1220,20 @@ xact_t * instance_t::parse_xact(char * line,
}
}
if (xact->_state == item_t::UNCLEARED) {
item_t::state_t result = item_t::CLEARED;
foreach (post_t * post, xact->posts) {
if (post->_state == item_t::UNCLEARED) {
result = item_t::UNCLEARED;
break;
}
else if (post->_state == item_t::PENDING) {
result = item_t::PENDING;
}
}
}
xact->end_pos = curr_pos;
xact->end_line = linenum;

View file

@ -54,19 +54,6 @@ xact_base_t::~xact_base_t()
}
}
item_t::state_t xact_base_t::state() const
{
state_t result = CLEARED;
foreach (post_t * post, posts) {
if (post->_state == UNCLEARED)
return UNCLEARED;
else if (post->_state == PENDING)
result = PENDING;
}
return result;
}
void xact_base_t::add_post(post_t * post)
{
posts.push_back(post);
@ -160,8 +147,10 @@ bool xact_base_t::finalize()
null_post->amount = pair.second.negated();
first = false;
} else {
add_post(new post_t(null_post->account, pair.second.negated(),
ITEM_GENERATED));
post_t * p = new post_t(null_post->account, pair.second.negated(),
ITEM_GENERATED);
p->set_state(null_post->state());
add_post(p);
}
}
}
@ -292,7 +281,9 @@ bool xact_base_t::finalize()
else
account = journal->find_account(_("Equity:Capital Losses"));
add_post(new post_t(account, gain_loss.rounded(), ITEM_GENERATED));
post_t * p = new post_t(account, gain_loss.rounded(), ITEM_GENERATED);
p->set_state(post->state());
add_post(p);
DEBUG("xact.finalize", "added gain_loss, balance = " << balance);
}
} else {

View file

@ -72,8 +72,6 @@ public:
virtual ~xact_base_t();
virtual state_t state() const;
virtual void add_post(post_t * post);
virtual bool remove_post(post_t * post);