feat(t224): add incremental freight sync

This commit is contained in:
QiuSW
2026-07-29 00:26:05 +08:00
parent 433db45100
commit c69879650e
35 changed files with 2085 additions and 156 deletions
+57
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
import base64
import json
from datetime import date
from urllib.parse import urlparse
import pytest
@@ -153,6 +154,62 @@ def test_query_and_detail_reproduce_har_contract() -> None:
assert session.calls[2]["json"] == {"ids": [99001122]}
def test_created_range_query_reproduces_har_contract_and_deduplicates() -> None:
stock = {"id": 99001122, "code": "FREIGHT-001"}
detail = {"id": 99001122, "details": []}
session = FakeSession(
[
FakeResponse(envelope(2)),
FakeResponse(envelope({"total": 2, "list": [stock, stock]})),
FakeResponse(envelope({"total": 1, "list": [detail]})),
]
)
client = ERPClient(session=session)
result = client.get_freight_details_by_created_range(
date(2026, 7, 22),
date(2026, 7, 28),
)
assert result["count"] == 1
assert result["query"] == {
"mode": "CREATED_RANGE",
"createdFrom": "2026-07-22",
"createdTo": "2026-07-28",
}
assert session.calls[0]["json"]["queries"] == [
{
"dvalue": "2026-07-22,2026-07-28",
"tableName": "t_stock",
"colName": "created",
"op": 0,
"type": 3,
"tableAlias": "t",
"optType": 0,
}
]
def test_created_range_rejects_more_than_seven_inclusive_days() -> None:
client = ERPClient(session=FakeSession([]))
with pytest.raises(ValueError, match="7 天"):
client.query_stock_by_created_range("2026-07-21", "2026-07-28")
def test_empty_created_range_does_not_request_details() -> None:
session = FakeSession([FakeResponse(envelope(0))])
client = ERPClient(session=session)
result = client.get_freight_details_by_created_range(
"2026-07-28",
"2026-07-28",
)
assert result["records"] == []
assert len(session.calls) == 1
def test_not_found_stops_before_detail_request() -> None:
session = FakeSession([FakeResponse(envelope(0))])
client = ERPClient(session=session)