diff --git a/main.py b/main.py index 41c5e25..6f3ae14 100644 --- a/main.py +++ b/main.py @@ -580,12 +580,22 @@ def main() -> None: t for t in all_ynab_txns if t["account_id"] in set(account_ids_for_ext) ] - # Filter WF to the comparison window, then find only new ones + # Filter WF to the comparison window filtered_wf = _filter_wf_from_date(wf_txns, start_iso) - new_wf = _find_new_transactions(filtered_wf, scoped_ynab) - # Convert the new WF transactions to YNAB-ready dicts - ynab_ready = _convert_wf_to_ynab_transactions(new_wf, target_account_id) + # For import: only exclude WF txns that already match a cleared/reconciled + # YNAB transaction. Posted WF txns matching *uncleared* YNAB entries must + # survive so _classify_for_import can promote them to cleared. + settled_ynab = [ + t for t in scoped_ynab + if t["cleared"] in ("cleared", "reconciled") + ] + import_candidates = _find_new_transactions(filtered_wf, settled_ynab) + + # Convert the candidates to YNAB-ready dicts + ynab_ready = _convert_wf_to_ynab_transactions( + import_candidates, target_account_id, + ) # Classify against existing YNAB transactions classification = _classify_for_import(ynab_ready, scoped_ynab)