From 8f8a94c28e26c0b46a43e89d566c941994645de7 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 13 Apr 2014 23:25:31 -0500 Subject: Add the concept of "deferred postings" This is pretty much exclusively for allowing one to use balance assertions with replicated transactions across multiple files. --- test/baseline/feat-balance_assert_split.test | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/baseline/feat-balance_assert_split.test (limited to 'test/baseline') diff --git a/test/baseline/feat-balance_assert_split.test b/test/baseline/feat-balance_assert_split.test new file mode 100644 index 00000000..7c2450b6 --- /dev/null +++ b/test/baseline/feat-balance_assert_split.test @@ -0,0 +1,55 @@ +;; a.dat + +2012-01-01 Test + Expenses:Unknown $100.00 + Liabilities:MasterCard + +2012-01-02 Test + Expenses:Unknown $100.00 + Liabilities:MasterCard + +2012-01-03 Test + Expenses:Unknown $100.00 + Liabilities:MasterCard + +2012-01-04 Test + ; UUID: foo + Liabilities:MasterCard $150.00 = $-300 + + +2012-01-04 Test + ; UUID: bar + Liabilities:MasterCard $150.00 = $0 + + +;; b.dat + +2012-01-01 Test + Assets:Checking $150.00 + Income + +2012-01-02 Test + Assets:Checking $150.00 + Income + +2012-01-03 Test + Assets:Checking $150.00 + Income + +2012-01-04 Test + ; UUID: foo + Liabilities:MasterCard $150.00 + Assets:Checking $-150.00 = $300.00 + +2012-01-04 Test + ; UUID: bar + Liabilities:MasterCard $150.00 + Assets:Checking $-150.00 = $150.00 + +test balance + $150.00 Assets:Checking + $300.00 Expenses:Unknown + $-450.00 Income +-------------------- + 0 +end test -- cgit v1.2.3 From 0d23e3d4f6ea4e9ec9a70211abb892383b80188e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 14 Apr 2014 11:08:26 -0500 Subject: Apply any outstanding deferred postings at the end of parsing --- src/account.cc | 15 +++++++++++++++ src/account.h | 1 + src/journal.cc | 1 + src/textual.cc | 3 +++ test/baseline/feat-balance_assert_split.test | 5 +++++ 5 files changed, 25 insertions(+) (limited to 'test/baseline') diff --git a/src/account.cc b/src/account.cc index a702cf11..216b15bd 100644 --- a/src/account.cc +++ b/src/account.cc @@ -154,6 +154,21 @@ void account_t::add_deferred_post(const string& uuid, post_t * post) } } +void account_t::apply_deferred_posts() +{ + if (deferred_posts) { + foreach (deferred_posts_map_t::value_type& pair, *deferred_posts) { + foreach (post_t * post, pair.second) + post->account->add_post(post); + } + deferred_posts = none; + } + + // Also apply in child accounts + foreach (const accounts_map::value_type& pair, accounts) + pair.second->apply_deferred_posts(); +} + bool account_t::remove_post(post_t * post) { // It's possible that 'post' wasn't yet in this account, but try to diff --git a/src/account.h b/src/account.h index 3ce93fba..d1377c39 100644 --- a/src/account.h +++ b/src/account.h @@ -139,6 +139,7 @@ public: void add_post(post_t * post); void add_deferred_post(const string& uuid, post_t * post); + void apply_deferred_posts(); bool remove_post(post_t * post); posts_list::iterator posts_begin() { diff --git a/src/journal.cc b/src/journal.cc index 94a535d7..ea74cb66 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -399,6 +399,7 @@ bool journal_t::add_xact(xact_t * xact) if (i != acct->deferred_posts->end()) { foreach (post_t * rpost, (*i).second) acct->add_post(rpost); + acct->deferred_posts->erase(i); } } } diff --git a/src/textual.cc b/src/textual.cc index 6f8f0492..d02e2f79 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -1925,6 +1925,9 @@ std::size_t journal_t::read_textual(parse_context_stack_t& context_stack) } TRACE_STOP(parsing_total, 1); + // Apply any deferred postings at this time + master->apply_deferred_posts(); + // These tracers were started in textual.cc TRACE_FINISH(xact_text, 1); TRACE_FINISH(xact_details, 1); diff --git a/test/baseline/feat-balance_assert_split.test b/test/baseline/feat-balance_assert_split.test index 7c2450b6..1640bf8b 100644 --- a/test/baseline/feat-balance_assert_split.test +++ b/test/baseline/feat-balance_assert_split.test @@ -22,6 +22,11 @@ Liabilities:MasterCard $150.00 = $0 +2012-01-04 Test + ; UUID: baz + Liabilities:MasterCard $150.00 = $0 + + ;; b.dat 2012-01-01 Test -- cgit v1.2.3 From 3435a81b676b850594915c8d07ae3721a4a4cd11 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 14 Apr 2014 11:41:52 -0500 Subject: Correct one of the baseline tests --- test/baseline/feat-balance_assert_split.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/baseline') diff --git a/test/baseline/feat-balance_assert_split.test b/test/baseline/feat-balance_assert_split.test index 1640bf8b..2d9cce9f 100644 --- a/test/baseline/feat-balance_assert_split.test +++ b/test/baseline/feat-balance_assert_split.test @@ -52,9 +52,9 @@ Assets:Checking $-150.00 = $150.00 test balance - $150.00 Assets:Checking $300.00 Expenses:Unknown $-450.00 Income + $150.00 Liabilities:MasterCard -------------------- 0 end test -- cgit v1.2.3