From 2ee8f3c376c83833e61a08c516a7da6e8dfd841d Mon Sep 17 00:00:00 2001 From: Eric Altendorf Date: Thu, 15 Aug 2024 22:27:24 -0700 Subject: [PATCH] test: get LTFO test working --- beancount/parser/booking_full_test.py | 47 ++++++++++++++------------- beancount/parser/booking_method.py | 2 ++ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/beancount/parser/booking_full_test.py b/beancount/parser/booking_full_test.py index 7a9ca75e9..f67e1de0f 100644 --- a/beancount/parser/booking_full_test.py +++ b/beancount/parser/booking_full_test.py @@ -1980,29 +1980,30 @@ def test_reduce__multiple_reductions_hifo(self, _, __): Assets:Account 45 HOOL {114.00 USD, 2016-01-17} """ - # @book_test(Booking.LTFO) - # def test_reduce__multiple_reductions_hifo(self, _, __): - # """ - # 2016-01-01 * #ante - # Assets:Account 50 HOOL {100.00 USD, 2016-01-01} - # Assets:Account 50 HOOL {116.00 USD, 2016-01-01} - # Assets:Account 50 HOOL {114.00 USD, 2016-01-17} - - # 2016-05-02 * #apply - # Assets:Account -40 HOOL {} - # Assets:Account -35 HOOL {} - # Assets:Account -30 HOOL {} - - # 2016-05-02 * #booked - # Assets:Account -40 HOOL {116.00 USD, 2016-01-16} - # Assets:Account -10 HOOL {116.00 USD, 2016-01-16} - # Assets:Account -25 HOOL {115.00 USD, 2016-01-15} - # Assets:Account -25 HOOL {115.00 USD, 2016-01-15} - # Assets:Account -5 HOOL {114.00 USD, 2016-01-17} - - # 2016-01-01 * #ex - # Assets:Account 45 HOOL {114.00 USD, 2016-01-17} - # """ + @book_test(Booking.LTFO) + def test_reduce__multiple_reductions_ltfo(self, _, __): + """ + 2016-01-01 * #ante + ;; Sell LT @ 140 USD = 60 USD * 20% = 12 USD tax ea + Assets:Account 50 HOOL {80.00 USD, 2016-01-01} + ;; Sell LT @ 140 USD = 20 USD * 20% = 4 USD tax ea + Assets:Account 50 HOOL {120.00 USD, 2016-01-01} + ;; Sell ST @ 140 USD = 25 USD * 40% = 10 USD tax ea + Assets:Account 50 HOOL {115.00 USD, 2017-01-01} + + 2017-03-01 * #apply + Assets:Account -40 HOOL {} @ 140.00 USD + Assets:Account -40 HOOL {} @ 140.00 USD + + 2017-03-01 * #booked + Assets:Account -40 HOOL {120.00 USD, 2016-01-01} @ 140.00 USD + Assets:Account -10 HOOL {120.00 USD, 2016-01-01} @ 140.00 USD + Assets:Account -30 HOOL {115.00 USD, 2017-01-01} @ 140.00 USD + + 2016-01-01 * #ex + Assets:Account 50 HOOL {80.00 USD, 2016-01-01} + Assets:Account 20 HOOL {115.00 USD, 2017-01-01} + """ @book_test(Booking.STRICT) def test_reduce__multiple_reductions__competing__with_error(self, _, __): diff --git a/beancount/parser/booking_method.py b/beancount/parser/booking_method.py index 6556e2cb0..7d11f377f 100644 --- a/beancount/parser/booking_method.py +++ b/beancount/parser/booking_method.py @@ -180,6 +180,8 @@ def us_tax_liability(match: Position): lt_threshold = (match.cost.date.replace(year=match.cost.date.year + 1) + timedelta(days=1)) tax_rate = Decimal("0.2") if entry.date >= lt_threshold else Decimal("0.4") + + # print(f"gain={gain_per_unit} rate={tax_rate} tax={gain_per_unit * tax_rate}") return gain_per_unit * tax_rate return _booking_method_xifo(entry, posting, matches,