Allow amounts with total price in the input to "hledger convert"
This commit is contained in:
parent
b4eca62334
commit
2c771f3d7f
@ -578,6 +578,15 @@ Notes:
|
|||||||
matched text with `\0` and any regex groups with `\1`, `\2` in the
|
matched text with `\0` and any regex groups with `\1`, `\2` in the
|
||||||
usual way.
|
usual way.
|
||||||
|
|
||||||
|
- Amount may contain the total or per-unit price. For example, lets
|
||||||
|
assume that your base account "bank-current" is in GBP, and your CSV specifies amount of "10
|
||||||
|
USD @@ 15 GBP", and account-assigning rules selected account
|
||||||
|
"travel-expenses" for this transaction. As a result,
|
||||||
|
"travel-expenses" would be credited by "10 USD @@ 15 GBP", and
|
||||||
|
"bank-current" would be debited by "-15 GBP". This way you could
|
||||||
|
track the expenses in the currencies there were made, while
|
||||||
|
keeping your base account in single currency
|
||||||
|
|
||||||
### histogram
|
### histogram
|
||||||
|
|
||||||
The histogram command displays a quick bar chart showing transaction
|
The histogram command displays a quick bar chart showing transaction
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import Hledger.Data.Types (Journal,AccountName,Transaction(..),Posting(..),Posti
|
|||||||
import Hledger.Data.Utils (strip, spacenonewline, restofline, parseWithCtx, assertParse, assertParseEqual, error')
|
import Hledger.Data.Utils (strip, spacenonewline, restofline, parseWithCtx, assertParse, assertParseEqual, error')
|
||||||
import Hledger.Read.JournalReader (someamount,ledgeraccountname)
|
import Hledger.Read.JournalReader (someamount,ledgeraccountname)
|
||||||
import Hledger.Data.Journal (nullctx)
|
import Hledger.Data.Journal (nullctx)
|
||||||
import Hledger.Data.Amount (nullmixedamt)
|
import Hledger.Data.Amount (nullmixedamt, costOfMixedAmount)
|
||||||
import Safe (atDef, maximumDef)
|
import Safe (atDef, maximumDef)
|
||||||
import System.IO (stderr)
|
import System.IO (stderr)
|
||||||
import Text.CSV (parseCSVFromFile, printCSV)
|
import Text.CSV (parseCSVFromFile, printCSV)
|
||||||
@ -284,6 +284,9 @@ transactionFromCsvRecord rules fields =
|
|||||||
amountstr'' = currency ++ amountstr'
|
amountstr'' = currency ++ amountstr'
|
||||||
amountparse = runParser someamount nullctx "" amountstr''
|
amountparse = runParser someamount nullctx "" amountstr''
|
||||||
amount = either (const nullmixedamt) id amountparse
|
amount = either (const nullmixedamt) id amountparse
|
||||||
|
-- Using costOfMixedAmount here to allow complex costs like "10 GBP @@ 15 USD".
|
||||||
|
-- Aim is to have "10 GBP @@ 15 USD" applied to account "acct", but have "-15USD" applied to "baseacct"
|
||||||
|
baseamount = costOfMixedAmount amount
|
||||||
unknownacct | (readDef 0 amountstr' :: Double) < 0 = "income:unknown"
|
unknownacct | (readDef 0 amountstr' :: Double) < 0 = "income:unknown"
|
||||||
| otherwise = "expenses:unknown"
|
| otherwise = "expenses:unknown"
|
||||||
(acct,newdesc) = identify (accountRules rules) unknownacct desc
|
(acct,newdesc) = identify (accountRules rules) unknownacct desc
|
||||||
@ -309,7 +312,7 @@ transactionFromCsvRecord rules fields =
|
|||||||
Posting {
|
Posting {
|
||||||
pstatus=False,
|
pstatus=False,
|
||||||
paccount=baseAccount rules,
|
paccount=baseAccount rules,
|
||||||
pamount=(-amount),
|
pamount=(-baseamount),
|
||||||
pcomment="",
|
pcomment="",
|
||||||
ptype=RegularPosting,
|
ptype=RegularPosting,
|
||||||
pmetadata=[],
|
pmetadata=[],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user