出库操作逻辑上面实现,成功跑通
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from app.services.outbound_service import OutboundService
|
||||
from flask_jwt_extended import jwt_required, get_jwt_identity
|
||||
import traceback
|
||||
|
||||
outbound_bp = Blueprint('outbound', __name__, url_prefix='/outbound')
|
||||
|
||||
|
||||
# --------------------------------------------------------
|
||||
# 1. 扫码查询库存接口
|
||||
# 1. 扫码查询库存接口 (关联三个库存表)
|
||||
# GET /api/v1/outbound/scan?barcode=...
|
||||
# --------------------------------------------------------
|
||||
@outbound_bp.route('/scan', methods=['GET'])
|
||||
@ -17,13 +18,24 @@ def scan_barcode():
|
||||
return jsonify({'code': 400, 'msg': '请提供条码'}), 400
|
||||
|
||||
try:
|
||||
# 调用 Service 层去三个表中查找
|
||||
result = OutboundService.get_stock_by_barcode(barcode)
|
||||
|
||||
if result:
|
||||
return jsonify({'code': 200, 'data': result, 'msg': '扫描成功'})
|
||||
return jsonify({
|
||||
'code': 200,
|
||||
'msg': '扫描成功',
|
||||
'data': result
|
||||
})
|
||||
else:
|
||||
return jsonify({'code': 404, 'msg': '未找到对应的库存记录'}), 404
|
||||
return jsonify({
|
||||
'code': 404,
|
||||
'msg': '未找到对应的库存记录,请确认条码是否正确'
|
||||
}), 404
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': f'扫描查询出错: {str(e)}'}), 500
|
||||
|
||||
|
||||
# --------------------------------------------------------
|
||||
@ -37,24 +49,37 @@ def create_outbound():
|
||||
if not data:
|
||||
return jsonify({'code': 400, 'msg': '无有效数据'}), 400
|
||||
|
||||
current_user = get_jwt_identity() # 获取当前登录用户作为操作员
|
||||
# 获取当前登录用户名 (JWT identity)
|
||||
current_user_name = get_jwt_identity()
|
||||
if not current_user_name:
|
||||
current_user_name = 'Unknown'
|
||||
|
||||
# 简单的必填校验 (更复杂的校验可放入 Schema)
|
||||
# ★ [修改] 获取最终的操作员名称
|
||||
# 优先取前端传来的 operator_name (你在前端下拉框选的人)
|
||||
# 如果前端没传,则回退使用当前登录用户的名字
|
||||
final_operator = data.get('operator_name')
|
||||
if not final_operator:
|
||||
final_operator = current_user_name
|
||||
|
||||
# 必填校验
|
||||
required_fields = ['stock_id', 'source_table', 'quantity', 'consumer_name', 'signature_path']
|
||||
for field in required_fields:
|
||||
if field not in data or not data[field]:
|
||||
return jsonify({'code': 400, 'msg': f'缺少必填字段: {field}'}), 400
|
||||
|
||||
try:
|
||||
outbound_record = OutboundService.create_outbound(data, operator_name=current_user)
|
||||
# ★ [修改] 将确认后的操作员名称传给 Service
|
||||
outbound_record = OutboundService.create_outbound(data, operator_name=final_operator)
|
||||
return jsonify({
|
||||
'code': 200,
|
||||
'msg': '出库成功',
|
||||
'data': outbound_record.to_dict()
|
||||
})
|
||||
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
|
||||
|
||||
|
||||
@ -67,11 +92,10 @@ def create_outbound():
|
||||
def get_outbound_list():
|
||||
try:
|
||||
page = int(request.args.get('page', 1))
|
||||
per_page = int(request.args.get('limit', 10))
|
||||
limit = int(request.args.get('limit', 10))
|
||||
keyword = request.args.get('keyword', '')
|
||||
# 日期范围处理可根据前端传参格式调整
|
||||
|
||||
result = OutboundService.get_list(page, per_page, keyword)
|
||||
result = OutboundService.get_list(page, limit, keyword)
|
||||
|
||||
return jsonify({
|
||||
'code': 200,
|
||||
@ -79,4 +103,5 @@ def get_outbound_list():
|
||||
'data': result
|
||||
})
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return jsonify({'code': 500, 'msg': str(e)}), 500
|
||||
Reference in New Issue
Block a user