fix: capture and persist target object names for delete, outbound, and borrow operations in audit logs

This commit is contained in:
DXC
2026-03-20 15:47:13 +08:00
parent b08bbba718
commit 032479fe38
15 changed files with 54 additions and 21 deletions

View File

@ -257,6 +257,23 @@ def audit_log(module: str, action: str = None, get_target_id_fn=None, get_target
target_name = get_target_name_fn()
except Exception:
pass
# 如果仍未获取到目标名称,尝试从响应 JSON 中常见字段获取
if not target_name and hasattr(response, 'json'):
resp_data = response.get_json()
if resp_data and isinstance(resp_data, dict):
# 优先从顶层获取
for field in ['order_no', 'outbound_no', 'borrow_no', 'adjustment_no', 'material_name']:
if field in resp_data:
target_name = resp_data[field]
break
# 再尝试从 data 字段获取(部分 API 返回格式)
if not target_name and 'data' in resp_data:
data = resp_data['data']
if isinstance(data, dict):
for field in ['order_no', 'outbound_no', 'borrow_no', 'adjustment_no', 'material_name']:
if field in data:
target_name = data[field]
break
# 获取 details
details = None