diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 59be64b1..79545470 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/input/golden/generic/test_data3_generic_2019-12-01_2020-04-01_lofo_rp2_full_report.ods b/input/golden/generic/test_data3_generic_2019-12-01_2020-04-01_lofo_rp2_full_report.ods index 6b7fe6a2..39fe968f 100644 Binary files a/input/golden/generic/test_data3_generic_2019-12-01_2020-04-01_lofo_rp2_full_report.ods and b/input/golden/generic/test_data3_generic_2019-12-01_2020-04-01_lofo_rp2_full_report.ods differ diff --git a/input/golden/generic/test_data3_generic_lofo_rp2_full_report.ods b/input/golden/generic/test_data3_generic_lofo_rp2_full_report.ods index 76cde1cd..f976f28e 100644 Binary files a/input/golden/generic/test_data3_generic_lofo_rp2_full_report.ods and b/input/golden/generic/test_data3_generic_lofo_rp2_full_report.ods differ diff --git a/input/golden/generic/test_hifo_generic_hifo_rp2_full_report.ods b/input/golden/generic/test_hifo_generic_hifo_rp2_full_report.ods index cf861e33..cdb8507e 100644 Binary files a/input/golden/generic/test_hifo_generic_hifo_rp2_full_report.ods and b/input/golden/generic/test_hifo_generic_hifo_rp2_full_report.ods differ diff --git a/input/golden/generic/test_hifo_generic_lofo_rp2_full_report.ods b/input/golden/generic/test_hifo_generic_lofo_rp2_full_report.ods index 95fee7a0..b6c27062 100644 Binary files a/input/golden/generic/test_hifo_generic_lofo_rp2_full_report.ods and b/input/golden/generic/test_hifo_generic_lofo_rp2_full_report.ods differ diff --git a/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_rp2_full_report.ods b/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_rp2_full_report.ods index 75fa852f..dc3f904d 100644 Binary files a/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_rp2_full_report.ods and b/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_rp2_full_report.ods differ diff --git a/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_tax_report_us.ods b/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_tax_report_us.ods index b2019d19..9222a230 100644 Binary files a/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_tax_report_us.ods and b/input/golden/us/test_data3_2019-12-01_2020-04-01_lofo_tax_report_us.ods differ diff --git a/input/golden/us/test_data3_lofo_rp2_full_report.ods b/input/golden/us/test_data3_lofo_rp2_full_report.ods index 2fef0597..ea385845 100644 Binary files a/input/golden/us/test_data3_lofo_rp2_full_report.ods and b/input/golden/us/test_data3_lofo_rp2_full_report.ods differ diff --git a/input/golden/us/test_data3_lofo_tax_report_us.ods b/input/golden/us/test_data3_lofo_tax_report_us.ods index 5ce76645..b57ad945 100644 Binary files a/input/golden/us/test_data3_lofo_tax_report_us.ods and b/input/golden/us/test_data3_lofo_tax_report_us.ods differ diff --git a/input/golden/us/test_hifo_hifo_rp2_full_report.ods b/input/golden/us/test_hifo_hifo_rp2_full_report.ods index dc682310..7abcd3e9 100644 Binary files a/input/golden/us/test_hifo_hifo_rp2_full_report.ods and b/input/golden/us/test_hifo_hifo_rp2_full_report.ods differ diff --git a/input/golden/us/test_hifo_hifo_tax_report_us.ods b/input/golden/us/test_hifo_hifo_tax_report_us.ods index 84de2df0..7f621973 100644 Binary files a/input/golden/us/test_hifo_hifo_tax_report_us.ods and b/input/golden/us/test_hifo_hifo_tax_report_us.ods differ diff --git a/input/golden/us/test_hifo_lofo_rp2_full_report.ods b/input/golden/us/test_hifo_lofo_rp2_full_report.ods index f3769b6f..9a8738ec 100644 Binary files a/input/golden/us/test_hifo_lofo_rp2_full_report.ods and b/input/golden/us/test_hifo_lofo_rp2_full_report.ods differ diff --git a/input/golden/us/test_hifo_lofo_tax_report_us.ods b/input/golden/us/test_hifo_lofo_tax_report_us.ods index 3dc17600..9a93a05e 100644 Binary files a/input/golden/us/test_hifo_lofo_tax_report_us.ods and b/input/golden/us/test_hifo_lofo_tax_report_us.ods differ diff --git a/src/rp2/accounting_engine.py b/src/rp2/accounting_engine.py index 227e425a..5fee8a40 100644 --- a/src/rp2/accounting_engine.py +++ b/src/rp2/accounting_engine.py @@ -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 ) diff --git a/src/rp2/plugin/accounting_method/hifo.py b/src/rp2/plugin/accounting_method/hifo.py index bd473221..8b96d185 100644 --- a/src/rp2/plugin/accounting_method/hifo.py +++ b/src/rp2/plugin/accounting_method/hifo.py @@ -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) diff --git a/src/rp2/plugin/accounting_method/lofo.py b/src/rp2/plugin/accounting_method/lofo.py index 0d824cae..2a9977a8 100644 --- a/src/rp2/plugin/accounting_method/lofo.py +++ b/src/rp2/plugin/accounting_method/lofo.py @@ -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) diff --git a/src/rp2/tax_engine.py b/src/rp2/tax_engine.py index 4db7bd02..2c379f8b 100644 --- a/src/rp2/tax_engine.py +++ b/src/rp2/tax_engine.py @@ -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) @@ -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 ) @@ -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 @@ -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: @@ -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 @@ -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 )