fix: bugs-01
This commit is contained in:
@@ -1,32 +1,18 @@
|
||||
"""Transaction deduplication rules.
|
||||
|
||||
Determines whether two transaction records likely represent the same
|
||||
underlying financial event captured from different screenshots / pages.
|
||||
Only marks records as duplicate when there is strong deterministic evidence.
|
||||
Highly similar records (same amount/time/counterparty) are intentionally kept
|
||||
for manual review to avoid filtering out potential scam brushing transactions.
|
||||
"""
|
||||
from datetime import timedelta
|
||||
|
||||
from app.models.transaction import TransactionRecord
|
||||
|
||||
TIME_WINDOW = timedelta(minutes=5)
|
||||
|
||||
|
||||
def is_duplicate_pair(a: TransactionRecord, b: TransactionRecord) -> bool:
|
||||
# Rule 1: exact order_no match
|
||||
# Rule 1: exact order_no match (strong deterministic signal).
|
||||
if a.order_no and b.order_no and a.order_no == b.order_no:
|
||||
return True
|
||||
|
||||
# Rule 2: same amount + close time + same account tail
|
||||
if (
|
||||
float(a.amount) == float(b.amount)
|
||||
and a.trade_time
|
||||
and b.trade_time
|
||||
and abs(a.trade_time - b.trade_time) <= TIME_WINDOW
|
||||
):
|
||||
if a.self_account_tail_no and b.self_account_tail_no:
|
||||
if a.self_account_tail_no == b.self_account_tail_no:
|
||||
return True
|
||||
# same counterparty and close time is also strong signal
|
||||
if a.counterparty_name and a.counterparty_name == b.counterparty_name:
|
||||
return True
|
||||
|
||||
# Intentionally do NOT deduplicate by amount/time similarity.
|
||||
# Those records should enter the review stage for human confirmation.
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user