journal: txn modifier multipliers multiply total-priced amounts (#928)
A different approach: instead of converting to unit prices and fiddling with the display precision, just multiply the total prices by the same multiplier (and keep them positive). This seems a little more natural. I'm not sure if one of these will be more robust than the other.
This commit is contained in:
parent
d7919003ae
commit
b00aa32d7b
@ -92,12 +92,14 @@ tmPostingRuleToFunction pr =
|
|||||||
Nothing -> const $ pamount pr
|
Nothing -> const $ pamount pr
|
||||||
Just n -> \p ->
|
Just n -> \p ->
|
||||||
-- Multiply the old posting's amount by the posting rule's multiplier.
|
-- Multiply the old posting's amount by the posting rule's multiplier.
|
||||||
-- Its display precision will be increased if needed to show all digits.
|
|
||||||
let
|
let
|
||||||
pramount = dbg6 "pramount" $ head $ amounts $ pamount pr
|
pramount = dbg6 "pramount" $ head $ amounts $ pamount pr
|
||||||
matchedamount = dbg6 "matchedamount" $ pamount p
|
matchedamount = dbg6 "matchedamount" $ pamount p
|
||||||
unitpricedmatchedamount = dbg6 "unitpricedmatchedamount" $ mixedAmountTotalPriceToUnitPrice matchedamount
|
-- Handle a matched amount with a total price carefully so as to keep the transaction balanced (#928).
|
||||||
Mixed as = dbg6 "scaledmatchedamount" $ n `multiplyMixedAmount` unitpricedmatchedamount
|
-- Approach 1: convert to a unit price and increase the display precision slightly
|
||||||
|
-- Mixed as = dbg6 "multipliedamount" $ n `multiplyMixedAmount` mixedAmountTotalPriceToUnitPrice matchedamount
|
||||||
|
-- Approach 2: multiply the total price (keeping it positive) as well as the quantity
|
||||||
|
Mixed as = dbg6 "multipliedamount" $ n `multiplyMixedAmountAndPrice` matchedamount
|
||||||
in
|
in
|
||||||
case acommodity pramount of
|
case acommodity pramount of
|
||||||
"" -> Mixed as
|
"" -> Mixed as
|
||||||
|
|||||||
@ -35,14 +35,21 @@ $ hledger -f- print --auto
|
|||||||
$ hledger -f- print --auto
|
$ hledger -f- print --auto
|
||||||
2018/01/01
|
2018/01/01
|
||||||
Expenses:Joint:Widgets $100.00 @@ £50
|
Expenses:Joint:Widgets $100.00 @@ £50
|
||||||
Expenses:Joint $-100.00 @ £0.5
|
Expenses:Joint $-100.00 @@ £50
|
||||||
Liabilities:Joint:Bob $50.00 @ £0.5
|
Liabilities:Joint:Bob $50.00 @@ £25
|
||||||
Liabilities:Joint:Bill $50.00 @ £0.5
|
Liabilities:Joint:Bill $50.00 @@ £25
|
||||||
Assets:Joint:Bank £-50.00
|
Assets:Joint:Bank £-50.00
|
||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
# alternate approach: convert to unit prices
|
||||||
|
#2018/01/01
|
||||||
|
# Expenses:Joint:Widgets $100.00 @@ £50
|
||||||
|
# Expenses:Joint $-100.00 @ £0.5
|
||||||
|
# Liabilities:Joint:Bob $50.00 @ £0.5
|
||||||
|
# Liabilities:Joint:Bill $50.00 @ £0.5
|
||||||
|
# Assets:Joint:Bank £-50.00
|
||||||
|
|
||||||
# Generating auto postings from an implicitly-priced amount. Same as above.
|
# Generating auto postings from an implicitly-priced amount. Should work like the above.
|
||||||
<
|
<
|
||||||
= ^Expenses:Joint
|
= ^Expenses:Joint
|
||||||
Expenses:Joint *-1
|
Expenses:Joint *-1
|
||||||
@ -56,9 +63,9 @@ $ hledger -f- print --auto
|
|||||||
$ hledger -f- print --auto
|
$ hledger -f- print --auto
|
||||||
2018/01/01
|
2018/01/01
|
||||||
Expenses:Joint:Widgets $100.00
|
Expenses:Joint:Widgets $100.00
|
||||||
Expenses:Joint $-100.00 @ £0.5
|
Expenses:Joint $-100.00 @@ £50
|
||||||
Liabilities:Joint:Bob $50.00 @ £0.5
|
Liabilities:Joint:Bob $50.00 @@ £25
|
||||||
Liabilities:Joint:Bill $50.00 @ £0.5
|
Liabilities:Joint:Bill $50.00 @@ £25
|
||||||
Assets:Joint:Bank £-50.00
|
Assets:Joint:Bank £-50.00
|
||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user