fix(track): track-lookup 按公司路由,修复 LICA 扫码误报"物料不存在"
lookup_product() 此前写死读全局 TRACK_API_URL(指向 IRIS)。LICA 员工在 LICA 业务里扫码 → 请求打到 IRIS 库 → 查不到 → MOM 报"物料不存在"。 改用 get_current_company_filter() + resolve_track_route(…, 'api') 选实例, 复用既有工具而非另写一套。无请求/JWT 上下文时(脚本、后台任务)包一层 异常保护回落默认实例,不阻断查询。 实测(身份证 0000000000000001 只存在于 LICA 库): LICA 员工 → company_filter='LICA' → 命中 sn='0000000000000001' IRIS 员工 → company_filter='IRIS' → 未命中 改造前两者都会打到 IRIS,LICA 员工必然查不到。
This commit is contained in:
@ -29,15 +29,28 @@ def lookup_product(code):
|
||||
sku/material_name/spec_model/material_type/order_no),未命中或异常返回 None。
|
||||
"""
|
||||
try:
|
||||
base_url = (current_app.config.get('TRACK_API_URL') or '').strip()
|
||||
api_key = (current_app.config.get('TRACK_WEBHOOK_KEY') or '').strip()
|
||||
if not base_url:
|
||||
logger.info("[TrackQuery] 未配置 TRACK_API_URL,跳过查询")
|
||||
return None
|
||||
if not api_key:
|
||||
logger.info("[TrackQuery] 未配置 TRACK_WEBHOOK_KEY,跳过查询")
|
||||
return None
|
||||
|
||||
# ★ 按当前用户所属公司路由到对应的 Track 实例(IRIS / LICA)。
|
||||
# 复用 get_current_company_filter():超管/跨域用户返回 None → 回落默认实例。
|
||||
# 改造前这里写死读 TRACK_API_URL,LICA 员工在 LICA 业务里扫码会打到 IRIS 库,
|
||||
# 查不到 → MOM 误报"物料不存在"。
|
||||
from app.services.track_webhook_service import resolve_track_route
|
||||
from app.utils.decorators import get_current_company_filter
|
||||
try:
|
||||
company = get_current_company_filter()
|
||||
except Exception:
|
||||
# 无请求/JWT 上下文(脚本、后台任务)时回落默认实例,不阻断查询
|
||||
company = None
|
||||
|
||||
base_url = resolve_track_route(company, 'api')
|
||||
if not base_url:
|
||||
logger.info("[TrackQuery] 未解析到 Track API 地址,跳过查询")
|
||||
return None
|
||||
|
||||
url = f'{base_url}/api/v1/external/products/lookup'
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user