Skip to content

Commit

Permalink
Merge pull request #7 from ericaltendorf/tax-booking
Browse files Browse the repository at this point in the history
feat: transfer aware hifo
  • Loading branch information
ericaltendorf authored Aug 20, 2024
2 parents 1f75018 + 12a6cfd commit 5784fb8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion beancount/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ class Booking(enum.Enum):
HIFO = "HIFO"


# Least tax first out
# Least tax first out, with transfer awareness
LTFO = 'LTFO'

# HIFO with transfer awareness
HIFO_XFER_AWARE = 'HIFO_XFER_AWARE'

# All possible types of entries. These are the main data structures in use
# within the program. They are all treated as immutable.
#
Expand Down
17 changes: 17 additions & 0 deletions beancount/parser/booking_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,22 @@ def booking_method_AVERAGE(entry, posting, matches):
)
_insufficient = abs(posting.units.number) > abs(units.number)

def booking_method_HIFO_XFER_AWARE(entry, posting, matches):
# If there's no price, it's probably a transfer rather than a sale. The
# posting we get is the reduction (donating account).
#
# If the posting is on a wallet account, it's probably a transfer to a
# trading account in preparation for sale, so we would want to pick the
# lot with minimal tax liability.
#
# If the posting is on a trading account, then it's probably a transfer to a
# wallet and we want the inverse -- to stash away the lots least desirable
# to sell.
sale_prep = "Wallet" in posting.account # Total hack
if sale_prep:
return booking_method_HIFO(entry, posting, matches)
else:
return booking_method_LowIFO(entry, posting, matches)

_BOOKING_METHODS = {
Booking.STRICT: booking_method_STRICT,
Expand All @@ -380,6 +396,7 @@ def booking_method_AVERAGE(entry, posting, matches):
Booking.LIFO: booking_method_LIFO,
Booking.HIFO: booking_method_HIFO,
Booking.LTFO: booking_method_LTFO,
Booking.HIFO_XFER_AWARE: booking_method_HIFO_XFER_AWARE,
Booking.NONE: booking_method_NONE,
Booking.AVERAGE: booking_method_AVERAGE,
}

0 comments on commit 5784fb8

Please sign in to comment.