fix: 简化待付款订单核单条件 (#126)
This commit is contained in:
@@ -99,10 +99,13 @@ class FaultAdapter(PddPurchaseAdapter):
|
||||
|
||||
|
||||
class ReadOnlyReconcileAdapter(PddPurchaseReconcileAdapter):
|
||||
def __init__(self, calls, candidates=None, error=None) -> None:
|
||||
def __init__(
|
||||
self, calls, candidates=None, error=None, preserve_times=False
|
||||
) -> None:
|
||||
self.calls = calls
|
||||
self.candidates = candidates
|
||||
self.error = error
|
||||
self.preserve_times = preserve_times
|
||||
|
||||
def read_order_candidates(self, query):
|
||||
self.calls.append(("reconcile", query.goods_id))
|
||||
@@ -113,18 +116,14 @@ class ReadOnlyReconcileAdapter(PddPurchaseReconcileAdapter):
|
||||
candidates = (
|
||||
PurchaseOrderCandidate(
|
||||
order_no="ORDER-001",
|
||||
goods_id=query.goods_id,
|
||||
options=dict(query.options),
|
||||
quantity=query.quantity,
|
||||
total_price_cent=query.total_price_cent,
|
||||
ordered_at=query.irreversible_action_at,
|
||||
ordered_at=query.order_submitted_at,
|
||||
ordered_at_raw="2026-08-10 16:00:00",
|
||||
payment_status="unpaid",
|
||||
),
|
||||
)
|
||||
else:
|
||||
elif not self.preserve_times:
|
||||
candidates = tuple(
|
||||
replace(candidate, ordered_at=query.irreversible_action_at)
|
||||
replace(candidate, ordered_at=query.order_submitted_at)
|
||||
for candidate in candidates
|
||||
)
|
||||
return PurchaseReconcileScan(
|
||||
@@ -305,6 +304,15 @@ class PurchaseRecoveryTest(unittest.TestCase):
|
||||
detail.pdd_data["purchase"]["payment_status"], "unpaid"
|
||||
)
|
||||
self.assertEqual(detail.pdd_data["purchase"]["order_no"], "ORDER-001")
|
||||
self.assertEqual(
|
||||
detail.pdd_data["purchase"]["confirmed"],
|
||||
{
|
||||
"options": OPTIONS,
|
||||
"quantity": 2,
|
||||
"unit_price_cent": 4200,
|
||||
"total_price_cent": 8400,
|
||||
},
|
||||
)
|
||||
|
||||
def test_reconcile_device_failure_is_recorded_as_unknown(self):
|
||||
task_id = "PUR-RECONCILE-OFFLINE"
|
||||
@@ -342,7 +350,7 @@ class PurchaseRecoveryTest(unittest.TestCase):
|
||||
|
||||
def test_no_multiple_mismatched_and_paid_candidates_need_manual_review(self):
|
||||
cases = {
|
||||
"EMPTY": ((), "ORDER_NOT_FOUND"),
|
||||
"EMPTY": ((), "ORDER_NOT_FOUND", False),
|
||||
"MULTIPLE": (
|
||||
(
|
||||
PurchaseOrderCandidate(
|
||||
@@ -367,21 +375,19 @@ class PurchaseRecoveryTest(unittest.TestCase):
|
||||
),
|
||||
),
|
||||
"AMBIGUOUS_ORDER_MATCH",
|
||||
False,
|
||||
),
|
||||
"MISMATCH": (
|
||||
"OUT_OF_TIME": (
|
||||
(
|
||||
PurchaseOrderCandidate(
|
||||
"ORDER-C",
|
||||
"OTHER-GOODS",
|
||||
OPTIONS,
|
||||
2,
|
||||
8400,
|
||||
"2026-08-10T08:00:00Z",
|
||||
"2026-08-10 16:00:00",
|
||||
"unpaid",
|
||||
order_no="ORDER-C",
|
||||
ordered_at="2020-01-01T00:00:00Z",
|
||||
ordered_at_raw="2020-01-01 08:00:00",
|
||||
payment_status="unpaid",
|
||||
),
|
||||
),
|
||||
"ORDER_MATCH_UNCERTAIN",
|
||||
True,
|
||||
),
|
||||
"PAID": (
|
||||
(
|
||||
@@ -397,9 +403,31 @@ class PurchaseRecoveryTest(unittest.TestCase):
|
||||
),
|
||||
),
|
||||
"ORDER_MATCH_UNCERTAIN",
|
||||
False,
|
||||
),
|
||||
"MISSING_ORDER_NO": (
|
||||
(
|
||||
PurchaseOrderCandidate(
|
||||
order_no="",
|
||||
payment_status="unpaid",
|
||||
),
|
||||
),
|
||||
"ORDER_MATCH_UNCERTAIN",
|
||||
False,
|
||||
),
|
||||
"MISSING_TIME": (
|
||||
(
|
||||
PurchaseOrderCandidate(
|
||||
order_no="ORDER-E",
|
||||
ordered_at="",
|
||||
payment_status="unpaid",
|
||||
),
|
||||
),
|
||||
"ORDER_MATCH_UNCERTAIN",
|
||||
True,
|
||||
),
|
||||
}
|
||||
for suffix, (candidates, error_code) in cases.items():
|
||||
for suffix, (candidates, error_code, preserve_times) in cases.items():
|
||||
with self.subTest(suffix=suffix):
|
||||
task_id = f"PUR-{suffix}"
|
||||
self._interrupt_after_irreversible(task_id)
|
||||
@@ -413,8 +441,13 @@ class PurchaseRecoveryTest(unittest.TestCase):
|
||||
"purchase"
|
||||
),
|
||||
purchase_reconcile_factory=(
|
||||
lambda _address, _cancelled, values=candidates:
|
||||
ReadOnlyReconcileAdapter(calls, values)
|
||||
lambda _address, _cancelled, values=candidates,
|
||||
keep_times=preserve_times:
|
||||
ReadOnlyReconcileAdapter(
|
||||
calls,
|
||||
values,
|
||||
preserve_times=keep_times,
|
||||
)
|
||||
),
|
||||
device_connection_checker=lambda _serial: None,
|
||||
).execute_one()
|
||||
|
||||
Reference in New Issue
Block a user