fix: bugs-04
This commit is contained in:
@@ -9,11 +9,17 @@ from app.models.assessment import FraudAssessment, ReviewStatus
|
||||
|
||||
|
||||
async def recalculate_case_total(case_id: UUID, db: AsyncSession) -> float:
|
||||
"""Recalculate and persist the total confirmed fraud amount for a case."""
|
||||
"""Recalculate and persist the recognized fraud amount for a case.
|
||||
|
||||
The case-level amount shown in case list/workspace represents the current
|
||||
recognized amount after analysis, so it should include pending/confirmed/
|
||||
needs_info items and only exclude explicitly rejected records.
|
||||
"""
|
||||
result = await db.execute(
|
||||
select(func.coalesce(func.sum(FraudAssessment.assessed_amount), 0))
|
||||
.where(FraudAssessment.case_id == case_id)
|
||||
.where(FraudAssessment.review_status == ReviewStatus.confirmed)
|
||||
.where(FraudAssessment.assessed_amount > 0)
|
||||
.where(FraudAssessment.review_status != ReviewStatus.rejected)
|
||||
)
|
||||
total = float(result.scalar() or 0)
|
||||
case = await db.get(Case, case_id)
|
||||
|
||||
@@ -15,7 +15,7 @@ from app.models.transaction import TransactionRecord
|
||||
from app.models.transaction_cluster import TransactionCluster
|
||||
from app.repositories.transaction_repo import TransactionRepository
|
||||
from app.rules.dedup_rules import is_duplicate_pair
|
||||
from app.rules.transit_rules import is_self_transfer
|
||||
from app.rules.transit_rules import is_self_transfer, is_fee_tolerant_transit_pair
|
||||
|
||||
|
||||
async def run_matching(case_id: UUID, self_accounts: list[str], db: AsyncSession) -> None:
|
||||
@@ -70,6 +70,15 @@ async def run_matching(case_id: UUID, self_accounts: list[str], db: AsyncSession
|
||||
if is_self_transfer(tx, self_accounts):
|
||||
tx.is_transit = True
|
||||
|
||||
# Rule extension: if an in/out pair occurs within 2 minutes and
|
||||
# amount difference is within 2% (e.g. fee), mark both as transit.
|
||||
non_duplicate = [tx for tx in transactions if not tx.is_duplicate]
|
||||
for i, tx_a in enumerate(non_duplicate):
|
||||
for tx_b in non_duplicate[i + 1 :]:
|
||||
if is_fee_tolerant_transit_pair(tx_a, tx_b):
|
||||
tx_a.is_transit = True
|
||||
tx_b.is_transit = True
|
||||
|
||||
await db.flush()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user