B-44: 返修——多币种对方汇总、镜像科目筛选、冲销独立生效日、创建来源撤销边界与并发幂等

This commit is contained in:
腾讯WorkBuddy
2026-08-19 13:28:28 +08:00
parent d59576739f
commit f16e8aad34
7 changed files with 528 additions and 91 deletions
+8 -5
View File
@@ -2435,6 +2435,7 @@ class AppHandler(SimpleHTTPRequestHandler):
actor=user,
subject_code=data.get("subject_code"),
target_ledger_event_id=data.get("target_ledger_event_id"),
effective_at=data.get("effective_at"),
)
except manual_records.ManualConflictError as exc:
self._send_json(409, {"status": "error", "message": str(exc)})
@@ -2495,7 +2496,9 @@ class AppHandler(SimpleHTTPRequestHandler):
connection, from_=from_, cutoff=cutoff, currency=currency,
company_id=company_id,
)
buckets: dict[int, dict[str, object]] = {}
# Buckets are keyed by ``(counterparty, currency)``: amounts never mix
# across currencies, so one counterparty with CNY and USD yields two rows.
buckets: dict[tuple[int, str], dict[str, object]] = {}
for event in events:
counterparty = (
event["payee_company_id"]
@@ -2507,8 +2510,9 @@ class AppHandler(SimpleHTTPRequestHandler):
if int(event["payer_company_id"]) == int(company_id)
else event["payer_company_name"]
)
key = (int(counterparty), event["currency"])
bucket = buckets.setdefault(
counterparty,
key,
{
"counterparty_company_id": counterparty,
"counterparty_company_name": name,
@@ -2550,7 +2554,7 @@ class AppHandler(SimpleHTTPRequestHandler):
else row["payer_company_name"]
)
buckets.setdefault(
counterparty,
(int(counterparty), row["currency"]),
{
"counterparty_company_id": counterparty,
"counterparty_company_name": name,
@@ -2560,8 +2564,7 @@ class AppHandler(SimpleHTTPRequestHandler):
},
)
items = []
for counterparty, bucket in sorted(buckets.items()):
cur = bucket["currency"]
for (counterparty, cur), bucket in sorted(buckets.items()):
signed = bucket["signed"]
unresolved = positions.unresolved_for_company(
connection, company_id, cutoff, currency=cur,