fixup! WIP

This commit is contained in:
2025-12-09 15:30:16 +09:00
parent 0504cc1a1e
commit cec91d923c
8 changed files with 8 additions and 12 deletions

View File

@@ -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",

View File

@@ -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)

View File

@@ -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

View File

@@ -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,

View File

@@ -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,

View File

@@ -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()

View File

@@ -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(

View File

@@ -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)