Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repos:
- id: isort
args: [--line-length 160]
- repo: https://github.com/psf/black
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
Expand Down
Binary file not shown.
Binary file modified input/golden/generic/test_data3_generic_lofo_rp2_full_report.ods
Binary file not shown.
Binary file modified input/golden/generic/test_hifo_generic_hifo_rp2_full_report.ods
Binary file not shown.
Binary file modified input/golden/generic/test_hifo_generic_lofo_rp2_full_report.ods
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified input/golden/us/test_data3_lofo_rp2_full_report.ods
Binary file not shown.
Binary file modified input/golden/us/test_data3_lofo_tax_report_us.ods
Binary file not shown.
Binary file modified input/golden/us/test_hifo_hifo_rp2_full_report.ods
Binary file not shown.
Binary file modified input/golden/us/test_hifo_hifo_tax_report_us.ods
Binary file not shown.
Binary file modified input/golden/us/test_hifo_lofo_rp2_full_report.ods
Binary file not shown.
Binary file modified input/golden/us/test_hifo_lofo_tax_report_us.ods
Binary file not shown.
2 changes: 1 addition & 1 deletion src/rp2/accounting_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_next_taxable_event_and_amount(
if taxable_event and taxable_event.timestamp < new_taxable_event.timestamp:
if acquired_lot:
self._set_partial_amount(acquired_lot, new_acquired_lot_amount)
(_, new_acquired_lot, _, new_acquired_lot_amount) = self.get_acquired_lot_for_taxable_event(
_, new_acquired_lot, _, new_acquired_lot_amount = self.get_acquired_lot_for_taxable_event(
new_taxable_event, acquired_lot, new_taxable_event_amount, new_acquired_lot_amount
)

Expand Down
3 changes: 2 additions & 1 deletion src/rp2/plugin/accounting_method/hifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
# HIFO (Highest In, First Out) plugin. See https://www.investopedia.com/terms/h/hifo.asp.
class AccountingMethod(AbstractFeatureBasedAccountingMethod):
def sort_key(self, lot: InTransaction) -> AcquiredLotSortKey:
return AcquiredLotSortKey(-lot.spot_price, lot.timestamp.timestamp(), lot.row)
adjusted_basis = lot.fiat_in_with_fee / lot.crypto_in
return AcquiredLotSortKey(-adjusted_basis, lot.timestamp.timestamp(), lot.row)
3 changes: 2 additions & 1 deletion src/rp2/plugin/accounting_method/lofo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
# LOFO (Lowest In, First Out) plugin. In this method the lot with lowest cost of purchase is the first to be used.
class AccountingMethod(AbstractFeatureBasedAccountingMethod):
def sort_key(self, lot: InTransaction) -> AcquiredLotSortKey:
return AcquiredLotSortKey(lot.spot_price, lot.timestamp.timestamp(), lot.row)
adjusted_basis = lot.fiat_in_with_fee / lot.crypto_in
return AcquiredLotSortKey(adjusted_basis, lot.timestamp.timestamp(), lot.row)
14 changes: 7 additions & 7 deletions src/rp2/tax_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def _get_next_taxable_event_and_acquired_lot(
new_acquired_lot: Optional[InTransaction]
new_taxable_event_amount: RP2Decimal
new_acquired_lot_amount: RP2Decimal
(new_taxable_event, new_acquired_lot, new_taxable_event_amount, new_acquired_lot_amount) = accounting_engine.get_next_taxable_event_and_amount(
new_taxable_event, new_acquired_lot, new_taxable_event_amount, new_acquired_lot_amount = accounting_engine.get_next_taxable_event_and_amount(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount
)
if acquired_lot == new_acquired_lot:
(_, new_acquired_lot, _, new_acquired_lot_amount) = accounting_engine.get_acquired_lot_for_taxable_event(
_, new_acquired_lot, _, new_acquired_lot_amount = accounting_engine.get_acquired_lot_for_taxable_event(
new_taxable_event, new_acquired_lot, new_taxable_event_amount, new_acquired_lot_amount
)
return TaxableEventAndAcquiredLot(new_taxable_event, new_acquired_lot, new_taxable_event_amount, new_acquired_lot_amount)
Expand All @@ -113,7 +113,7 @@ def _create_unfiltered_gain_and_loss_set(
total_amount: RP2Decimal = ZERO

# Retrieve first taxable event and acquired lot
(taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount) = _get_next_taxable_event_and_acquired_lot(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount = _get_next_taxable_event_and_acquired_lot(
new_accounting_engine, None, None, ZERO, ZERO
)

Expand All @@ -140,7 +140,7 @@ def _create_unfiltered_gain_and_loss_set(
)
total_amount += taxable_event_amount
gain_loss_set.add_entry(gain_loss)
(taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount) = new_accounting_engine.get_next_taxable_event_and_amount(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount = new_accounting_engine.get_next_taxable_event_and_amount(
taxable_event, acquired_lot, ZERO, acquired_lot_amount
)
continue
Expand All @@ -157,7 +157,7 @@ def _create_unfiltered_gain_and_loss_set(
)
total_amount += taxable_event_amount
gain_loss_set.add_entry(gain_loss)
(taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount) = _get_next_taxable_event_and_acquired_lot(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount = _get_next_taxable_event_and_acquired_lot(
new_accounting_engine, taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount
)
elif taxable_event_amount < acquired_lot_amount:
Expand All @@ -173,7 +173,7 @@ def _create_unfiltered_gain_and_loss_set(
)
total_amount += taxable_event_amount
gain_loss_set.add_entry(gain_loss)
(taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount) = new_accounting_engine.get_next_taxable_event_and_amount(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount = new_accounting_engine.get_next_taxable_event_and_amount(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount
)
else: # taxable_amount > acquired_lot_amount
Expand All @@ -189,7 +189,7 @@ def _create_unfiltered_gain_and_loss_set(
)
total_amount += acquired_lot_amount
gain_loss_set.add_entry(gain_loss)
(taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount) = new_accounting_engine.get_acquired_lot_for_taxable_event(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount = new_accounting_engine.get_acquired_lot_for_taxable_event(
taxable_event, acquired_lot, taxable_event_amount, acquired_lot_amount
)

Expand Down
Loading