Skip to content

Commit

Permalink
Renamed heap_key to sort_key
Browse files Browse the repository at this point in the history
  • Loading branch information
eprbell committed Jul 18, 2024
1 parent 028c29c commit 99f3eae
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ from rp2.in_transaction import InTransaction
```
class AccountingMethod(AbstractFeatureBasedAccountingMethod):
```
* Add a `heap_key()` method to the class with the following signature:
* Add a `sort_key()` method to the class with the following signature:
```
def heap_key(self, lot: InTransaction) -> AcquiredLotSortKey:
def sort_key(self, lot: InTransaction) -> AcquiredLotSortKey:
```
* write the body of the method: it should return the heap key, reflecting the desired sort criteria for acquired lots.
* write the body of the method: it should return the sort key, reflecting the desired sort criteria for acquired lots. Note that you may have to add new fields to `AcquiredLotSortKey` to reflect the feature you want to sort on: such addition should be backward compatible to ensure it doesn't break existing accounting methods.

**NOTE**: If you're interested in adding support for a new accounting method, open a [PR](CONTRIBUTING.md).

Expand Down
4 changes: 2 additions & 2 deletions src/rp2/abstract_accounting_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def create_lot_candidates(
return FeatureBasedAcquiredLotCandidates(self, acquired_lot_list, acquired_lot_2_partial_amount)

def add_selected_lot_to_heap(self, heap: List[Tuple[AcquiredLotSortKey, InTransaction]], lot: InTransaction) -> None:
heap_item = (self.heap_key(lot), lot)
heap_item = (self.sort_key(lot), lot)
heappush(heap, heap_item)

def heap_key(self, lot: InTransaction) -> AcquiredLotSortKey:
def sort_key(self, lot: InTransaction) -> AcquiredLotSortKey:
raise NotImplementedError("Abstract function")

def _create_accounting_method_iterator(self, lot_candidates: AbstractAcquiredLotCandidates) -> FeatureBasedAccountingMethodIterator:
Expand Down
2 changes: 1 addition & 1 deletion src/rp2/plugin/accounting_method/hifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
# More on this at https://www.forbes.com/sites/shehanchandrasekera/2020/09/17/what-crypto-taxpayers-need-to-know-about-fifo-lifo-hifo-specific-id/
class AccountingMethod(AbstractFeatureBasedAccountingMethod):

def heap_key(self, lot: InTransaction) -> AcquiredLotSortKey:
def sort_key(self, lot: InTransaction) -> AcquiredLotSortKey:
return AcquiredLotSortKey(-lot.spot_price, lot.timestamp.timestamp(), lot.row)
2 changes: 1 addition & 1 deletion src/rp2/plugin/accounting_method/lifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
# https://ttlc.intuit.com/community/investments-and-rental-properties/discussion/using-lifo-method-for-cryptocurrency-or-even-stock-cost-basis/00/1433542
class AccountingMethod(AbstractFeatureBasedAccountingMethod):

def heap_key(self, lot: InTransaction) -> AcquiredLotSortKey:
def sort_key(self, lot: InTransaction) -> AcquiredLotSortKey:
return AcquiredLotSortKey(ZERO, -lot.timestamp.timestamp(), -lot.row)

0 comments on commit 99f3eae

Please sign in to comment.