diff --git a/dibbler/models/Transaction.py b/dibbler/models/Transaction.py index 05da1f1..845793b 100644 --- a/dibbler/models/Transaction.py +++ b/dibbler/models/Transaction.py @@ -66,6 +66,7 @@ EXPECTED_FIELDS: dict[TransactionType, set[str]] = { TransactionType.BUY_PRODUCT: {"product_count", "product_id"}, TransactionType.JOINT: {"product_count", "product_id"}, TransactionType.JOINT_BUY_PRODUCT: {"joint_transaction_id"}, + TransactionType.THROW_PRODUCT: {"product_count", "product_id"}, TransactionType.TRANSFER: {"amount", "transfer_user_id"}, } diff --git a/dibbler/models/TransactionType.py b/dibbler/models/TransactionType.py index f1ab4c2..d823dbe 100644 --- a/dibbler/models/TransactionType.py +++ b/dibbler/models/TransactionType.py @@ -16,6 +16,7 @@ class TransactionType(StrEnum): BUY_PRODUCT = auto() JOINT = auto() JOINT_BUY_PRODUCT = auto() + THROW_PRODUCT = auto() TRANSFER = auto() diff --git a/dibbler/queries/product_stock.py b/dibbler/queries/product_stock.py index fb7aa4a..44d904d 100644 --- a/dibbler/queries/product_stock.py +++ b/dibbler/queries/product_stock.py @@ -29,28 +29,33 @@ def _product_stock_query( Transaction.type_ == TransactionType.ADD_PRODUCT, Transaction.product_count, ), - ( - Transaction.type_ == TransactionType.BUY_PRODUCT, - -Transaction.product_count, - ), ( Transaction.type_ == TransactionType.ADJUST_STOCK, Transaction.product_count, ), + ( + Transaction.type_ == TransactionType.BUY_PRODUCT, + -Transaction.product_count, + ), ( Transaction.type_ == TransactionType.JOINT, -Transaction.product_count, ), + ( + Transaction.type_ == TransactionType.THROW_PRODUCT, + -Transaction.product_count, + ), else_=0, ) ) ).where( Transaction.type_.in_( [ - TransactionType.BUY_PRODUCT, TransactionType.ADD_PRODUCT, TransactionType.ADJUST_STOCK, + TransactionType.BUY_PRODUCT, TransactionType.JOINT, + TransactionType.THROW_PRODUCT, ] ), Transaction.product_id == product_id, diff --git a/dibbler/queries/search_user.py b/dibbler/queries/search_user.py index 421b794..5cc9c00 100644 --- a/dibbler/queries/search_user.py +++ b/dibbler/queries/search_user.py @@ -7,7 +7,6 @@ from dibbler.models import User def search_user( string: str, sql_session: Session, - ignorethisflag=None, ) -> User | list[User]: string = string.lower() diff --git a/dibbler/queries/transaction_log.py b/dibbler/queries/transaction_log.py index 998c210..af94028 100644 --- a/dibbler/queries/transaction_log.py +++ b/dibbler/queries/transaction_log.py @@ -9,6 +9,8 @@ from dibbler.models import ( ) +# TODO: should this include full joint transactions that involve a user? +# TODO: should this involve throw-away transactions that affects a user? def transaction_log( sql_session: Session, user: User | None = None, diff --git a/dibbler/queries/user_balance.py b/dibbler/queries/user_balance.py index 161502d..d590b47 100644 --- a/dibbler/queries/user_balance.py +++ b/dibbler/queries/user_balance.py @@ -92,6 +92,7 @@ def _user_balance_query( ), Transaction.type_.in_( [ + TransactionType.THROW_PRODUCT, TransactionType.ADJUST_INTEREST, TransactionType.ADJUST_PENALTY, ] @@ -155,10 +156,10 @@ def _user_balance_query( # at the moment of writing, after sound right, but maybe ask someone? # Interest * (cast(recursive_cte.c.interest_rate_percent, Float) / 100) + # TODO: these should be added together, not multiplied, see specification # Penalty * case( ( - # TODO: should this be <= or if the user is considered to have bought it, balance increases + # TODO: + # ( + # trx_subset.c.type_ == TransactionType.THROW_PRODUCT, + # recursive_cte.c.balance + trx_subset.c.amount, + # ), + # Interest adjustment -> balance stays the same # Penalty adjustment -> balance stays the same else_=recursive_cte.c.balance, diff --git a/tests/queries/test_product_stock.py b/tests/queries/test_product_stock.py index db03018..490ddde 100644 --- a/tests/queries/test_product_stock.py +++ b/tests/queries/test_product_stock.py @@ -177,3 +177,7 @@ def test_product_stock_joint_transaction(sql_session: Session) -> None: ) assert product_stock(sql_session, product) == 5 - 3 + + +def test_product_stock_throw_away(sql_session: Session) -> None: + ... diff --git a/tests/queries/test_transaction_log.py b/tests/queries/test_transaction_log.py index 58efad7..73cfc11 100644 --- a/tests/queries/test_transaction_log.py +++ b/tests/queries/test_transaction_log.py @@ -563,6 +563,7 @@ def test_transaction_log_combined_filter_product_transaction_id_transaction_type assert len(result) == 2 +# NOTE: see the corresponding TODO's above the function definition -# NOTE: how should this work? Do we includ the entire JOINT transaction, or only the part relevant to the user? def test_transaction_log_filtered_by_user_joint_transactions(sql_session: Session) -> None: ... +def test_transaction_log_filtered_by_user_throw_away_transactions(sql_session: Session) -> None: ... diff --git a/tests/queries/test_user_balance.py b/tests/queries/test_user_balance.py index 1f88ae8..3a9ec20 100644 --- a/tests/queries/test_user_balance.py +++ b/tests/queries/test_user_balance.py @@ -324,3 +324,6 @@ def test_user_balance_joint_transactions_changing_penalty(sql_session: Session): def test_user_balance_joint_transactions_penalty_interest_combined(sql_session: Session): pass + +def test_user_balance_throw_away_products(sql_session: Session): + pass