Skip to content

Commit

Permalink
Reimplemented artificial id logic (now it's more generic).
Browse files Browse the repository at this point in the history
  • Loading branch information
eprbell committed Dec 1, 2024
1 parent 484c8b8 commit 9162edb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/rp2/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from datetime import date, datetime
from enum import Enum
from pathlib import Path
from threading import Lock
from typing import Any, Dict, List, Set

from dateutil.parser import parse
Expand Down Expand Up @@ -150,6 +151,8 @@ def __init__( # pylint: disable=too-many-branches
self.__holders: Set[str] = set()
self.__generators: Set[str] = {f"{REPORT_GENERATOR_PACKAGE}.{generator}" for generator in country.get_report_generators()}
self.__years_2_accounting_method_names: Dict[int, str] = {}
self.__artificial_id_counter: int = 0
self.__lock = Lock()

if not Path(configuration_path).exists():
raise RP2ValueError(f"Error: {configuration_path} does not exist")
Expand Down Expand Up @@ -479,3 +482,10 @@ def type_check_decimal(cls, name: str, value: RP2Decimal) -> RP2Decimal:
if not isinstance(value, RP2Decimal):
raise RP2TypeError(f"Parameter '{name}' has non-RP2Decimal value {repr(value)}")
return value

def update_artificial_id_counter(self) -> int:
result: int
with self.__lock:
self.__artificial_id_counter -= 1
result = self.__artificial_id_counter
return result
6 changes: 3 additions & 3 deletions src/rp2/ods_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _create_and_process_transaction(
spot_price=transaction.spot_price,
crypto_out_no_fee=ZERO,
crypto_fee=transaction.crypto_fee,
row=get_artificial_id_from_row(internal_id),
row=get_artificial_id(configuration),
unique_id=transaction.unique_id,
notes=(
f"Artificial transaction modeling the crypto fee of {transaction.crypto_fee} {transaction.asset} "
Expand All @@ -215,8 +215,8 @@ def _create_and_process_transaction(
else:
unfiltered_transaction_sets[current_table_type].add_entry(transaction)

def get_artificial_id_from_row(row: int) -> int:
return -row
def get_artificial_id(configuration: Configuration) -> int:
return configuration.update_artificial_id_counter()

# Returns all numeric parameters of the constructor: used in construction of __init__ argument pack to parse such parameters as decimals
@lru_cache(maxsize=None, typed=False)
Expand Down

0 comments on commit 9162edb

Please sign in to comment.