feat(borrow): 借库未归还直接报废功能(关联报废单流程)
后端: - trans_service 新增 scrap_borrow 方法:未归还借用标记为 scrapped, 扣减总库存 stock_quantity(可用已在借出时冻结),生成 TransScrap 报废记录 - transactions.py 新增 POST /borrow/scrap 接口(复用 op_return:operation 权限,库管/主管可操作) - scrap.py query_records 支持 trans_borrow 来源的物料名解析 + 行级隔离 前端: - records.vue 未归还记录新增「报废」按钮(库管/主管可见) - 报废弹窗:勾选明细 + 填报废原因 + 二次确认 - 状态显示新增「已报废」标签;整单所有明细报废时标记为 scrapped
This commit is contained in:
@ -110,6 +110,38 @@ def submit_return():
|
||||
return jsonify({'code': 400, 'msg': str(e)}), 400
|
||||
|
||||
|
||||
# --- 借库报废(未归还直接报废,关联报废单流程)---
|
||||
@trans_bp.route('/borrow/scrap', methods=['POST'])
|
||||
@jwt_required()
|
||||
@permission_required('op_return:operation') # 复用归还权限:能归还的库管即可报废
|
||||
@audit_log(
|
||||
module='借库管理',
|
||||
action='借库报废',
|
||||
get_target_name_fn=lambda: request.get_json().get('reason') if request.get_json() else None
|
||||
)
|
||||
def scrap_borrow():
|
||||
"""
|
||||
借库未归还直接报废(库管/主管操作)
|
||||
请求体: { "record_ids": [1, 2, 3], "reason": "物品丢失" }
|
||||
"""
|
||||
data = request.get_json() or {}
|
||||
record_ids = data.get('record_ids', [])
|
||||
reason = data.get('reason', '')
|
||||
|
||||
if not record_ids:
|
||||
return jsonify({'code': 400, 'msg': '请选择要报废的借出记录'}), 400
|
||||
|
||||
user = get_jwt_identity() or 'Unknown'
|
||||
try:
|
||||
result = TransService.scrap_borrow(record_ids, operator_name=user, reason=reason)
|
||||
return jsonify({'code': 200, 'msg': f'已报废 {result["count"]} 条借出记录', 'data': result})
|
||||
except ValueError as e:
|
||||
return jsonify({'code': 400, 'msg': str(e)}), 400
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': f'报废失败: {str(e)}'}), 500
|
||||
|
||||
|
||||
# --- 记录列表 ---
|
||||
@trans_bp.route('/records', methods=['GET'])
|
||||
@jwt_required()
|
||||
|
||||
Reference in New Issue
Block a user