Skip to content

Commit

Permalink
test: get LTFO test working
Browse files Browse the repository at this point in the history
  • Loading branch information
ericaltendorf committed Aug 16, 2024
1 parent 10da0f5 commit 2ee8f3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
47 changes: 24 additions & 23 deletions beancount/parser/booking_full_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _, __):
Expand Down
2 changes: 2 additions & 0 deletions beancount/parser/booking_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2ee8f3c

Please sign in to comment.