盘库操作初设计
This commit is contained in:
@ -2,18 +2,19 @@ from flask import Blueprint
|
||||
from .buy import inbound_buy_bp
|
||||
from .semi import inbound_semi_bp
|
||||
from .base import inbound_base_bp
|
||||
# 导入 product
|
||||
from .product import inbound_product_bp
|
||||
# ★ [新增] 导入 summary
|
||||
from .inbound_summary import bp as inbound_summary_bp
|
||||
# ★ [新增] 导入 stock 模块
|
||||
from .stock import bp as stock_bp
|
||||
|
||||
inbound_bp = Blueprint('inbound', __name__)
|
||||
|
||||
inbound_bp.register_blueprint(inbound_buy_bp, url_prefix='/buy')
|
||||
inbound_bp.register_blueprint(inbound_semi_bp, url_prefix='/semi')
|
||||
inbound_bp.register_blueprint(inbound_base_bp, url_prefix='/base')
|
||||
# 挂载 product,前缀改为 /product
|
||||
inbound_bp.register_blueprint(inbound_product_bp, url_prefix='/product')
|
||||
inbound_bp.register_blueprint(inbound_summary_bp, url_prefix='/summary')
|
||||
|
||||
# ★ [新增] 挂载 summary, url 变成 /api/v1/inbound/summary/list
|
||||
inbound_bp.register_blueprint(inbound_summary_bp, url_prefix='/summary')
|
||||
# ★ [新增] 挂载 stock 模块,路径前缀为 /stock
|
||||
# 最终访问路径例:/api/v1/inbound/stock/all
|
||||
inbound_bp.register_blueprint(stock_bp, url_prefix='/stock')
|
||||
@ -3,7 +3,7 @@ from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.base_service import MaterialBaseService
|
||||
import traceback
|
||||
|
||||
inbound_base_bp = Blueprint('inbound_base', __name__)
|
||||
inbound_base_bp = Blueprint('stock_base', __name__)
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
|
||||
@ -3,7 +3,7 @@ from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.buy_service import BuyInboundService
|
||||
import traceback
|
||||
|
||||
inbound_buy_bp = Blueprint('inbound_buy', __name__)
|
||||
inbound_buy_bp = Blueprint('stock_buy', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@ -3,7 +3,7 @@ from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.product_service import ProductInboundService
|
||||
import traceback
|
||||
|
||||
inbound_product_bp = Blueprint('inbound_product', __name__)
|
||||
inbound_product_bp = Blueprint('stock_product', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@ -4,7 +4,7 @@ from app.services.inbound.semi_service import SemiInboundService
|
||||
import traceback
|
||||
|
||||
# 定义蓝图
|
||||
inbound_semi_bp = Blueprint('inbound_semi', __name__)
|
||||
inbound_semi_bp = Blueprint('stock_semi', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
98
inventory-backend/app/api/v1/inbound/stock.py
Normal file
98
inventory-backend/app/api/v1/inbound/stock.py
Normal file
@ -0,0 +1,98 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
# ★ [核心修复] 导入正确的模型类名 StockBuy (替换原来的 InboundBuy)
|
||||
from app.models.inbound.buy import StockBuy
|
||||
|
||||
# 尝试导入半成品和成品模型 (根据你的命名习惯修正为 StockSemi/StockProduct)
|
||||
# 使用 try-except 防止如果其他文件还没改名导致再次报错
|
||||
try:
|
||||
from app.models.inbound.semi import StockSemi
|
||||
except ImportError:
|
||||
StockSemi = None
|
||||
|
||||
try:
|
||||
from app.models.inbound.product import StockProduct
|
||||
except ImportError:
|
||||
StockProduct = None
|
||||
|
||||
from app.services.print.network_print_service import NetworkPrintService
|
||||
|
||||
bp = Blueprint('stock_ops', __name__)
|
||||
|
||||
|
||||
@bp.route('/all', methods=['GET'])
|
||||
def get_all_stock():
|
||||
"""
|
||||
获取所有在库物品(采购件+半成品+成品)
|
||||
用于:盘点初始化、出库选单列表
|
||||
"""
|
||||
try:
|
||||
# 1. 获取采购件
|
||||
# ★ [核心修复] 使用 StockBuy 查询,并将状态条件改为 '在库' (匹配你的 Model 定义)
|
||||
materials = []
|
||||
if StockBuy:
|
||||
materials = StockBuy.query.filter(StockBuy.status == '在库').all()
|
||||
|
||||
# 2. 获取半成品
|
||||
semis = []
|
||||
if StockSemi:
|
||||
try:
|
||||
# 假设半成品也使用 '在库' 状态
|
||||
semis = StockSemi.query.filter(StockSemi.status == '在库').all()
|
||||
except Exception:
|
||||
semis = []
|
||||
|
||||
# 3. 获取成品
|
||||
products = []
|
||||
if StockProduct:
|
||||
try:
|
||||
products = StockProduct.query.filter(StockProduct.status == '在库').all()
|
||||
except Exception:
|
||||
products = []
|
||||
|
||||
return jsonify({
|
||||
"materials": [item.to_dict() for item in materials],
|
||||
"semis": [item.to_dict() for item in semis],
|
||||
"products": [item.to_dict() for item in products]
|
||||
}), 200
|
||||
except Exception as e:
|
||||
print(f"Error in get_all_stock: {e}") # 输出错误日志以便调试
|
||||
return jsonify({"message": f"查询库存失败: {str(e)}"}), 500
|
||||
|
||||
|
||||
@bp.route('/print/selection', methods=['POST'])
|
||||
def print_selection():
|
||||
"""打印出库选单"""
|
||||
try:
|
||||
data = request.json
|
||||
items = data.get('items', [])
|
||||
|
||||
if not items:
|
||||
return jsonify({"message": "未选择任何物品"}), 400
|
||||
|
||||
printer = NetworkPrintService() # 默认连接 192.168.9.205
|
||||
success, msg = printer.print_outbound_selection(items)
|
||||
|
||||
if success:
|
||||
return jsonify({"message": "打印指令已发送"}), 200
|
||||
else:
|
||||
return jsonify({"message": msg}), 500
|
||||
except Exception as e:
|
||||
return jsonify({"message": f"打印服务错误: {str(e)}"}), 500
|
||||
|
||||
|
||||
@bp.route('/print/stocktake', methods=['POST'])
|
||||
def print_stocktake():
|
||||
"""打印盘点报告"""
|
||||
try:
|
||||
data = request.json
|
||||
# data 结构: { total, scanned, missing, missing_items: [] }
|
||||
|
||||
printer = NetworkPrintService()
|
||||
success, msg = printer.print_stocktake_report(data)
|
||||
|
||||
if success:
|
||||
return jsonify({"message": "盘点报告已发送"}), 200
|
||||
else:
|
||||
return jsonify({"message": msg}), 500
|
||||
except Exception as e:
|
||||
return jsonify({"message": f"打印服务错误: {str(e)}"}), 500
|
||||
Reference in New Issue
Block a user