Remember default account even if user submits a different amount.
The use case here is spending that fits a certain template, but whose amount tends to vary (for example, daily lunch at a cafe).
This commit is contained in:
parent
3ae989e8cb
commit
9f539f0138
@ -40,6 +40,7 @@ import Control.Exception (throw)
|
|||||||
data PostingState = PostingState {
|
data PostingState = PostingState {
|
||||||
psContext :: JournalContext,
|
psContext :: JournalContext,
|
||||||
psAccept :: AccountName -> Bool,
|
psAccept :: AccountName -> Bool,
|
||||||
|
psSuggestHistoricalAmount :: Bool,
|
||||||
psHistory :: Maybe [Posting]}
|
psHistory :: Maybe [Posting]}
|
||||||
|
|
||||||
-- | Read transactions from the terminal, prompting for each field,
|
-- | Read transactions from the terminal, prompting for each field,
|
||||||
@ -89,7 +90,7 @@ getTransaction j opts args defaultDate = do
|
|||||||
else True
|
else True
|
||||||
where (ant,_,_,_) = groupPostings $ journalPostings j
|
where (ant,_,_,_) = groupPostings $ journalPostings j
|
||||||
getpostingsandvalidate = do
|
getpostingsandvalidate = do
|
||||||
ps <- getPostings (PostingState (jContext j) accept bestmatchpostings) []
|
ps <- getPostings (PostingState (jContext j) accept True bestmatchpostings) []
|
||||||
let t = nulltransaction{tdate=date
|
let t = nulltransaction{tdate=date
|
||||||
,tstatus=False
|
,tstatus=False
|
||||||
,tdescription=description
|
,tdescription=description
|
||||||
@ -125,7 +126,7 @@ getPostings st enteredps = do
|
|||||||
| n <= length ps = Just $ ps !! (n-1)
|
| n <= length ps = Just $ ps !! (n-1)
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
where Just ps = historicalps'
|
where Just ps = historicalps'
|
||||||
defaultamountstr | isJust bestmatch' = Just historicalamountstr
|
defaultamountstr | isJust bestmatch' && suggesthistorical = Just historicalamountstr
|
||||||
| n > 1 = Just balancingamountstr
|
| n > 1 = Just balancingamountstr
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
where
|
where
|
||||||
@ -145,7 +146,9 @@ getPostings st enteredps = do
|
|||||||
p = nullposting{paccount=stripbrackets account,
|
p = nullposting{paccount=stripbrackets account,
|
||||||
pamount=amount,
|
pamount=amount,
|
||||||
ptype=postingtype account}
|
ptype=postingtype account}
|
||||||
st' = st{psHistory = if defaultamtused then historicalps' else Nothing}
|
st' = if defaultamtused then st
|
||||||
|
else st{psHistory = historicalps',
|
||||||
|
psSuggestHistoricalAmount = False}
|
||||||
when (isJust commodityadded) $
|
when (isJust commodityadded) $
|
||||||
liftIO $ hPutStrLn stderr $ printf "using default commodity (%s)" (symbol $ fromJust commodityadded)
|
liftIO $ hPutStrLn stderr $ printf "using default commodity (%s)" (symbol $ fromJust commodityadded)
|
||||||
getPostings st' (enteredps ++ [p])
|
getPostings st' (enteredps ++ [p])
|
||||||
@ -153,6 +156,7 @@ getPostings st enteredps = do
|
|||||||
historicalps = psHistory st
|
historicalps = psHistory st
|
||||||
ctx = psContext st
|
ctx = psContext st
|
||||||
accept = psAccept st
|
accept = psAccept st
|
||||||
|
suggesthistorical = psSuggestHistoricalAmount st
|
||||||
n = length enteredps + 1
|
n = length enteredps + 1
|
||||||
enteredrealps = filter isReal enteredps
|
enteredrealps = filter isReal enteredps
|
||||||
showacctname p = showAccountName Nothing (ptype p) $ paccount p
|
showacctname p = showAccountName Nothing (ptype p) $ paccount p
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user