fix(sync): dashboard sync covers current year plus Nov-Dec of previous
/sync-bank now uses one shared default window in both implementations: 1 November of the previous year to 31 December of the current year. Payments dated around New Year are picked up in January; duplicates are still filtered by Sync ID. Python used a hardcoded 2026 window and would have stopped syncing on 2027-01-01; Go used the current calendar year only. Adds make sync-year [YEAR=N] with the same window. The CLI default without flags (last 30 days) is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,18 @@ type SyncOpts struct {
|
||||
PrintFioTable bool // with DryRun: print every fetched Fio txn with NEW/DUP status
|
||||
}
|
||||
|
||||
// DefaultWindow is the window used by the dashboard sync: the whole current
|
||||
// calendar year plus the last two months of the previous one, so payments
|
||||
// dated around New Year are still picked up in January. Re-fetching is safe
|
||||
// because rows are deduplicated by Sync ID.
|
||||
// Mirrors default_sync_window in legacy/scripts/sync_fio_to_sheets.py.
|
||||
func DefaultWindow(now time.Time) (from, to time.Time) {
|
||||
yr := now.Year()
|
||||
from = time.Date(yr-1, time.November, 1, 0, 0, 0, 0, time.UTC)
|
||||
to = time.Date(yr, time.December, 31, 23, 59, 59, 0, time.UTC)
|
||||
return from, to
|
||||
}
|
||||
|
||||
// SyncToSheets fetches Fio transactions from all provided clients and appends
|
||||
// new ones to the payments sheet. Returns the number of rows appended.
|
||||
// Ports legacy/scripts/sync_fio_to_sheets.py sync_to_sheets.
|
||||
|
||||
@@ -193,3 +193,23 @@ func syncIDFor(tx fio.Transaction) string {
|
||||
Sender: tx.Sender, VS: tx.VS, Message: tx.Message, BankID: tx.BankID,
|
||||
})
|
||||
}
|
||||
|
||||
func TestDefaultWindow(t *testing.T) {
|
||||
cases := []struct {
|
||||
now time.Time
|
||||
from, to string
|
||||
}{
|
||||
{time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC), "2025-11-01", "2026-12-31"},
|
||||
{time.Date(2027, 1, 1, 0, 0, 0, 0, time.UTC), "2026-11-01", "2027-12-31"},
|
||||
{time.Date(2027, 12, 31, 23, 0, 0, 0, time.UTC), "2026-11-01", "2027-12-31"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
from, to := DefaultWindow(tc.now)
|
||||
if got := from.Format("2006-01-02"); got != tc.from {
|
||||
t.Errorf("DefaultWindow(%s) from: want %s, got %s", tc.now.Format("2006-01-02"), tc.from, got)
|
||||
}
|
||||
if got := to.Format("2006-01-02"); got != tc.to {
|
||||
t.Errorf("DefaultWindow(%s) to: want %s, got %s", tc.now.Format("2006-01-02"), tc.to, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user