fix: capture and persist target object names for delete, outbound, and borrow operations in audit logs
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user