出库进行修改,确保可以进行多个样例的出库以及出库的记录展示
This commit is contained in:
@ -18,7 +18,7 @@ def scan_barcode():
|
||||
return jsonify({'code': 400, 'msg': '请提供条码'}), 400
|
||||
|
||||
try:
|
||||
# 调用 Service 层去三个表中查找
|
||||
# 调用 Service 层去三个表中查找 (Service已更新,会返回价格)
|
||||
result = OutboundService.get_stock_by_barcode(barcode)
|
||||
|
||||
if result:
|
||||
@ -39,7 +39,7 @@ def scan_barcode():
|
||||
|
||||
|
||||
# --------------------------------------------------------
|
||||
# 2. 提交出库单接口
|
||||
# 2. 提交出库单接口 (批量)
|
||||
# POST /api/v1/outbound
|
||||
# --------------------------------------------------------
|
||||
@outbound_bp.route('', methods=['POST'])
|
||||
@ -54,26 +54,26 @@ def create_outbound():
|
||||
if not current_user_name:
|
||||
current_user_name = 'Unknown'
|
||||
|
||||
# ★ [修改] 获取最终的操作员名称
|
||||
# 优先取前端传来的 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
|
||||
# 必填校验 (针对整个单据)
|
||||
# items 必须是列表且不为空,consumer_name 和 signature_path 必填
|
||||
if 'items' not in data or not data['items']:
|
||||
return jsonify({'code': 400, 'msg': '出库商品列表不能为空'}), 400
|
||||
|
||||
if not data.get('consumer_name') or not data.get('signature_path'):
|
||||
return jsonify({'code': 400, 'msg': '领用人及签名信息缺失'}), 400
|
||||
|
||||
try:
|
||||
# ★ [修改] 将确认后的操作员名称传给 Service
|
||||
outbound_record = OutboundService.create_outbound(data, operator_name=final_operator)
|
||||
# ★ [修改] 调用批量创建服务
|
||||
outbound_no = OutboundService.create_outbound_batch(data, operator_name=final_operator)
|
||||
return jsonify({
|
||||
'code': 200,
|
||||
'msg': '出库成功',
|
||||
'data': outbound_record.to_dict()
|
||||
'data': {'outbound_no': outbound_no}
|
||||
})
|
||||
except ValueError as e:
|
||||
# 业务逻辑错误 (如库存不足)
|
||||
@ -84,7 +84,7 @@ def create_outbound():
|
||||
|
||||
|
||||
# --------------------------------------------------------
|
||||
# 3. 获取出库记录列表
|
||||
# 3. 获取出库记录列表 (分组展示)
|
||||
# GET /api/v1/outbound
|
||||
# --------------------------------------------------------
|
||||
@outbound_bp.route('', methods=['GET'])
|
||||
@ -94,8 +94,10 @@ def get_outbound_list():
|
||||
page = int(request.args.get('page', 1))
|
||||
limit = int(request.args.get('limit', 10))
|
||||
keyword = request.args.get('keyword', '')
|
||||
# 如果前端传了日期范围,可以解析处理,这里暂略
|
||||
|
||||
result = OutboundService.get_list(page, limit, keyword)
|
||||
# ★ [修改] 调用分组查询服务
|
||||
result = OutboundService.get_grouped_list(page, limit, keyword)
|
||||
|
||||
return jsonify({
|
||||
'code': 200,
|
||||
|
||||
Reference in New Issue
Block a user