fix: bugs-04

This commit is contained in:
2026-03-17 22:39:05 +08:00
parent 143a1b4507
commit cdc2c4ead6
50 changed files with 1694 additions and 1916 deletions

View File

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