fix: 简化待付款订单核单条件 (#126)
This commit is contained in:
@@ -208,21 +208,14 @@ class PurchaseReconcileService:
|
||||
) -> bool:
|
||||
if (
|
||||
not candidate.order_no.strip()
|
||||
or candidate.goods_id.strip() != query.goods_id
|
||||
or dict(candidate.options) != dict(query.options)
|
||||
or candidate.quantity != query.quantity
|
||||
or candidate.total_price_cent != query.total_price_cent
|
||||
or candidate.payment_status != "unpaid"
|
||||
):
|
||||
return False
|
||||
try:
|
||||
ordered_at = _parse_iso_time(candidate.ordered_at)
|
||||
lower = _parse_iso_time(query.irreversible_action_at) - timedelta(
|
||||
minutes=5
|
||||
)
|
||||
upper = _parse_iso_time(query.reconcile_started_at) + timedelta(
|
||||
minutes=5
|
||||
)
|
||||
submitted_at = _parse_iso_time(query.order_submitted_at)
|
||||
lower = submitted_at - timedelta(minutes=5)
|
||||
upper = submitted_at + timedelta(minutes=5)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
return lower <= ordered_at <= upper
|
||||
@@ -237,21 +230,41 @@ class PurchaseReconcileService:
|
||||
options = payload.get("options")
|
||||
if not isinstance(options, Mapping) or not options:
|
||||
raise ValueError("采购任务缺少 options")
|
||||
requested_options = {
|
||||
str(key): str(value) for key, value in options.items()
|
||||
}
|
||||
goods_id = str(payload.get("goods_id") or "").strip()
|
||||
quantity = payload.get("quantity")
|
||||
requested_quantity = payload.get("quantity")
|
||||
snapshot = run.diagnostics_json.get("final_confirmation")
|
||||
if not isinstance(snapshot, Mapping):
|
||||
raise ValueError("采购运行缺少提交前确认快照")
|
||||
confirmed_options = snapshot.get("options")
|
||||
confirmed_quantity = snapshot.get("quantity")
|
||||
total_price_cent = snapshot.get("total_price_cent")
|
||||
unit_price_cent = snapshot.get("unit_price_cent")
|
||||
if not goods_id:
|
||||
raise ValueError("采购任务缺少 goods_id")
|
||||
if (
|
||||
isinstance(quantity, bool)
|
||||
or not isinstance(quantity, int)
|
||||
or quantity <= 0
|
||||
isinstance(requested_quantity, bool)
|
||||
or not isinstance(requested_quantity, int)
|
||||
or requested_quantity <= 0
|
||||
):
|
||||
raise ValueError("采购任务缺少有效 quantity")
|
||||
if not isinstance(confirmed_options, Mapping):
|
||||
raise ValueError("采购运行缺少确认规格")
|
||||
normalized_confirmed_options = {
|
||||
str(key): str(value) for key, value in confirmed_options.items()
|
||||
}
|
||||
if normalized_confirmed_options != requested_options:
|
||||
raise ValueError("采购运行确认规格与任务不一致")
|
||||
if (
|
||||
isinstance(confirmed_quantity, bool)
|
||||
or not isinstance(confirmed_quantity, int)
|
||||
or confirmed_quantity <= 0
|
||||
):
|
||||
raise ValueError("采购运行缺少有效确认数量")
|
||||
if confirmed_quantity != requested_quantity:
|
||||
raise ValueError("采购运行确认数量与任务不一致")
|
||||
if (
|
||||
isinstance(total_price_cent, bool)
|
||||
or not isinstance(total_price_cent, int)
|
||||
@@ -264,13 +277,19 @@ class PurchaseReconcileService:
|
||||
or unit_price_cent <= 0
|
||||
):
|
||||
raise ValueError("采购运行缺少有效确认单价")
|
||||
order_submitted_at = str(
|
||||
run.order_submitted_at or run.irreversible_action_at or ""
|
||||
).strip()
|
||||
if not order_submitted_at:
|
||||
raise ValueError("采购运行缺少下单时间基准")
|
||||
return PurchaseReconcileQuery(
|
||||
goods_id=goods_id,
|
||||
options={str(key): str(value) for key, value in options.items()},
|
||||
quantity=quantity,
|
||||
options=normalized_confirmed_options,
|
||||
quantity=confirmed_quantity,
|
||||
unit_price_cent=unit_price_cent,
|
||||
total_price_cent=total_price_cent,
|
||||
irreversible_action_at=str(run.irreversible_action_at),
|
||||
order_submitted_at=order_submitted_at,
|
||||
reconcile_started_at=_utc_now_iso(),
|
||||
)
|
||||
|
||||
@@ -292,10 +311,10 @@ class PurchaseReconcileService:
|
||||
"max_price_cent": task.price_cent,
|
||||
},
|
||||
"confirmed": {
|
||||
"options": dict(candidate.options),
|
||||
"quantity": candidate.quantity,
|
||||
"options": dict(query.options),
|
||||
"quantity": query.quantity,
|
||||
"unit_price_cent": query.unit_price_cent,
|
||||
"total_price_cent": candidate.total_price_cent,
|
||||
"total_price_cent": query.total_price_cent,
|
||||
},
|
||||
"confirmation_reached": True,
|
||||
"order_submitted": True,
|
||||
|
||||
Reference in New Issue
Block a user