diff --git a/dibbler/models/Transaction.py b/dibbler/models/Transaction.py index 863bd8e..0d6df69 100644 --- a/dibbler/models/Transaction.py +++ b/dibbler/models/Transaction.py @@ -83,8 +83,8 @@ def _transaction_type_field_constraints( or_( column("type") != transaction_type.value, and_( - *[column(field) != None for field in expected_fields], - *[column(field) == None for field in unexpected_fields], + *[column(field).is_not(None) for field in expected_fields], + *[column(field).is_(None) for field in unexpected_fields], ), ), name=f"trx_type_{transaction_type.value}_expected_fields", diff --git a/dibbler/models/User.py b/dibbler/models/User.py index 026c46a..8f7ca93 100644 --- a/dibbler/models/User.py +++ b/dibbler/models/User.py @@ -5,19 +5,14 @@ from typing import TYPE_CHECKING, Self from sqlalchemy import ( Integer, String, - select, ) from sqlalchemy.orm import ( Mapped, - Session, mapped_column, ) from .Base import Base -if TYPE_CHECKING: - from .Transaction import Transaction - class User(Base): id: Mapped[int] = mapped_column(Integer, primary_key=True) diff --git a/dibbler/queries/__init__.py b/dibbler/queries/__init__.py index 613b36b..417bf54 100644 --- a/dibbler/queries/__init__.py +++ b/dibbler/queries/__init__.py @@ -27,6 +27,7 @@ from .current_penalty import current_penalty from .joint_buy_product import joint_buy_product from .product_price import product_price, product_price_log from .product_stock import product_stock + # from .products_owned_by_user import products_owned_by_user from .search_product import search_product from .search_user import search_user diff --git a/dibbler/queries/transaction_log.py b/dibbler/queries/transaction_log.py index bb552a7..998c210 100644 --- a/dibbler/queries/transaction_log.py +++ b/dibbler/queries/transaction_log.py @@ -13,15 +13,12 @@ def transaction_log( sql_session: Session, user: User | None = None, product: Product | None = None, - exclusive_after: bool = False, after_time=None, after_transaction_id: int | None = None, - exclusive_before: bool = False, before_time=None, before_transaction_id: int | None = None, - transaction_type: list[TransactionType] | None = None, negate_transaction_type_filter: bool = False, limit: int | None = None, diff --git a/dibbler/queries/user_balance.py b/dibbler/queries/user_balance.py index f150f66..161502d 100644 --- a/dibbler/queries/user_balance.py +++ b/dibbler/queries/user_balance.py @@ -80,7 +80,6 @@ def _user_balance_query( TransactionType.ADJUST_BALANCE, TransactionType.BUY_PRODUCT, TransactionType.TRANSFER, - # TODO: join this with the JOINT transactions, and determine # how much the current user paid for the product. TransactionType.JOINT_BUY_PRODUCT, diff --git a/dibbler/subcommands/transaction_log.py b/dibbler/subcommands/transaction_log.py index 9629f0e..adc3080 100644 --- a/dibbler/subcommands/transaction_log.py +++ b/dibbler/subcommands/transaction_log.py @@ -2,6 +2,7 @@ from dibbler.db import Session from dibbler.queries import transaction_log from dibbler.lib.render_transaction_log import render_transaction_log + def main() -> None: sql_session = Session() diff --git a/tests/queries/test_product_price.py b/tests/queries/test_product_price.py index 736fbe2..683ec24 100644 --- a/tests/queries/test_product_price.py +++ b/tests/queries/test_product_price.py @@ -386,7 +386,9 @@ def test_product_price_joint_transactions(sql_session: Session) -> None: old_product_price = product_price_ product_price_ = product_price(sql_session, product) - assert product_price_ == old_product_price, "Joint buy transactions should not affect product price" + assert product_price_ == old_product_price, ( + "Joint buy transactions should not affect product price" + ) transactions = [ Transaction.add_product( diff --git a/tests/queries/test_product_stock.py b/tests/queries/test_product_stock.py index e61c784..db03018 100644 --- a/tests/queries/test_product_stock.py +++ b/tests/queries/test_product_stock.py @@ -140,6 +140,7 @@ def test_negative_product_stock(sql_session: Session) -> None: # The stock should be negative because we added and bought the product assert product_stock(sql_session, product) == 1 - 2 - 1 + def test_product_stock_joint_transaction(sql_session: Session) -> None: insert_test_data(sql_session)