fix: SDS 款号解析器重写(split('()') 永不命中 bug)+RIIN style_code 兜底
This commit is contained in:
+13
-9
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -238,6 +239,7 @@ def map_riin_order(raw: Any) -> OrderUpsertInput:
|
|||||||
def map_riin_goods(raw: Any, parent_order_no: str, parent_created_at: datetime) -> GoodsUpsertInput:
|
def map_riin_goods(raw: Any, parent_order_no: str, parent_created_at: datetime) -> GoodsUpsertInput:
|
||||||
product_code = raw.product_code
|
product_code = raw.product_code
|
||||||
item_name = product_code.split("-")[0] if product_code else None
|
item_name = product_code.split("-")[0] if product_code else None
|
||||||
|
style_no = raw.style_code or item_name
|
||||||
return GoodsUpsertInput(
|
return GoodsUpsertInput(
|
||||||
orderNo=parent_order_no,
|
orderNo=parent_order_no,
|
||||||
productionNo=raw.id,
|
productionNo=raw.id,
|
||||||
@@ -246,7 +248,7 @@ def map_riin_goods(raw: Any, parent_order_no: str, parent_created_at: datetime)
|
|||||||
itemName=item_name,
|
itemName=item_name,
|
||||||
itemColor=raw.color_code,
|
itemColor=raw.color_code,
|
||||||
itemSize=raw.size_code,
|
itemSize=raw.size_code,
|
||||||
itemStyleNo=item_name,
|
itemStyleNo=style_no,
|
||||||
quantity=raw.num if raw.num is not None else 1,
|
quantity=raw.num if raw.num is not None else 1,
|
||||||
status=RIIN_GOODS_STATUS_MAP.get(raw.goods_status) if raw.goods_status else None,
|
status=RIIN_GOODS_STATUS_MAP.get(raw.goods_status) if raw.goods_status else None,
|
||||||
)
|
)
|
||||||
@@ -335,17 +337,19 @@ def map_sds_order(raw: Any, channel_type_map: dict[int, str | None], pre_courier
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_STYLE_CODE_RE = re.compile(r"[A-Za-z]{1,6}\d{2,4}[A-Za-z]{0,2}|\d{2,6}[A-Za-z]{1,2}")
|
||||||
|
|
||||||
|
|
||||||
def _parse_sds_style_no(name: str | None) -> str | None:
|
def _parse_sds_style_no(name: str | None) -> str | None:
|
||||||
|
"""从商品名提取款号,如 '英国(包邮)180g纯棉T恤-GBTM001-单面印花' → 'GBTM001';
|
||||||
|
裸码名(如 'DF009')直接返回本身。逐 '-' 段扫描,避免误中段外字符。"""
|
||||||
if not name:
|
if not name:
|
||||||
return None
|
return None
|
||||||
parts = name.split("()")
|
for seg in name.split("-"):
|
||||||
if len(parts) < 3:
|
seg = seg.strip()
|
||||||
return None
|
m = _STYLE_CODE_RE.fullmatch(seg)
|
||||||
subs = parts[2].split("-")
|
if m:
|
||||||
if len(subs) == 2:
|
return seg.upper()
|
||||||
return subs[0] or None
|
|
||||||
if len(subs) >= 3:
|
|
||||||
return subs[1] or None
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user