(derive_new_entry): If the "entry" command can't figure out which
account to draw from, and if there is a "basket account" (defined with "A" in a textual ledger), use that.
This commit is contained in:
parent
dab2bfabc8
commit
1f433a129f
1 changed files with 17 additions and 9 deletions
26
derive.cc
26
derive.cc
|
|
@ -45,13 +45,18 @@ entry_t * derive_new_entry(journal_t& journal,
|
||||||
added->add_transaction(new transaction_t(**j));
|
added->add_transaction(new transaction_t(**j));
|
||||||
}
|
}
|
||||||
else if ((*i)[0] == '-' || std::isdigit((*i)[0])) {
|
else if ((*i)[0] == '-' || std::isdigit((*i)[0])) {
|
||||||
if (! matching)
|
account_t * draw_acct;
|
||||||
|
if (matching)
|
||||||
|
draw_acct = matching->transactions.front()->account;
|
||||||
|
else if (journal.basket)
|
||||||
|
draw_acct = journal.basket;
|
||||||
|
else
|
||||||
throw error("Could not determine the account to draw from");
|
throw error("Could not determine the account to draw from");
|
||||||
|
|
||||||
transaction_t * m_xact, * xact, * first;
|
transaction_t * m_xact, * xact, * first;
|
||||||
m_xact = matching->transactions.front();
|
m_xact = matching->transactions.front();
|
||||||
|
|
||||||
first = xact = new transaction_t(m_xact->account, amount_t(*i++));
|
first = xact = new transaction_t(draw_acct, amount_t(*i++));
|
||||||
added->add_transaction(xact);
|
added->add_transaction(xact);
|
||||||
|
|
||||||
if (! xact->amount.commodity())
|
if (! xact->amount.commodity())
|
||||||
|
|
@ -59,7 +64,7 @@ entry_t * derive_new_entry(journal_t& journal,
|
||||||
|
|
||||||
m_xact = matching->transactions.back();
|
m_xact = matching->transactions.back();
|
||||||
|
|
||||||
xact = new transaction_t(m_xact->account, - first->amount);
|
xact = new transaction_t(draw_acct, - first->amount);
|
||||||
added->add_transaction(xact);
|
added->add_transaction(xact);
|
||||||
|
|
||||||
if (i != end) {
|
if (i != end) {
|
||||||
|
|
@ -112,13 +117,16 @@ entry_t * derive_new_entry(journal_t& journal,
|
||||||
added->add_transaction(xact);
|
added->add_transaction(xact);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! matching) {
|
account_t * draw_acct;
|
||||||
|
if (matching)
|
||||||
|
draw_acct = matching->transactions.back()->account;
|
||||||
|
else if (journal.basket)
|
||||||
|
draw_acct = journal.basket;
|
||||||
|
else
|
||||||
throw error("Could not determine the account to draw from");
|
throw error("Could not determine the account to draw from");
|
||||||
} else {
|
|
||||||
transaction_t * xact
|
transaction_t * xact = new transaction_t(draw_acct);
|
||||||
= new transaction_t(matching->transactions.back()->account);
|
added->add_transaction(xact);
|
||||||
added->add_transaction(xact);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue