This commit is contained in:
@@ -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"},
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class TransactionType(StrEnum):
|
||||
BUY_PRODUCT = auto()
|
||||
JOINT = auto()
|
||||
JOINT_BUY_PRODUCT = auto()
|
||||
THROW_PRODUCT = auto()
|
||||
TRANSFER = auto()
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 <?
|
||||
recursive_cte.c.balance < recursive_cte.c.penalty_threshold,
|
||||
(
|
||||
cast(recursive_cte.c.penalty_multiplier_percent, Float)
|
||||
@@ -188,6 +189,13 @@ def _user_balance_query(
|
||||
),
|
||||
recursive_cte.c.balance - trx_subset.c.amount,
|
||||
),
|
||||
# Throws a product -> 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,
|
||||
|
||||
Reference in New Issue
Block a user