Skip to content

Commit

Permalink
Initial implementation of least-tax booking
Browse files Browse the repository at this point in the history
  • Loading branch information
ericaltendorf committed Sep 5, 2023
1 parent 7c83141 commit f3b6761
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
3 changes: 3 additions & 0 deletions beancount/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Booking(enum.Enum):
# Highest-in first-out in the case of ambiguity.
HIFO = 'HIFO'

# Least tax first out
LTFO = 'LTFO'

# All possible types of entries. These are the main data structures in use
# within the program. They are all treated as immutable.
#
Expand Down
20 changes: 10 additions & 10 deletions beancount/core/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def cost_to_str(cost, dformat, detail=True):
strlist.append('"{}"'.format(cost.label))

elif isinstance(cost, CostSpec):
if isinstance(cost.number_per, Decimal) or isinstance(cost.number_total, Decimal):
amountlist = []
if isinstance(cost.number_per, Decimal):
amountlist.append(dformat.format(cost.number_per))
if isinstance(cost.number_total, Decimal):
amountlist.append('#')
amountlist.append(dformat.format(cost.number_total))
if isinstance(cost.currency, str):
amountlist.append(cost.currency)
strlist.append(' '.join(amountlist))
# if isinstance(cost.number_per, Decimal) or isinstance(cost.number_total, Decimal):
amountlist = []
if isinstance(cost.number_per, Decimal):
amountlist.append(dformat.format(cost.number_per))
if isinstance(cost.number_total, Decimal):
amountlist.append('#')
amountlist.append(dformat.format(cost.number_total))
if isinstance(cost.currency, str):
amountlist.append(cost.currency)
strlist.append(' '.join(amountlist))
if detail:
if cost.date:
strlist.append(cost.date.isoformat())
Expand Down
24 changes: 24 additions & 0 deletions beancount/parser/booking_full_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,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.STRICT)
def test_reduce__multiple_reductions__competing__with_error(self, _, __):
"""
Expand Down
1 change: 1 addition & 0 deletions beancount/parser/booking_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def booking_method_AVERAGE(entry, posting, matches):
Booking.FIFO : booking_method_FIFO,
Booking.LIFO : booking_method_LIFO,
Booking.HIFO : booking_method_HIFO,
Booking.LTFO : booking_method_LTFO,
Booking.NONE : booking_method_NONE,
Booking.AVERAGE : booking_method_AVERAGE,
}

0 comments on commit f3b6761

Please sign in to comment.