diff --git a/server.py b/server.py index 91140fb..6496c14 100644 --- a/server.py +++ b/server.py @@ -30,7 +30,7 @@ STORAGE_DIR = Path(os.environ.get("APP_STORAGE_DIR", ROOT / "data" / "files")) SESSION_COOKIE = "cw_fusion_session" if portal_sso.enabled() else "cw_session" # Local plain-HTTP deployment: the cookie intentionally carries no Secure # flag (see docs/decisions/003-auth.md). -COOKIE_FLAGS = "HttpOnly; SameSite=Lax; Path=/" +COOKIE_FLAGS = "HttpOnly; SameSite=Lax; Path=/" + ("; Secure" if os.environ.get("PORTAL_COOKIE_SECURE") == "1" else "") class AppHandler(portal_sso.PortalMixin, SimpleHTTPRequestHandler): diff --git a/tests/ledger_helpers.py b/tests/ledger_helpers.py index 475f29f..6d72d0c 100644 --- a/tests/ledger_helpers.py +++ b/tests/ledger_helpers.py @@ -3,6 +3,7 @@ from __future__ import annotations from pathlib import Path +import hashlib import sqlite3 import tempfile import unittest @@ -13,6 +14,7 @@ from bank_importer.db import connect, migrate, utc_now class LedgerBase(unittest.TestCase): def setUp(self) -> None: + self._source_file_sequence = 0 self.temp_dir = tempfile.TemporaryDirectory() self.addCleanup(self.temp_dir.cleanup) root = Path(self.temp_dir.name) @@ -66,13 +68,15 @@ class LedgerBase(unittest.TestCase): summary: str | None = None, purpose: str | None = None, ) -> int: + self._source_file_sequence = getattr(self, "_source_file_sequence", 0) + 1 + fixture_hash = hashlib.sha256(f"ledger-fixture-{self._source_file_sequence}".encode()).hexdigest() with self.connection: cursor = self.connection.execute( """ INSERT INTO source_files (sha256, original_filename, size_bytes, storage_path, created_at) VALUES (?, '测试.xlsx', 1, 'data/files/测试.xlsx', ?) """, - (utc_now(), utc_now()), + (fixture_hash, utc_now()), ) source_file_id = int(cursor.lastrowid) cursor = self.connection.execute( diff --git a/tests/test_matching.py b/tests/test_matching.py index 964c9b5..6779155 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -5,6 +5,7 @@ idempotency, concurrency, Decimal precision and B-44 eligibility.""" from __future__ import annotations from decimal import Decimal +import hashlib from pathlib import Path import sqlite3 import tempfile @@ -17,6 +18,7 @@ from bank_importer.db import connect, migrate, utc_now class MatchingBase(unittest.TestCase): def setUp(self) -> None: + self._source_file_sequence = 0 self.temp_dir = tempfile.TemporaryDirectory() self.addCleanup(self.temp_dir.cleanup) root = Path(self.temp_dir.name) @@ -74,13 +76,15 @@ class MatchingBase(unittest.TestCase): summary: str | None = None, sheet: str = "流水", ) -> int: + self._source_file_sequence = getattr(self, "_source_file_sequence", 0) + 1 + fixture_hash = hashlib.sha256(f"matching-fixture-{self._source_file_sequence}".encode()).hexdigest() with self.connection: cursor = self.connection.execute( """ INSERT INTO source_files (sha256, original_filename, size_bytes, storage_path, created_at) VALUES (?, '测试.xlsx', 1, 'data/files/测试.xlsx', ?) """, - (utc_now(), utc_now()), + (fixture_hash, utc_now()), ) source_file_id = int(cursor.lastrowid) cursor = self.connection.execute( diff --git a/web/admin.html b/web/admin.html index 761cc80..b5350f4 100644 --- a/web/admin.html +++ b/web/admin.html @@ -205,8 +205,8 @@
-
金牛农业 → 应收 386.24 万元
-
14 笔(借 9 / 贷 5)· 最早未结 2026-03-12
+
查看所选公司的实际往来
+
金额、统计截止日及未解决事项以往来查询结果为准
@@ -217,9 +217,9 @@ 账期与结账每月 5 日结账 · 全局起算日 2026-01-01
-
当前账期
2026-07 · 进行中
-
结账日
2026-08-29(顺延)· 距今 9 天
-
上一账期
2026-06 · 已于 07-03 结账
+
待结账期
正在读取
+
结账状态
正在读取
+
最近结账
正在读取
@@ -1257,6 +1257,6 @@ - + diff --git a/web/app.js b/web/app.js index c9de67f..51e05c2 100644 --- a/web/app.js +++ b/web/app.js @@ -2278,6 +2278,11 @@ function applyClosePanel(overview) { state.periodClose = overview; const close = overview.close || {}; const ym = close.year_month || overview.target_month || "—"; + if ($("#dashboardClosePeriod")) $("#dashboardClosePeriod").textContent = ym; + if ($("#dashboardCloseStatus")) $("#dashboardCloseStatus").textContent = + ({ closed: "已结账", closing: "处理中", failed: "结账失败", reopened: "已重开", open: "未结账" })[close.status] || "待结账检查"; + if ($("#dashboardCloseHistory")) $("#dashboardCloseHistory").textContent = overview.history + ? `${overview.history.year_month} · ${String(overview.history.closed_at || "").slice(0, 10)}` : "尚无结账记录"; renderTimeline(overview.timeline); const start = state.calculationStart || "—"; if ($("#timelineSub")) $("#timelineSub").textContent = `全局起算日 ${start} 起,每月 ${overview.closing_day || "—"} 日结账`; @@ -2388,6 +2393,9 @@ async function loadPeriodClose() { if (response?.status === 401) { window.location.href = window.PORTAL_HOME || "index.html"; return; } const result = await response?.json().catch(() => null); if (!response?.ok || result?.status !== "ok") { + for (const id of ['dashboardClosePeriod', 'dashboardCloseStatus', 'dashboardCloseHistory']) { + if ($(`#${id}`)) $(`#${id}`).textContent = '读取失败,请重试'; + } showToast("结账状态加载失败", result?.message || "请稍后重试", "danger"); return; }